Commit dd9cda12 authored by hass's avatar hass
Browse files

#1741514: Use the doubleclick.net URL instead of the

google-analytics.com one
parent 43458e44
......@@ -221,29 +221,34 @@ function googleanalytics_admin_settings_form($form_state) {
// Google already have many translations, if not - they display a note to change the language.
global $language;
$form['tracking']['search_and_adsense'] = array(
$form['tracking']['search_and_advertising'] = array(
'#type' => 'fieldset',
'#title' => t('Search and AdSense'),
'#title' => t('Search and Advertising'),
);
$site_search_dependencies = '<div class="admin-dependencies">';
$site_search_dependencies .= t('Depends on: !dependencies', array('!dependencies' => (module_exists('search') ? t('@module (<span class="admin-enabled">enabled</span>)', array('@module' => 'Search')) : t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => 'Search')))));
$site_search_dependencies .= '</div>';
$form['tracking']['search_and_adsense']['googleanalytics_site_search'] = array(
$form['tracking']['search_and_advertising']['googleanalytics_site_search'] = array(
'#type' => 'checkbox',
'#title' => t('Track internal search'),
'#description' => t('If checked, internal search keywords are tracked. You must configure your Google account to use the internal query parameter <strong>search</strong>. For more information see <a href="@url">Setting Up Site Search for a Profile</a>.', array('@url' => url('http://support.google.com/analytics/bin/answer.py', array('query' => array('answer' => '1012264'))))) . $site_search_dependencies,
'#default_value' => variable_get('googleanalytics_site_search', FALSE),
'#disabled' => (module_exists('search') ? FALSE : TRUE),
);
$form['tracking']['search_and_adsense']['googleanalytics_trackadsense'] = array(
$form['tracking']['search_and_advertising']['googleanalytics_trackadsense'] = array(
'#type' => 'checkbox',
'#title' => t('Track AdSense ads'),
'#description' => t('If checked, your AdSense ads will be tracked in your Google Analytics account.'),
'#default_value' => variable_get('googleanalytics_trackadsense', FALSE),
);
$form['tracking']['search_and_advertising']['googleanalytics_trackdoubleclick'] = array(
'#type' => 'checkbox',
'#title' => t('Track DoubleClick data'),
'#description' => t('If checked, the alternative Google <a href="@doubleclick">DoubleClick data tracking</a> is used to enable AdWords remarketing features. If you choose this option you will need to <a href="@privacy">update your privacy policy</a>.', array('@doubleclick' => url('http://support.google.com/analytics/bin/answer.py', array('query' => array('answer' => '2444872'))), '@privacy' => url('http://support.google.com/analytics/bin/answer.py', array('query' => array('answer' => '2636405'))))),
'#default_value' => variable_get('googleanalytics_trackdoubleclick', FALSE),
);
// Privacy specific configurations.
$form['tracking']['privacy'] = array(
......
......@@ -82,7 +82,7 @@ Drupal.behaviors.trackingSettingsSummary = {
return Drupal.t('@items enabled', {'@items' : vals.join(', ')});
});
$('fieldset#edit-search-and-adsense', context).drupalSetSummary(function (context) {
$('fieldset#edit-search-and-advertising', context).drupalSetSummary(function (context) {
var vals = [];
if ($('input#edit-googleanalytics-site-search', context).is(':checked')) {
vals.push(Drupal.t('Site search'));
......@@ -90,6 +90,9 @@ Drupal.behaviors.trackingSettingsSummary = {
if ($('input#edit-googleanalytics-trackadsense', context).is(':checked')) {
vals.push(Drupal.t('AdSense ads'));
}
if ($('input#edit-googleanalytics-trackdoubleclick', context).is(':checked')) {
vals.push(Drupal.t('DoubleClick data'));
}
if (!vals.length) {
return Drupal.t('Not tracked');
}
......
......@@ -38,6 +38,7 @@ function googleanalytics_uninstall() {
variable_del('googleanalytics_segmentation');
variable_del('googleanalytics_site_search');
variable_del('googleanalytics_trackadsense');
variable_del('googleanalytics_trackdoubleclick');
variable_del('googleanalytics_tracker_anonymizeip');
variable_del('googleanalytics_trackfiles');
variable_del('googleanalytics_trackfiles_extensions');
......
......@@ -287,8 +287,18 @@ function googleanalytics_page_alter(&$page) {
$script .= 'ga.type = "text/javascript";';
$script .= 'ga.async = true;';
// Which version of the tracking library should be used?
if ($trackdoubleclick = variable_get('googleanalytics_trackdoubleclick', FALSE)) {
$library_tracker_url = 'stats.g.doubleclick.net/dc.js';
$library_cache_url = 'http://' . $library_tracker_url;
}
else {
$library_tracker_url = '.google-analytics.com/ga.js';
$library_cache_url = 'http://www' . $library_tracker_url;
}
// Should a local cached copy of ga.js be used?
if (variable_get('googleanalytics_cache', 0) && $url = _googleanalytics_cache('http://www.google-analytics.com/ga.js')) {
if (variable_get('googleanalytics_cache', 0) && $url = _googleanalytics_cache($library_cache_url)) {
// A dummy query-string is added to filenames, to gain control over
// browser-caching. The string changes on every update or full cache
// flush, forcing browsers to load a new copy of the files, as the
......@@ -298,7 +308,13 @@ function googleanalytics_page_alter(&$page) {
$script .= 'ga.src = "' . $url . $query_string . '";';
}
else {
$script .= 'ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";';
// Library paths do not follow the same naming convention.
if ($trackdoubleclick) {
$script .= 'ga.src = ("https:" == document.location.protocol ? "https://" : "http://") + "' . $library_tracker_url . '";';
}
else {
$script .= 'ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + "' . $library_tracker_url . '";';
}
}
$script .= 'var s = document.getElementsByTagName("script")[0];';
$script .= 's.parentNode.insertBefore(ga, s);';
......@@ -389,7 +405,13 @@ function googleanalytics_user_presave(&$edit, $account, $category) {
function googleanalytics_cron() {
// Regenerate the tracking code file every day.
if (REQUEST_TIME - variable_get('googleanalytics_last_cache', 0) >= 86400 && variable_get('googleanalytics_cache', 0)) {
_googleanalytics_cache('http://www.google-analytics.com/ga.js', TRUE);
// Which version of the tracking library should be used?
if (variable_get('googleanalytics_trackdoubleclick', FALSE)) {
_googleanalytics_cache('http://stats.g.doubleclick.net/dc.js', TRUE);
}
else {
_googleanalytics_cache('http://www.google-analytics.com/ga.js', TRUE);
}
variable_set('googleanalytics_last_cache', REQUEST_TIME);
}
}
......
......@@ -136,6 +136,11 @@ class GoogleAnalyticsBasicTest extends DrupalWebTestCase {
$this->drupalGet('');
$this->assertRaw('google-analytics.com/ga.js', '[testGoogleAnalyticsTrackingCode]: Latest tracking code used.');
// Test whether the alternate doubleclick library is used
variable_set('googleanalytics_trackdoubleclick', 1);
$this->drupalGet('');
$this->assertRaw('stats.g.doubleclick.net/dc.js', '[testGoogleAnalyticsTrackingCode]: Doubleclick tracking code used.');
// Test whether anonymize visitors IP address feature has been enabled.
$this->drupalGet('');
$this->assertNoRaw('_gaq.push(["_gat._anonymizeIp"]);', '[testGoogleAnalyticsTrackingCode]: Anonymize visitors IP address not found on frontpage.');
......
Supports Markdown
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