From 66952bb35f099295a431a9276eb993e672153e45 Mon Sep 17 00:00:00 2001 From: Jen Lampton Date: Fri, 26 May 2023 16:41:42 -0700 Subject: [PATCH 1/4] Issue #3349502: Add check to ensure account data is an array before using keys. --- googleanalytics.module | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/googleanalytics.module b/googleanalytics.module index 191207e..12a99e8 100644 --- a/googleanalytics.module +++ b/googleanalytics.module @@ -443,8 +443,9 @@ function googleanalytics_field_extra_fields() { function googleanalytics_form_user_profile_form_alter(&$form, &$form_state) { $account = $form['#user']; $config = config('googleanalytics.settings'); + $custom = $config->get('custom') - if (user_access('opt-in or out of tracking') && ($custom = $config->get('custom')) != 0 && _googleanalytics_visibility_roles($account)) { + if (user_access('opt-in or out of tracking') && $custom != 0 && _googleanalytics_visibility_roles($account)) { $form['googleanalytics'] = array( '#type' => 'fieldset', '#title' => t('Google Analytics configuration'), @@ -468,6 +469,11 @@ function googleanalytics_form_user_profile_form_alter(&$form, &$form_state) { if ($config->get('privacy_donottrack') && !empty($_SERVER['HTTP_DNT'])) { $disabled = TRUE; + // Ensure account data is an array. + if (!is_array($account->data)) { + $account->data = array(); + } + // Override settings value. $account->data['googleanalytics'] = array('custom' => FALSE); From 814dccaec1339176f93167d42a400cb8410fb5d6 Mon Sep 17 00:00:00 2001 From: Daniel Mundra <11160-dmundra@users.noreply.drupalcode.org> Date: Fri, 26 May 2023 16:47:34 -0700 Subject: [PATCH 2/4] Issue #3349458 by dmundra, mglaman, DamienMcKenna: backdropSettings is not defined error when using colorbox --- js/googleanalytics.debug.js | 6 +++--- js/googleanalytics.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/js/googleanalytics.debug.js b/js/googleanalytics.debug.js index b8a922f..432bc34 100644 --- a/js/googleanalytics.debug.js +++ b/js/googleanalytics.debug.js @@ -36,7 +36,7 @@ $(document).ready(function() { else if (Backdrop.googleanalytics.isInternalSpecial(this.href)) { // Keep the internal URL for Google Analytics website overlay intact. console.info("Click on internal special link '%s' has been tracked.", Backdrop.googleanalytics.getPageUrl(this.href)); - gtag('config', backdropSettings.google_analytics.account, { + gtag('config', Backdrop.settings.google_analytics.account, { page_path: Backdrop.googleanalytics.getPageUrl(this.href), transport_type: 'beacon' }); @@ -80,7 +80,7 @@ $(document).ready(function() { if (Backdrop.settings.googleanalytics.trackUrlFragments) { window.onhashchange = function() { console.info("Track URL '%s' as pageview. Hash '%s' has changed.", location.pathname + location.search + location.hash, location.hash); - gtag('config', backdropSettings.google_analytics.account, { + gtag('config', Backdrop.settings.google_analytics.account, { page_path: location.pathname + location.search + location.hash }); }; @@ -93,7 +93,7 @@ $(document).ready(function() { var href = $.colorbox.element().attr("href"); if (href) { console.info("Colorbox transition to url '%s' has been tracked.", Backdrop.googleanalytics.getPageUrl(href)); - gtag('config', backdropSettings.google_analytics.account, { + gtag('config', Backdrop.settings.google_analytics.account, { page_path: Backdrop.googleanalytics.getPageUrl(href) }); } diff --git a/js/googleanalytics.js b/js/googleanalytics.js index 848e43a..1fb59a6 100644 --- a/js/googleanalytics.js +++ b/js/googleanalytics.js @@ -33,7 +33,7 @@ $(document).ready(function() { // Keep the internal URL for Google Analytics website overlay intact. // @todo: May require tracking ID var target = this; - $.each(backdropSettings.google_analytics.account, function () { + $.each(Backdrop.settings.google_analytics.account, function () { gtag('config', this, { page_path: Backdrop.googleanalytics.getPageUrl(target.href), transport_type: 'beacon' @@ -67,7 +67,7 @@ $(document).ready(function() { // Track hash changes as unique pageviews, if this option has been enabled. if (Backdrop.settings.googleanalytics.trackUrlFragments) { window.onhashchange = function() { - $.each(backdropSettings.google_analytics.account, function () { + $.each(Backdrop.settings.google_analytics.account, function () { gtag('config', this, { page_path: location.pathname + location.search + location.hash }); @@ -81,7 +81,7 @@ $(document).ready(function() { $(document).bind("cbox_complete", function () { var href = $.colorbox.element().attr("href"); if (href) { - $.each(backdropSettings.google_analytics.account, function () { + $.each(Backdrop.settings.google_analytics.account, function () { gtag('config', this, { page_path: Backdrop.googleanalytics.getPageUrl(href) }); From 5b177a14366c1d0efd17228de005e564c50f8fb0 Mon Sep 17 00:00:00 2001 From: Jen Lampton Date: Fri, 26 May 2023 16:53:27 -0700 Subject: [PATCH 3/4] Two minor updates to the variable_set() fix. --- googleanalytics.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googleanalytics.module b/googleanalytics.module index 12a99e8..e1998db 100644 --- a/googleanalytics.module +++ b/googleanalytics.module @@ -386,9 +386,9 @@ function googleanalytics_preprocess_layout() { // @FIXME: Cannot find the debug URL!??? $library = 'https://www.googletagmanager.com/gtag/js?id=' . $id_list[0]; } - elseif ($config->get('googleanalytics_cache') && $url = _googleanalytics_cache('https://www.googletagmanager.com/gtag/js')) { + elseif ($config->get('cache') && $url = _googleanalytics_cache('https://www.googletagmanager.com/gtag/js')) { // Should a local cached copy of gtag.js be used? - $query_string = '?' . state_get('css_js_query_string', '0'); + $query_string = '?' . state_get('css_js_query_string', base_convert(REQUEST_TIME, 10, 36)); $library = $url . $query_string; } else { From dc9f7154644031c90f037da2e29a0d2d042687aa Mon Sep 17 00:00:00 2001 From: Paul Rooney <1382384+paulrooney@users.noreply.github.com> Date: Mon, 29 May 2023 11:07:14 -0400 Subject: [PATCH 4/4] Add missing semicolon. Fixes error 500 after updating #31 --- googleanalytics.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googleanalytics.module b/googleanalytics.module index e1998db..3757094 100644 --- a/googleanalytics.module +++ b/googleanalytics.module @@ -443,7 +443,7 @@ function googleanalytics_field_extra_fields() { function googleanalytics_form_user_profile_form_alter(&$form, &$form_state) { $account = $form['#user']; $config = config('googleanalytics.settings'); - $custom = $config->get('custom') + $custom = $config->get('custom'); if (user_access('opt-in or out of tracking') && $custom != 0 && _googleanalytics_visibility_roles($account)) { $form['googleanalytics'] = array(