From 258762da47ac42046e21943a2385cd1d8b700fb6 Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Sun, 18 Nov 2018 02:25:35 -0500 Subject: [PATCH 1/4] Set unique user id for google analytics and facebook pixel. Also logged web visitor access on each page view. Removed unique id generation from php and using internal unique id. --- controller/Session.class.php | 11 ++++++++--- lib/thirdparty/LBRY.class.php | 5 +++++ view/template/layout/_analytics_footer.php | 5 ++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/controller/Session.class.php b/controller/Session.class.php index 0da141e6..085e5741 100644 --- a/controller/Session.class.php +++ b/controller/Session.class.php @@ -11,13 +11,15 @@ class Session const NAMESPACE_DEFAULT = 'default', NAMESPACE_FLASH = 'flash', - NAMESPACE_FLASH_REMOVE = 'flash_remove'; + NAMESPACE_FLASH_REMOVE = 'flash_remove', + USER_ID = 'user_id'; public static function init() { ini_set('session.cookie_secure', IS_PRODUCTION); // send cookie over ssl only - ini_set('session.cookie_httponly', true); // no js access to cookies - session_start(); + ini_set('session.cookie_httponly', true); // no js access to cookies + session_start(); + if (!static::get('secure_and_httponly_set')) { session_regenerate_id(); // ensure that old cookies get new settings @@ -31,6 +33,9 @@ class Session static::setNamespace(static::NAMESPACE_DEFAULT, $oldSession); } + $response = LBRY::logWebVisitor('lbry.io', $_SESSION[static::USER_ID], $_SERVER['REMOTE_ADDR']); + $_SESSION[static::USER_ID] = $response['data']['visitor_id']; + static::initFlashes(); } diff --git a/lib/thirdparty/LBRY.class.php b/lib/thirdparty/LBRY.class.php index a6223d24..0bad0b26 100644 --- a/lib/thirdparty/LBRY.class.php +++ b/lib/thirdparty/LBRY.class.php @@ -75,4 +75,9 @@ class LBRY return Curl::post(static::getApiUrl("/yt/update"), ['status_token' => $status_token, 'new_email' => $email, 'new_preferred_channel' => $channel_name, 'sync_consent' => $sync_consent], ['json_response' => true]); } } + + public static function logWebVisitor($site, $visitorID, $IPAddress) + { + return Curl::post(static::getApiUrl("/visitor/new"), ['site' => $site, 'visitor_id' => $visitorID, 'ip_address' => $IPAddress], ['json_response' => true]); + } } diff --git a/view/template/layout/_analytics_footer.php b/view/template/layout/_analytics_footer.php index d5432e90..5d0fe5ee 100644 --- a/view/template/layout/_analytics_footer.php +++ b/view/template/layout/_analytics_footer.php @@ -8,13 +8,16 @@ ga('create', 'UA-60403362-1', 'auto'); ga('require', 'GTM-NT8579P'); + ga('set', 'userId', ''); ga('send', 'pageview'); !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'); - fbq('init', '1618717031725766'); + fbq('init', '1618717031725766',{uid: ''})); fbq('track', ''); + +