AdWords
1.8K members online now
1.8K members online now
Use AdWords conversion tracking and reporting to measure your results. Have a question about Google Analytics? Post it here, on the Google Analytics Community!
Guide Me
star_border
Reply

Which traditional ga.js code is enabled to do remarketing?

Explorer ✭ ✭ ☆
# 1
Explorer ✭ ✭ ☆

Hi people,

 

I have been using the Classic Analytics Web Tracking (ga.js) on my webpage, which the code is exactly like this below:

 

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document
.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
 
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
  pageTracker
._trackPageview();
} catch(err) {}
</script>

 

 

Recently I'm about to do remarketing, and found a Google help centre page on how to modify the code for it. However, the classic ga.js code that Google refer to is not quite the same as mine shows above, which is:

 

 

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxx-y']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

ga.src=('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

 

 

 

I'm a bit confused of what's the change I should make next. So far I don't want to upgrade to Universal Analytics code. Anyone has idea which ga.js code is correct and what change I should make to recognize the remarketing function?

 

Thanks,

Jason

Marked as Best Answer.
Solution
Accepted by topic author Jason Zhang
September 2015

Re: Which traditional ga.js code is enabled to do remarketing?

Collaborator ✭ ✭ ✭
# 2
Collaborator ✭ ✭ ✭

Hello,

 

They are both correct, the second code is called "asynchronous JavaScript" and optimizes the way ga.js loads.

I think using Display Features only works with the second code.

 

I would recommend to replace your current code with the second one asynchronous, by changing only the UA number to your own in the second code. After the change test if it works with the Tag Assistant plugin from Chrome found here :

 

https://chrome.google.com/webstore/detail/tag-assistant-by-google/kejbdjndbnbjgmefkgdddjlbokphdefk?h...

 

Also you can test by visiting your site and looking in Google analytics at the real time report.

Re: Which traditional ga.js code is enabled to do remarketing?

Explorer ✭ ✭ ☆
# 3
Explorer ✭ ✭ ☆
Hi Adrian,

That was really helpful! Thanks so much and I will accept as the solution.

May I ask a follow-up question? To do display remarketing, should I also put this second code on every page of my website? Since it's not Universal Anayltics so it have to be manually put on the page that matters with audience targeting.

Best,
Jason
Marked as Best Answer.
Solution
Accepted by topic author Jason Zhang
September 2015

Re: Which traditional ga.js code is enabled to do remarketing?

Collaborator ✭ ✭ ✭
# 4
Collaborator ✭ ✭ ✭

I would replace the old code on all pages with the second code but to use Analytics remarketing you need to replace the line from your example :

 

ga.src=('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

 

with this line

 

ga.src=('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';

 

The help page you linked in your first message explained this part of replacing a single line to use remarketing under the paragraph "Modify your tracking code" .

Basically remarketing is done by tracking the user browser through a cookie placed by the dc.js javascript code.

 

To check if Analytics remarketing is active and collecting visitors , go in AdWords in the Shared Library / Audience menu and look to the right for a message such as

"Remarketing tag

Google Analytics tag last active at 12:23 PM"
This message will probably be active after 48 hours of changing the analytics code.

The complete code will look like this (taken from the help center) :

Code modified to enable these features<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxx-y']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

ga.src=('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>