diff a/googleanalytics.admin.inc b/googleanalytics.admin.inc
--- a/googleanalytics.admin.inc
+++ b/googleanalytics.admin.inc
@@ -315,7 +315,12 @@ function googleanalytics_admin_settings_form(&$form_state) {
'#description' => t('If checked, your AdSense ads will be tracked in your Google Analytics account.'),
'#default_value' => variable_get('googleanalytics_trackadsense', FALSE),
);
-
+ $form['advanced']['googleanalytics_trackdoubleclick'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Track DoubleClick data'),
+ '#description' => t('If checked, the alternative Google DoubleClick data tracking is used to enable AdWords remarketing features. If you choose this option you will need to update your privacy policy.', 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),
+ );
$form['advanced']['codesnippet'] = array(
'#type' => 'fieldset',
'#title' => t('Custom JavaScript code'),
diff a/googleanalytics.install b/googleanalytics.install
--- a/googleanalytics.install
+++ b/googleanalytics.install
@@ -19,6 +19,7 @@ function googleanalytics_uninstall() {
variable_del('googleanalytics_last_cache');
variable_del('googleanalytics_site_search');
variable_del('googleanalytics_trackadsense');
+ variable_del('googleanalytics_trackdoubleclick');
variable_del('googleanalytics_js_scope');
variable_del('googleanalytics_custom');
variable_del('googleanalytics_roles');
diff a/googleanalytics.module b/googleanalytics.module
--- a/googleanalytics.module
+++ b/googleanalytics.module
@@ -223,8 +223,18 @@ function googleanalytics_footer($main = 0) {
$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
@@ -234,7 +244,13 @@ function googleanalytics_footer($main = 0) {
$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);';
@@ -305,7 +321,13 @@ function googleanalytics_user($type, $edit, &$account, $category = NULL) {
function googleanalytics_cron() {
// Regenerate the tracking code file every day.
if (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', time());
}
}
diff a/googleanalytics.test b/googleanalytics.test
--- a/googleanalytics.test
+++ b/googleanalytics.test
@@ -129,6 +129,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.');