Commit 3e677343 authored by Riccardo Padovani's avatar Riccardo Padovani

Updated module google_analytics to 7.x-2.1

parent adf988be
...@@ -30,7 +30,7 @@ $(document).ready(function() { ...@@ -30,7 +30,7 @@ $(document).ready(function() {
else if (Drupal.googleanalytics.isInternalSpecial(this.href)) { else if (Drupal.googleanalytics.isInternalSpecial(this.href)) {
// Keep the internal URL for Google Analytics website overlay intact. // Keep the internal URL for Google Analytics website overlay intact.
console.info("Click on internal special link '%s' has been tracked.", Drupal.googleanalytics.getPageUrl(this.href)); console.info("Click on internal special link '%s' has been tracked.", Drupal.googleanalytics.getPageUrl(this.href));
ga("send", "pageview", { page: Drupal.googleanalytics.getPageUrl(this.href) }); ga("send", "pageview", { "page": Drupal.googleanalytics.getPageUrl(this.href) });
} }
else { else {
// e.g. anchor in same page or other internal page link // e.g. anchor in same page or other internal page link
...@@ -44,7 +44,7 @@ $(document).ready(function() { ...@@ -44,7 +44,7 @@ $(document).ready(function() {
ga("send", "event", "Mails", "Click", this.href.substring(7)); ga("send", "event", "Mails", "Click", this.href.substring(7));
} }
else if (Drupal.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) { else if (Drupal.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) {
if (Drupal.settings.googleanalytics.trackDomainMode != 2 && !Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains)) { if (Drupal.settings.googleanalytics.trackDomainMode != 2 || (Drupal.settings.googleanalytics.trackDomainMode == 2 && !Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains))) {
// External link clicked / No top-level cross domain clicked. // External link clicked / No top-level cross domain clicked.
console.info("Outbound link '%s' has been tracked.", this.href); console.info("Outbound link '%s' has been tracked.", this.href);
ga("send", "event", "Outbound links", "Click", this.href); ga("send", "event", "Outbound links", "Click", this.href);
...@@ -73,7 +73,7 @@ $(document).ready(function() { ...@@ -73,7 +73,7 @@ $(document).ready(function() {
var href = $.colorbox.element().attr("href"); var href = $.colorbox.element().attr("href");
if (href) { if (href) {
console.info("Colorbox transition to url '%s' has been tracked.", Drupal.googleanalytics.getPageUrl(href)); console.info("Colorbox transition to url '%s' has been tracked.", Drupal.googleanalytics.getPageUrl(href));
ga("send", "pageview", { page: Drupal.googleanalytics.getPageUrl(href) }); ga("send", "pageview", { "page": Drupal.googleanalytics.getPageUrl(href) });
} }
}); });
...@@ -103,7 +103,7 @@ Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) { ...@@ -103,7 +103,7 @@ Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) {
else { else {
return $.inArray(hostname, crossDomains) > -1 ? true : false; return $.inArray(hostname, crossDomains) > -1 ? true : false;
} }
} };
/** /**
* Check whether this is a download URL or not. * Check whether this is a download URL or not.
...@@ -116,7 +116,7 @@ Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) { ...@@ -116,7 +116,7 @@ Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) {
Drupal.googleanalytics.isDownload = function (url) { Drupal.googleanalytics.isDownload = function (url) {
var isDownload = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); var isDownload = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i");
return isDownload.test(url); return isDownload.test(url);
} };
/** /**
* Check whether this is an absolute internal URL or not. * Check whether this is an absolute internal URL or not.
...@@ -129,7 +129,7 @@ Drupal.googleanalytics.isDownload = function (url) { ...@@ -129,7 +129,7 @@ Drupal.googleanalytics.isDownload = function (url) {
Drupal.googleanalytics.isInternal = function (url) { Drupal.googleanalytics.isInternal = function (url) {
var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
return isInternal.test(url); return isInternal.test(url);
} };
/** /**
* Check whether this is a special URL or not. * Check whether this is a special URL or not.
...@@ -145,7 +145,7 @@ Drupal.googleanalytics.isInternal = function (url) { ...@@ -145,7 +145,7 @@ Drupal.googleanalytics.isInternal = function (url) {
Drupal.googleanalytics.isInternalSpecial = function (url) { Drupal.googleanalytics.isInternalSpecial = function (url) {
var isInternalSpecial = new RegExp("(\/go\/.*)$", "i"); var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
return isInternalSpecial.test(url); return isInternalSpecial.test(url);
} };
/** /**
* Extract the relative internal URL from an absolute internal URL. * Extract the relative internal URL from an absolute internal URL.
...@@ -163,7 +163,7 @@ Drupal.googleanalytics.isInternalSpecial = function (url) { ...@@ -163,7 +163,7 @@ Drupal.googleanalytics.isInternalSpecial = function (url) {
Drupal.googleanalytics.getPageUrl = function (url) { Drupal.googleanalytics.getPageUrl = function (url) {
var extractInternalUrl = new RegExp("^(https?):\/\/" + window.location.host, "i"); var extractInternalUrl = new RegExp("^(https?):\/\/" + window.location.host, "i");
return url.replace(extractInternalUrl, ''); return url.replace(extractInternalUrl, '');
} };
/** /**
* Extract the download file extension from the URL. * Extract the download file extension from the URL.
...@@ -178,6 +178,6 @@ Drupal.googleanalytics.getDownloadExtension = function (url) { ...@@ -178,6 +178,6 @@ Drupal.googleanalytics.getDownloadExtension = function (url) {
var extractDownloadextension = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); var extractDownloadextension = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i");
var extension = extractDownloadextension.exec(url); var extension = extractDownloadextension.exec(url);
return (extension === null) ? '' : extension[1]; return (extension === null) ? '' : extension[1];
} };
})(jQuery); })(jQuery);
...@@ -5,9 +5,9 @@ package = Statistics ...@@ -5,9 +5,9 @@ package = Statistics
configure = admin/config/system/googleanalytics configure = admin/config/system/googleanalytics
files[] = googleanalytics.test files[] = googleanalytics.test
test_dependencies[] = token test_dependencies[] = token
; Information added by Drupal.org packaging script on 2014-07-01 ; Information added by Drupal.org packaging script on 2014-11-29
version = "7.x-2.0" version = "7.x-2.1"
core = "7.x" core = "7.x"
project = "google_analytics" project = "google_analytics"
datestamp = "1404257628" datestamp = "1417276982"
...@@ -41,11 +41,8 @@ function googleanalytics_uninstall() { ...@@ -41,11 +41,8 @@ function googleanalytics_uninstall() {
variable_del('googleanalytics_privacy_donottrack'); variable_del('googleanalytics_privacy_donottrack');
// Remove backup variables if exist. Remove this code in D8. // Remove backup variables if exist. Remove this code in D8.
variable_del('googleanalytics_codesnippet_after_backup_6300');
variable_del('googleanalytics_codesnippet_before_backup_6300');
variable_del('googleanalytics_codesnippet_after_backup_7200'); variable_del('googleanalytics_codesnippet_after_backup_7200');
variable_del('googleanalytics_codesnippet_before_backup_7200'); variable_del('googleanalytics_codesnippet_before_backup_7200');
variable_del('googleanalytics_segmentation');
} }
/** /**
...@@ -74,7 +71,7 @@ function googleanalytics_requirements($phase) { ...@@ -74,7 +71,7 @@ function googleanalytics_requirements($phase) {
'value' => $t('Not configured'), 'value' => $t('Not configured'),
); );
} }
}
// Raise warning if debugging is enabled. // Raise warning if debugging is enabled.
if (variable_get('googleanalytics_debug', 0)) { if (variable_get('googleanalytics_debug', 0)) {
$requirements['google_analytics_debugging'] = array( $requirements['google_analytics_debugging'] = array(
...@@ -84,6 +81,7 @@ function googleanalytics_requirements($phase) { ...@@ -84,6 +81,7 @@ function googleanalytics_requirements($phase) {
'value' => $t('Debugging enabled'), 'value' => $t('Debugging enabled'),
); );
} }
}
return $requirements; return $requirements;
} }
...@@ -445,7 +443,7 @@ function googleanalytics_update_7200() { ...@@ -445,7 +443,7 @@ function googleanalytics_update_7200() {
// ga.js code will cause the tracker to break. Remove custom code snippets. // ga.js code will cause the tracker to break. Remove custom code snippets.
$googleanalytics_codesnippet_before = variable_get('googleanalytics_codesnippet_before', ''); $googleanalytics_codesnippet_before = variable_get('googleanalytics_codesnippet_before', '');
if (!empty($googleanalytics_codesnippet_before)) { if (!empty($googleanalytics_codesnippet_before) && stristr($googleanalytics_codesnippet_before, '_gaq.push(')) {
variable_set('googleanalytics_codesnippet_before_backup_7200', $googleanalytics_codesnippet_before); variable_set('googleanalytics_codesnippet_before_backup_7200', $googleanalytics_codesnippet_before);
variable_del('googleanalytics_codesnippet_before'); variable_del('googleanalytics_codesnippet_before');
drupal_set_message(Database::getConnection()->prefixTables("A backup of your previous Google Analytics code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_before_backup_7200'. You need to manually upgrade the custom 'before' code snippet."), 'warning'); drupal_set_message(Database::getConnection()->prefixTables("A backup of your previous Google Analytics code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_before_backup_7200'. You need to manually upgrade the custom 'before' code snippet."), 'warning');
...@@ -453,7 +451,7 @@ function googleanalytics_update_7200() { ...@@ -453,7 +451,7 @@ function googleanalytics_update_7200() {
} }
$googleanalytics_codesnippet_after = variable_get('googleanalytics_codesnippet_after', ''); $googleanalytics_codesnippet_after = variable_get('googleanalytics_codesnippet_after', '');
if (!empty($googleanalytics_codesnippet_after)) { if (!empty($googleanalytics_codesnippet_after) && stristr($googleanalytics_codesnippet_after, '_gaq.push(')) {
variable_set('googleanalytics_codesnippet_after_backup_7200', $googleanalytics_codesnippet_after); variable_set('googleanalytics_codesnippet_after_backup_7200', $googleanalytics_codesnippet_after);
variable_del('googleanalytics_codesnippet_after'); variable_del('googleanalytics_codesnippet_after');
drupal_set_message(Database::getConnection()->prefixTables("A backup of your previous Google Analytics code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_before_backup_7200'. You need to manually upgrade the custom 'before' code snippet."), 'warning'); drupal_set_message(Database::getConnection()->prefixTables("A backup of your previous Google Analytics code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_before_backup_7200'. You need to manually upgrade the custom 'before' code snippet."), 'warning');
...@@ -481,3 +479,59 @@ function googleanalytics_update_7202() { ...@@ -481,3 +479,59 @@ function googleanalytics_update_7202() {
return t('Removed obsolete JavaScript scope variable.'); return t('Removed obsolete JavaScript scope variable.');
} }
/**
* Flatten the metrics and dimensions arrays.
*/
function googleanalytics_update_7203() {
$googleanalytics_custom_dimension = variable_get('googleanalytics_custom_dimension', array());
if (isset($googleanalytics_custom_dimension['indexes'])) {
foreach ($googleanalytics_custom_dimension['indexes'] as $dimension) {
$googleanalytics_custom_dimension['indexes'][$dimension['index']]['value'] = trim($dimension['value']);
// Remove empty values from the array.
if (!drupal_strlen($googleanalytics_custom_dimension['indexes'][$dimension['index']]['value'])) {
unset($googleanalytics_custom_dimension['indexes'][$dimension['index']]);
}
}
variable_set('googleanalytics_custom_dimension', $googleanalytics_custom_dimension['indexes']);
}
$googleanalytics_custom_metric = variable_get('googleanalytics_custom_metric', array());
if (isset($googleanalytics_custom_metric['indexes'])) {
foreach ($googleanalytics_custom_metric['indexes'] as $dimension) {
$googleanalytics_custom_metric['indexes'][$dimension['index']]['value'] = trim($dimension['value']);
// Remove empty values from the array.
if (!drupal_strlen($googleanalytics_custom_metric['indexes'][$dimension['index']]['value'])) {
unset($googleanalytics_custom_metric['indexes'][$dimension['index']]);
}
}
variable_set('googleanalytics_custom_metric', $googleanalytics_custom_metric['indexes']);
}
return t('Saved custom dimensions and metrics.');
}
/**
* Remove obsolete backup variables.
*/
function googleanalytics_update_7204() {
variable_del('googleanalytics_segmentation');
variable_del('googleanalytics_codesnippet_after_backup_6300');
variable_del('googleanalytics_codesnippet_before_backup_6300');
variable_del('googleanalytics_codesnippet_after_backup_6400');
variable_del('googleanalytics_codesnippet_before_backup_6400');
return t('Removed obsolete backup variables.');
}
/**
* Update list of default file extensions.
*/
function googleanalytics_update_7205() {
if (variable_get('googleanalytics_trackfiles_extensions', '') == '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls|xml|z|zip') {
variable_set('googleanalytics_trackfiles_extensions', '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc(x|m)?|dot(x|m)?|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt(x|m)?|pot(x|m)?|pps(x|m)?|ppam|sld(x|m)?|thmx|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls(x|m|b)?|xlt(x|m)|xlam|xml|z|zip');
return t('The default extensions for download tracking have been updated.');
}
else {
return t('Custom extensions for download tracking setting found. Update skipped!');
}
}
...@@ -25,7 +25,7 @@ $(document).ready(function() { ...@@ -25,7 +25,7 @@ $(document).ready(function() {
} }
else if (Drupal.googleanalytics.isInternalSpecial(this.href)) { else if (Drupal.googleanalytics.isInternalSpecial(this.href)) {
// Keep the internal URL for Google Analytics website overlay intact. // Keep the internal URL for Google Analytics website overlay intact.
ga("send", "pageview", { page: Drupal.googleanalytics.getPageUrl(this.href) }); ga("send", "pageview", { "page": Drupal.googleanalytics.getPageUrl(this.href) });
} }
} }
else { else {
...@@ -34,7 +34,7 @@ $(document).ready(function() { ...@@ -34,7 +34,7 @@ $(document).ready(function() {
ga("send", "event", "Mails", "Click", this.href.substring(7)); ga("send", "event", "Mails", "Click", this.href.substring(7));
} }
else if (Drupal.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) { else if (Drupal.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) {
if (Drupal.settings.googleanalytics.trackDomainMode != 2 && !Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains)) { if (Drupal.settings.googleanalytics.trackDomainMode != 2 || (Drupal.settings.googleanalytics.trackDomainMode == 2 && !Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains))) {
// External link clicked / No top-level cross domain clicked. // External link clicked / No top-level cross domain clicked.
ga("send", "event", "Outbound links", "Click", this.href); ga("send", "event", "Outbound links", "Click", this.href);
} }
...@@ -55,7 +55,7 @@ $(document).ready(function() { ...@@ -55,7 +55,7 @@ $(document).ready(function() {
$(document).bind("cbox_complete", function () { $(document).bind("cbox_complete", function () {
var href = $.colorbox.element().attr("href"); var href = $.colorbox.element().attr("href");
if (href) { if (href) {
ga("send", "pageview", { page: Drupal.googleanalytics.getPageUrl(href) }); ga("send", "pageview", { "page": Drupal.googleanalytics.getPageUrl(href) });
} }
}); });
...@@ -85,7 +85,7 @@ Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) { ...@@ -85,7 +85,7 @@ Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) {
else { else {
return $.inArray(hostname, crossDomains) > -1 ? true : false; return $.inArray(hostname, crossDomains) > -1 ? true : false;
} }
} };
/** /**
* Check whether this is a download URL or not. * Check whether this is a download URL or not.
...@@ -98,7 +98,7 @@ Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) { ...@@ -98,7 +98,7 @@ Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) {
Drupal.googleanalytics.isDownload = function (url) { Drupal.googleanalytics.isDownload = function (url) {
var isDownload = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); var isDownload = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i");
return isDownload.test(url); return isDownload.test(url);
} };
/** /**
* Check whether this is an absolute internal URL or not. * Check whether this is an absolute internal URL or not.
...@@ -111,7 +111,7 @@ Drupal.googleanalytics.isDownload = function (url) { ...@@ -111,7 +111,7 @@ Drupal.googleanalytics.isDownload = function (url) {
Drupal.googleanalytics.isInternal = function (url) { Drupal.googleanalytics.isInternal = function (url) {
var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
return isInternal.test(url); return isInternal.test(url);
} };
/** /**
* Check whether this is a special URL or not. * Check whether this is a special URL or not.
...@@ -127,7 +127,7 @@ Drupal.googleanalytics.isInternal = function (url) { ...@@ -127,7 +127,7 @@ Drupal.googleanalytics.isInternal = function (url) {
Drupal.googleanalytics.isInternalSpecial = function (url) { Drupal.googleanalytics.isInternalSpecial = function (url) {
var isInternalSpecial = new RegExp("(\/go\/.*)$", "i"); var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
return isInternalSpecial.test(url); return isInternalSpecial.test(url);
} };
/** /**
* Extract the relative internal URL from an absolute internal URL. * Extract the relative internal URL from an absolute internal URL.
...@@ -145,7 +145,7 @@ Drupal.googleanalytics.isInternalSpecial = function (url) { ...@@ -145,7 +145,7 @@ Drupal.googleanalytics.isInternalSpecial = function (url) {
Drupal.googleanalytics.getPageUrl = function (url) { Drupal.googleanalytics.getPageUrl = function (url) {
var extractInternalUrl = new RegExp("^(https?):\/\/" + window.location.host, "i"); var extractInternalUrl = new RegExp("^(https?):\/\/" + window.location.host, "i");
return url.replace(extractInternalUrl, ''); return url.replace(extractInternalUrl, '');
} };
/** /**
* Extract the download file extension from the URL. * Extract the download file extension from the URL.
...@@ -160,6 +160,6 @@ Drupal.googleanalytics.getDownloadExtension = function (url) { ...@@ -160,6 +160,6 @@ Drupal.googleanalytics.getDownloadExtension = function (url) {
var extractDownloadextension = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); var extractDownloadextension = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i");
var extension = extractDownloadextension.exec(url); var extension = extractDownloadextension.exec(url);
return (extension === null) ? '' : extension[1]; return (extension === null) ? '' : extension[1];
} };
})(jQuery); })(jQuery);
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
/** /**
* Define the default file extension list that should be tracked as download. * Define the default file extension list that should be tracked as download.
*/ */
define('GOOGLEANALYTICS_TRACKFILES_EXTENSIONS', '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls|xml|z|zip'); define('GOOGLEANALYTICS_TRACKFILES_EXTENSIONS', '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc(x|m)?|dot(x|m)?|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt(x|m)?|pot(x|m)?|pps(x|m)?|ppam|sld(x|m)?|thmx|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls(x|m|b)?|xlt(x|m)|xlam|xml|z|zip');
/** /**
* Define default path exclusion list to remove tracking from admin pages, * Define default path exclusion list to remove tracking from admin pages,
...@@ -204,25 +204,38 @@ function googleanalytics_page_alter(&$page) { ...@@ -204,25 +204,38 @@ function googleanalytics_page_alter(&$page) {
$custom_var = ''; $custom_var = '';
foreach (array('dimension', 'metric') as $googleanalytics_custom_type) { foreach (array('dimension', 'metric') as $googleanalytics_custom_type) {
$googleanalytics_custom_vars = variable_get('googleanalytics_custom_' . $googleanalytics_custom_type, array()); $googleanalytics_custom_vars = variable_get('googleanalytics_custom_' . $googleanalytics_custom_type, array());
for ($i = 1; $i <= 20; $i++) { // Are there dimensions or metrics configured?
$custom_var_value = !empty($googleanalytics_custom_vars['indexes'][$i]['value']) ? $googleanalytics_custom_vars['indexes'][$i]['value'] : ''; if (!empty($googleanalytics_custom_vars)) {
if (!empty($custom_var_value)) { // Add all the configured variables to the content.
foreach ($googleanalytics_custom_vars as $googleanalytics_custom_var) {
// Replace tokens in values.
$types = array(); $types = array();
$node = menu_get_object(); $node = menu_get_object();
if (is_object($node)) { if (is_object($node)) {
$types += array('node' => $node); $types += array('node' => $node);
} }
$custom_var_value = token_replace($custom_var_value, $types, array('clear' => TRUE)); $googleanalytics_custom_var['value'] = token_replace($googleanalytics_custom_var['value'], $types, array('clear' => TRUE));
// Suppress empty custom names and/or variables.
if (!drupal_strlen(trim($custom_var_value))) { // Suppress empty values.
if (!drupal_strlen(trim($googleanalytics_custom_var['value']))) {
continue; continue;
} }
// Per documentation the max length of a dimension is 150 bytes.
// A metric has no length limitation. It's not documented if this
// limit means 150 bytes after url encoding or before.
// See https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#customs
if ($googleanalytics_custom_type == 'dimension' && drupal_strlen($googleanalytics_custom_var['value']) > 150) {
$googleanalytics_custom_var['value'] = substr($googleanalytics_custom_var['value'], 0, 150);
}
// Cast metric values for json_encode to data type numeric. // Cast metric values for json_encode to data type numeric.
if ($googleanalytics_custom_type == 'metric') { if ($googleanalytics_custom_type == 'metric') {
settype($custom_var_value, 'float'); settype($googleanalytics_custom_var['value'], 'float');
}; };
$custom_var .= 'ga("set", ' . drupal_json_encode($googleanalytics_custom_type . $i) . ', ' . drupal_json_encode($custom_var_value) . ');';
// Add variables to tracker.
$custom_var .= 'ga("set", ' . drupal_json_encode($googleanalytics_custom_type . $googleanalytics_custom_var['index']) . ', ' . drupal_json_encode($googleanalytics_custom_var['value']) . ');';
} }
} }
} }
...@@ -259,7 +272,7 @@ function googleanalytics_page_alter(&$page) { ...@@ -259,7 +272,7 @@ function googleanalytics_page_alter(&$page) {
$codesnippet_after = variable_get('googleanalytics_codesnippet_after', ''); $codesnippet_after = variable_get('googleanalytics_codesnippet_after', '');
// Build the create only fields list. // Build the create only fields list.
$create_only_fields = array(); $create_only_fields = array('cookieDomain' => 'auto');
$create_only_fields = array_merge($create_only_fields, $codesnippet_create); $create_only_fields = array_merge($create_only_fields, $codesnippet_create);
// Domain tracking type. // Domain tracking type.
...@@ -279,16 +292,15 @@ function googleanalytics_page_alter(&$page) { ...@@ -279,16 +292,15 @@ function googleanalytics_page_alter(&$page) {
$googleanalytics_adsense_script .= 'window.google_analytics_domain_name = "none";'; $googleanalytics_adsense_script .= 'window.google_analytics_domain_name = "none";';
} }
// Track logged in users accross all devices. // Track logged in users across all devices.
if (variable_get('googleanalytics_trackuserid', 0) && user_is_logged_in()) { if (variable_get('googleanalytics_trackuserid', 0) && user_is_logged_in()) {
// The USER_ID value should be a unique, persistent, and non-personally // The USER_ID value should be a unique, persistent, and non-personally
// identifiable string identifier that represents a user or signed-in // identifiable string identifier that represents a user or signed-in
// account across devices. // account across devices.
$create_only_fields['userId'] = drupal_base64_encode(drupal_get_hash_salt() . $user->uid); $create_only_fields['userId'] = drupal_hmac_base64($user->uid, drupal_get_private_key() . drupal_get_hash_salt());
} }
// Create a tracker. // Create a tracker.
$create_only_fields = empty($create_only_fields) ? 'auto' : $create_only_fields;
$script .= 'ga("create", ' . drupal_json_encode($id) . ', ' . drupal_json_encode($create_only_fields) .');'; $script .= 'ga("create", ' . drupal_json_encode($id) . ', ' . drupal_json_encode($create_only_fields) .');';
// Prepare Adsense tracking. // Prepare Adsense tracking.
...@@ -439,11 +451,13 @@ function googleanalytics_cron() { ...@@ -439,11 +451,13 @@ function googleanalytics_cron() {
* Collects and adds the number of search results to the head. * Collects and adds the number of search results to the head.
*/ */
function googleanalytics_preprocess_search_results(&$variables) { function googleanalytics_preprocess_search_results(&$variables) {
if (variable_get('googleanalytics_site_search', FALSE)) {
// There is no search result $variable available that hold the number of items // There is no search result $variable available that hold the number of items
// found. But the pager item mumber can tell the number of search results. // found. But the pager item mumber can tell the number of search results.
global $pager_total_items; global $pager_total_items;
drupal_add_js('window.googleanalytics_search_results = ' . intval($pager_total_items[0]) . ';', array('type' => 'inline', 'group' => JS_LIBRARY-1)); drupal_add_js('window.googleanalytics_search_results = ' . intval($pager_total_items[0]) . ';', array('type' => 'inline', 'group' => JS_LIBRARY-1));
}
} }
/** /**
......
...@@ -21,7 +21,7 @@ Drupal.googleanalytics.test.assertSame = function (value1, value2, message) { ...@@ -21,7 +21,7 @@ Drupal.googleanalytics.test.assertSame = function (value1, value2, message) {
else { else {
console.error(message); console.error(message);
} }
} };
Drupal.googleanalytics.test.assertNotSame = function (value1, value2, message) { Drupal.googleanalytics.test.assertNotSame = function (value1, value2, message) {
if (value1 !== value2) { if (value1 !== value2) {
...@@ -30,7 +30,7 @@ Drupal.googleanalytics.test.assertNotSame = function (value1, value2, message) { ...@@ -30,7 +30,7 @@ Drupal.googleanalytics.test.assertNotSame = function (value1, value2, message) {
else { else {
console.error(message); console.error(message);
} }
} };
Drupal.googleanalytics.test.assertTrue = function (value1, message) { Drupal.googleanalytics.test.assertTrue = function (value1, message) {
if (value1 === true) { if (value1 === true) {
...@@ -39,7 +39,7 @@ Drupal.googleanalytics.test.assertTrue = function (value1, message) { ...@@ -39,7 +39,7 @@ Drupal.googleanalytics.test.assertTrue = function (value1, message) {
else { else {
console.error(message); console.error(message);
} }
} };
Drupal.googleanalytics.test.assertFalse = function (value1, message) { Drupal.googleanalytics.test.assertFalse = function (value1, message) {
if (value1 === false) { if (value1 === false) {
...@@ -48,7 +48,7 @@ Drupal.googleanalytics.test.assertFalse = function (value1, message) { ...@@ -48,7 +48,7 @@ Drupal.googleanalytics.test.assertFalse = function (value1, message) {
else { else {
console.error(message); console.error(message);
} }
} };
// Run after the documented is ready or Drupal.settings is undefined. // Run after the documented is ready or Drupal.settings is undefined.
$(document).ready(function() { $(document).ready(function() {
...@@ -86,8 +86,8 @@ $(document).ready(function() { ...@@ -86,8 +86,8 @@ $(document).ready(function() {
console.groupEnd(); console.groupEnd();
console.group("Test 'getPageUrl':"); console.group("Test 'getPageUrl':");
Drupal.googleanalytics.test.assertSame(base_path + 'node/1', Drupal.googleanalytics.getPageUrl(base_url + Drupal.settings.basePath + 'node/1'), "Absolute internal URL '" + Drupal.settings.basePath + "node/1' has been extracted from full qualified url '" + base_url + base_path + "node/1'."); Drupal.googleanalytics.test.assertSame(base_path, Drupal.googleanalytics.getPageUrl(base_url + Drupal.settings.basePath + 'node/1'), "Absolute internal URL '" + Drupal.settings.basePath + "node/1' has been extracted from full qualified url '" + base_url + base_path + "'.");
Drupal.googleanalytics.test.assertSame(base_path + 'node/1', Drupal.googleanalytics.getPageUrl(Drupal.settings.basePath + 'node/1'), "Absolute internal URL '" + Drupal.settings.basePath + "node/1' has been extracted from absolute url '" + base_path + "node/1'."); Drupal.googleanalytics.test.assertSame(base_path, Drupal.googleanalytics.getPageUrl(Drupal.settings.basePath + 'node/1'), "Absolute internal URL '" + Drupal.settings.basePath + "node/1' has been extracted from absolute url '" + base_path + "'.");
Drupal.googleanalytics.test.assertSame('http://example.com/node/2', Drupal.googleanalytics.getPageUrl('http://example.com/node/2'), "Full qualified external url 'http://example.com/node/2' has been extracted."); Drupal.googleanalytics.test.assertSame('http://example.com/node/2', Drupal.googleanalytics.getPageUrl('http://example.com/node/2'), "Full qualified external url 'http://example.com/node/2' has been extracted.");
Drupal.googleanalytics.test.assertSame('//example.com/node/2', Drupal.googleanalytics.getPageUrl('//example.com/node/2'), "Full qualified external url '//example.com/node/2' has been extracted."); Drupal.googleanalytics.test.assertSame('//example.com/node/2', Drupal.googleanalytics.getPageUrl('//example.com/node/2'), "Full qualified external url '//example.com/node/2' has been extracted.");
console.groupEnd(); console.groupEnd();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment