From bd0086a3272f3f8b2901576e8050d91d57670384 Mon Sep 17 00:00:00 2001 From: Christian Nyffenegger Date: Wed, 10 Apr 2019 09:29:29 +0200 Subject: [PATCH 01/15] implemented workaround to user_logged_in being cached --- Classes/Loader.php | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/Classes/Loader.php b/Classes/Loader.php index 1448467..692ec13 100644 --- a/Classes/Loader.php +++ b/Classes/Loader.php @@ -5,19 +5,6 @@ class Loader { - /** - * Returns whether the current request should be tracked or not - * - * @since 1.2 - * @return boolean - * - */ - function should_track_visit() - { - return (!is_user_logged_in() || get_option('track_logged_in')); - } - - /** * Returns if the cookie is present * @@ -36,6 +23,23 @@ function hasWKGoogleAnalyticsCookie() { return ob_get_clean(); } + /** + * Outputs a js function that allows a cached page to check if the user should be tracked + */ + public function output_should_track_js_function(){ + ?> + function shouldTrack(){ + var trackLoggedIn = ; + var loggedIn = $("body").hasClass("logged-in"); + if(!loggedin){ + return true; + } else if( trackLoggedIn ) { + return true; + } + return false; + } + should_track_visit() && get_option('ga_use_tag_manager')) { + if (get_option('ga_use_tag_manager')) { $TAG_MANAGER_ID = get_option('ga_tag_manager_id'); + output_should_track_js_function(); ?> - if (!hasWKGoogleAnalyticsCookie()) { + if (!hasWKGoogleAnalyticsCookie() && shouldTrack()) { //Google Tag Manager (function (w, d, s, l, i) { w[l] = w[l] || []; @@ -81,7 +86,7 @@ function google_tag_manager_script() function google_tag_manager_noscript() { ob_start(); - if ($this->should_track_visit() && get_option('ga_use_tag_manager')) { + if (get_option('ga_use_tag_manager')) { $TAG_MANAGER_ID = get_option('ga_tag_manager_id'); ?>