2

I have a website with two Analytic codes:

<!-- Google Analytics Content Experiment code -->
<script>function utmx_section(){}function utmx(){}(function(){var
k='1234567-0',d=document,l=d.location,c=d.cookie;
if(l.search.indexOf('utm_expid='+k)>0)return;
function f(n){if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.
indexOf(';',i);return escape(c.substring(i+n.length+1,j<0?c.
length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;d.write(
'<sc'+'ript src="'+'http'+(l.protocol=='https:'?'s://ssl':
'://www')+'.google-analytics.com/ga_exp.js?'+'utmxkey='+k+
'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().
 valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+
'" type="text/javascript" charset="utf-8"><\/sc'+'ript>')})();
</script>

<script>utmx('url','A/B');</script>
<!-- End of Google Analytics Content Experiment code -->

and

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-    1234567-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '1234567-1');
</script>

I have read on a website from Google, what these codes do. What I don't understand is, how to implement them. Could anyone please explain to me in simple words how to implement it? I must have both the codes on every page of my website? What is the difference between both?

5
  • What experiment are you doing? Commented Aug 7, 2019 at 10:44
  • I not making no experiment...I ask it because I don't understand when implementing bother...
    – biotza
    Commented Aug 7, 2019 at 11:56
  • If you aren't doing an experiment, you don't need the first snippet at all. It is only if you are testing how something works in an A/B experiment. Commented Aug 7, 2019 at 12:08
  • Do you think for a simple Website I not to need it? my Website, linuxusers.net
    – biotza
    Commented Aug 7, 2019 at 12:23
  • 1
    If you don't know what it is for, then you don't need it. If you don't know how to do an A/B test, then it is pointless. Commented Aug 7, 2019 at 14:22

1 Answer 1

2

You usually include the Google Analytics code in the header of your page template so that it loads on every page. Google recommends to paste both of these pieces of code right after the opening <head> tag in your document.

As to what is the difference between the two:

The first (Google Analytics Content Experiment code) is something you need when you run A/B tests on your pages. It needs to be present on at least one of the pages that is part of the experiment.

The second (Global site tag (gtag.js)) is the code you need to use Google Analytics at all.

I hope this makes things clear for you. If not, feel free to ask more questions.

2
  • Very Thanks for your explain! so, I will have now both on all site from my website...
    – biotza
    Commented Aug 7, 2019 at 12:00
  • Glad to help! Good luck!
    – WSU
    Commented Aug 8, 2019 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.