I had to hack this out on the SwellPath site today so I figured I’d share it. If you’re using the Google Analytics for WordPress plugin for your WordPress site, and you want to enable Remarketing for Google Analytics, you need to tweak one of the plugin’s files.
Change line 1126 of /wp-content/plugins/google-analytics-for-wordpress/googleanalytics.php
from:
$script = ‘ga.js’;
to:
$script = ‘dc.js’;
And then change line 1129 of /wp-content/plugins/google-analytics-for-wordpress/googleanalytics.php
from:
echo “(‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/” . $script . “‘;”;
to:
echo “(‘https:’ == document.location.protocol ? ‘https://’ : ‘http://’) + ‘stats.g.doubleclick.net/” . $script . “‘;”;
Note that if you upgrade the plugin, it’ll probably overwrite these changes. So make sure you upgrade first, or make the changes again after upgrading. That is it. Happy remarketing!






I did this today just as you described and it killed my GA Experiments. If you create a new Experiment or go to ReValidate an existing Experiment it says it can’t find the tracking script for GA. Any ideas how to make both work? Thanks – Bryan
Bryan, I’m not sure how to do that. I’ll look into it if I have a chance.
This has been helpful but I found one small thing you left out which causes analyitics to be set up incorrectly and not track data correctly. I found this out because I was trying to create a content experiment and it check for correct google analytics code and it failed. it need to reference the doubleclick javascript file (dc.js) instead of the google analytics file (ga.js).
on line 1125 you will notice:
$script = ‘ga.js’;
For Doubleclick it needs to be:
$script = ‘dc.js’;
which will result in the following code on your page:
ga.src = (‘https:’ == document.location.protocol ? ‘https://’ : ‘http://’) + ‘stats.g.doubleclick.net/dc.js’;
Ahh, I forgot that part, and then just broke this on our site by following my own directions. Updated the post. Thanks for pointing it out.
Thanks for that post! Very helpful. Took me 2 minutes. Had to do the same for Magento storefront as well. This one was easier.
Glad it worked for you Tim!
Looks like Yoast has updated where this code lives.
Change line 297 /wp-content/plugins/google-analytics-for-wordpress/frontend/class-frontend.php
from:
$script = ‘ga.js’;
to:
$script = ‘dc.js’;
And then change line 300 of /wp-content/plugins/google-analytics-for-wordpress/frontend/class-frontend.php
from:
echo “(‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/” . $script . “‘;”;
to:
echo “(‘https:’ == document.location.protocol ? ‘https://’ : ‘http://’) + ‘stats.g.doubleclick.net/” . $script . “‘;”;
Thanks guy!