Google Analytics Script
Wondering if anyone can explain the difference between these too someone who hasn't really worked alot with coding. I tried looking online but i couldn't really find anything that really explains it.
The one currently on the website is below.
Here is the code from analytic that i need to update it to.
ga('create', 'UA-2022525-1', 'auto');
So what is the difference between (i,s,o,g,r,a,m) & (b,o,i,l,e,r)? Should i just update the old UA code on the website and leave (function(b,o,i,l,e,r)?
Re: Google Analytics Script
A little bit of coding background first. Those letters i, s, o, g, r, a, m and b, o, i, l, e, r are placeholders for the parameters that are used in a "self-invoking anonymous function'. This is another way of saying that the function that is defined, with the given parameters, will run immediately after it is has been created. It also, as you might have guessed by the word "anonymous" does not have a name. Each letter corresponds to a parameter that is to be passed into the function. The parameters are defined at the end of the function in the comma separated list (ie. "window", "document", "script", "ga"). I won't go into any more detail, but what is key here is what those functions are doing.
A note of caution. I am not an expert developer here, so definitely do your due diligence and investigate some more.
The first function looks like it could a "boilerplate" function. "Boilerplate" is a name for something that is to be used as a template - something to get you started. Typically you need to add and build functionality on top of the boilerplate. (And somebody jump in if I have misspoken). Note that this code is not officially supported by Google. Although it looks "analytics"ish to me, I can't be certain without testing it out.
The second function is very familiar (at least to this community) and is the standard tracking code. This is the code that you should be using if you want to avoid any problems with GA.
The first function could be working perfectly well for you, and if so, then go ahead and keep using it, but you need to know the risks of using that, with the realisation that there may not be a lot of support for it if it does break somehow. The second function is legit, and if you have problems with it, then at least you can always come back here for support.
Hope this helps.
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.
Find me on: Google+ | LinkedIn