Those of you with WordPress-based websites and blogs may well want to make use of Google AdWords Remarketing via Analytics, which gives more control over how your remarketing lists are defined. This requires a change of your Analytics code to call a script from doubleclick.net rather than google-analytics.com.
A common (and very good) plugin for WordPress is Joost de Valk’s (Yoast’s) Google Analytics for WordPress, which offers lots of control over how Analytics is configured for your site (and of course it automatically adds the code to your pages!) However, for reasons unknown, requests for Joost to add a remarketing code option to his plugin have fallen on deaf ears.
There are some instructions around showing how to alter the plugin code for remarketing, but the ones I’ve found are out of date, so I thought I’d write this quick guide. You are going to have to get your hands dirty editing some PHP code though! 🙂
Firstly, go to the Plugins > Editor section of your WordPress admin and choose Google Analytics for WordPress from the “Select plugin to edit:” menu on the right. From the list of files that appears below, click “google-analytics-for-wordpress/frontend/class-frontend.php”.
Now, use your browser’s Find function to locate ga.js in the script. This is usually done by pressing Ctrl-F (Windows) then typing your search term into the box that appears in most browsers.
We will now edit the code so that it calls the remarketing version from doubleclick.net instead. This is the original code:
$script = 'ga.js'; if ( current_user_can( 'manage_options' ) && $this->options['debug'] ) $script = 'u/ga_debug.js'; echo "('https:' == document.location.protocol ? 'https://ssl' : 'https://www') + 'google-analytics.com/" . $script . "'"; } ?>;
We want to edit it so that it matches this code:
$script = 'dc.js'; if ( current_user_can( 'manage_options' ) && $this->options['debug'] ) $script = 'u/ga_debug.js'; echo "('https:' == document.location.protocol ? 'https://' : 'https://') + 'stats.g.doubleclick.net/" . $script . "'"; } ?>;
When that’s done, you can click the Update File button to save the changes.
And that’s it – you have Yoast’s Google Analytics for WordPress with remarketing! There is the caveat that every time you update the plugin, you will need to make these changes again as the file will be over-written. Happy remarketing!