Store google analytics client id in cookie.

User google analytics client id for logging web visitors.
This commit is contained in:
Mark Beamer Jr 2019-01-19 17:31:28 -05:00
parent d3e71573df
commit 3dd1922e8d
No known key found for this signature in database
GPG key ID: 1C314FB89AD76973
2 changed files with 8 additions and 1 deletions

View file

@ -35,7 +35,8 @@ class Session
}
Response::addPostRenderCallback(function () {
$site_visitor_id = key_exists(static::USER_ID, $_SESSION) ? $_SESSION[static::USER_ID] : '';
$ga_cid = filter_input(INPUT_COOKIE, 'ga_cid');
$site_visitor_id = key_exists(static::USER_ID, $_SESSION) ? $_SESSION[static::USER_ID] : $ga_cid;
$response = LBRY::logWebVisitor(static::SITE_ID, $site_visitor_id, static::getClientIP());
if (!is_null($response)
&& key_exists('data', $response)

View file

@ -10,6 +10,12 @@
ga('require', 'GTM-NT8579P');
ga('set', 'userId', '<?php echo $_SESSION[Session::USER_ID] ?>');
ga('send', 'pageview');
// put the Google Analytics Client ID into a cookie, so that it will be available to PHP
ga(function(tracker) {
let date = new Date();
date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
document.cookie = 'ga_cid=' + tracker.get('clientId') + '; expires=' + date.toUTCString() + '; path=/';
});
!function(f,b,e,v,n,t,s) {if(f.fbq)return;n=f.fbq=function(){n.callMethod? n.callMethod.apply(n,arguments):n.queue.push(arguments)}; if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t,s)}(window,document,'script', 'https://connect.facebook.net/en_US/fbevents.js');