Hello again! So once again it's been just about forever since I last wrote but I thought this topic would be nice since there's not a whole lot pertaining to it.
Recently at work I was tasked with getting custom code working with a modal popup that would send events to a client's Google Analytics(GA). The client is using Universal Analytics so I thought simply calling ga('send','event','category','action'); would do the trick. But it was not that simple.
First I will give you the written part of my research. Google Tag Manager(GTM) is a simple way to control library's that get loaded onto your site. You can specify rules for when certain scripts or libraries are loaded. It's a great tool but like everything you need to know the caveats. When you put GA into GTM the container the script is placed in hides the ga Tracking object. Plain and simple that means you can't call ga() from an outside script....initially. GTM has a property for a tag in each container called Tracker Name. If this is not set GTM creates it's own Tracker Name each time a page is loaded. You can write client side code to find this name but now you are hard coding a value. If something would change now your script is broken. The best work around is to enable the Tracker Name but leave it blank. Now you can simply call the ga() tracking object and not have to prepend the Tracker Name to anything. Now what does that look like? I'll show you of course.
First log into GTM and navigate to the account you want to configure. Below I have a container called Blog in an account.
Click on Tags on the left hand side and select the tag you want to modify. See figure below.
You will then see three green circles with checks. The third one says "Configure Tag". To configure this one select the pen to the far right as shown below.
You will be presented with more configuration options. The one we are interested in is the "Advanced Configuration".
Under "Advanced Configuration" you fill find a setting called "Set Tracker Name". We want to enable this setting and leave it blank so that GTM will not generate it's own Tracker Name.
Now we can simply call the ga() Tracking object with out the use of a Tracker Name. Keep in mind that if you do fill in the Tracker Name you will need to prepend this to the correct property in the ga() Tracker object. GTM does highly recommend not using Tracker names. So please consider your situation before enabling this setting.
I hope this post helps some of you using GTM and GA. This certainly is not an introduction to either GA or GTM but hopefully provides some insight into an issue you are experiencing. Until next time!