google analytics events on links fail on Chrome - google-analytics

I am installing google analytics on some links
javascript:_gaq.push(['_trackEvent', 'category', 'browse', '/hair'])
here's how the link is
<a onclick="javascript:_gaq.push(['_trackEvent', 'category', 'browse', '/hair'])" href="/hair"><i class="icon-"></i>Hair (162)</a>
if I click on the link the push event is not getting recorded.
If I hit the same code from the console then the event is recorded.
NOTE: on Firefox the event are getting recorded properly. So far this only happens on Chrome! :S
Any ideas?

You need the "javascript:" bit only if you put the js in the href attribute (as a protocol designation of sorts). For a click event the javascript method itself will suffice, so your example should look:
<a onclick="_gaq.push(['_trackEvent', 'category', 'browse', '/hair'])" href="/hair"><i class="icon-"></i>Hair (162)</a>
I'm taking a quite educated guess here that FF is more forgiving with the irregular syntax than Chrome. Maybe you can look at the Chrome developer console if this throws an error (or simply fix it and see if things improve).

Related

OnClick - Uncaught SyntaxError: Invalid or unexpected token

I'm having trouble getting an OnClick event to send back to Google(Universal) Analytics.
Here's the line in question:
<a href= “link-to-asset-goes-here” onclick="ga(‘send’, ‘event’, ‘Button’, ‘Click’, ‘AllVisits_Free’, {‘NonInteraction’: 1});”>
When I inspect with Chrome Dev tools, I'm seeing this error: "Uncaught SyntaxError: Invalid or unexpected token"
When looking through other questions, I found this one:java - OnClick error
Could it possibly be just escaping all the strings then? Like so:
<a href= “link-to-asset-goes-here” onclick="ga(\‘send’\, \‘event’\, \‘Button’\, \‘Click’\, \‘AllVisits_Free’\, {\‘NonInteraction’\: 1});”>
Would that cause any issues with the NonInteraction part of the code?
Unfortunately I don't have access to test this live, and have to send each code revision over to the client each time, or I could just test different variations of code a lot easier.
And just for reference, we're using the newest version of GA(Universal) analytics tracking code. When looking at the Real Time reports in GA, it's registering that I'm on the page, but events are not firing when clicking the link.
Thanks!
If that it the exact code format you are using, then try using straight quotes rather than the smart quotes:
<a href= "link-to-asset-goes-here" onclick="ga('send', 'event', 'Button', 'Click', 'AllVisits_Free', {'NonInteraction': 1});">
....Something with smart quotes not playing well with JavaScript.
I was getting the same error while using this onClick code.
Straight codes worked for me.
The mistake which I made was copying the code snippet from the website. Enter the quotes directly from the keyboard and it will work great!
Also for quick debugging, use the GA Debugger, it helped me resolve the error quickly.

Google Analytics Events Tracking not working

I've being tried to install google events tracking on several sites but with no luck. I really want to know why its not working.
I installed events tracking on this site http://bedsndrinks.com/, the second "Book Now" button, here is the code I added to the button onClick=”ga(‘send’, ‘event’, ‘book form’, ‘click’, ‘book now’);“
I tried to use Google Analytics Debugger, but I don't see any "event" hitType. one thing I noticed is that the tracking code looks okay in source code but different when I inspect it in Chrome.
You need to check how your onclick is being rendered. When I loaded the page I saw the following:
<input id="sendBook" type="submit" value="Book Now"
onclick="”ga(‘send’," ‘event’,="" ‘book="" form’,="" ‘click’,="" now’);“="">
As you stated in your question, the format should be as below:
onclick="ga('send', 'event', 'book form', 'click', 'book now');

Did I implement this Google Analytics Event Tracking Correctly?

Did I implement this event tracking correctly? I want to measure clicks on a call to action at the bottom of a blog post:
<a href="http://marketingcuriosity.com/download-a-350-page-ebook-about-digital-analytics-for-free/" onclick=”_gaq.push([‘_trackEvent’, ‘CTA’,’click’, ’red-button’])”></a>
For some reason It's not populating data in my reports.
This is perfectly fine! I would just add a semicollon at the end and make sure you use correct apostrophe in your code
onclick="_gaq.push(['_trackEvent', 'CTA', 'click', 'red-button']);"

Tag parameters only come through on new tab

I'm using Google Analytics via Google Tag Manager. I'm on Chrome and checking tags using Google Tag Assistant.
I've noticed that for many, if not most of the events I have tagged, the parameters will not pass through unless the link or key webpage they are clicking on opens in a new tab.
In HttpFox the result is a NS_BINDING_ERROR or something along those lines.
For example, if you visit this site, you can see there are two means of navigating to the "submit report" page - the CTA on the top right and in the main nav. I'd like to understand how the CTA performs compared to the main nav so have set up events, but the event only fires if I open the links in new tabs.
What does this error mean and what should I do about it?
To get rid of the ns binding error, have the onclick return false - Documentation Here.
In regards to the event not getting passed, I'm seeing in httpfox that the tid (on the event) is UA-34035531-[1-6]. That doesn't look quite right. How are you setting the account id?

Window.open javascript function is not working in Mozilla, but working in other browsers

Window.open javascript function is not working in Mozilla, but working in other browsers, here is what I have write.
<a href="javascript:window.open('../Terms.aspx','Terms','width=550,height=400')">
click here</a>
Actually what happened in Mozilla is popup is opened but parent window is blank with [object Window]
Please tell me What I am doing wrong?
Thanks
The script looks all right, what might be a problem is that you are running it in the URL. Use the click event instead.
Also, you can use the href and target attributes in the link to make it degrade gracefully. That way the link will at least open up the page even if Javascript is disabled in the browser:
<a href="../Terms.aspx" target="Terms" onclick="window.open(this.href,this.target,'width=550,height=400');return false;">
click here</a>
Try a generator.
Alternatively, you might want to try href="javascript: randomVar = window.open ...". The issue might be that the window.open function returns an ID, thus breaking the in-line JavaScript.

Resources