diff --git a/googleanalytics.module b/googleanalytics.module index 191207e..3757094 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 { @@ -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); 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) });