diff --git a/controller/Session.class.php b/controller/Session.class.php index 830affea..4cc09e54 100644 --- a/controller/Session.class.php +++ b/controller/Session.class.php @@ -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) diff --git a/view/template/layout/_analytics_footer.php b/view/template/layout/_analytics_footer.php index d6e6df6b..5a6c4039 100644 --- a/view/template/layout/_analytics_footer.php +++ b/view/template/layout/_analytics_footer.php @@ -10,6 +10,12 @@ ga('require', 'GTM-NT8579P'); ga('set', 'userId', ''); 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');