0

I am trying to track a user logging in with GA. I have my custom_var code occuring onClick of the login button.

<input type="submit" formtarget="_blank" onClick="_gaq.push(['_setCustomVar', 1, 'Users Login', '$("#user_login").val());', 3]);"/>

"#user_login" is the field containing the information I need passed.

I am using the formtarget attribute to open in a new window. This was after thinking that maybe the onClick event was not running before the page was being redirected.

This custom event is not being tracked when I log in to the account, but page views are. At first, I thought there was an issue with my code, so I tried tracking a regular event on click of an anchor:

<a href="/about-us/about-discovery-capital/" onclick="_gaq.push(['_trackEvent', 'Testing', 'Click', 'About']);">About</a>

The same issue occured, page views are fine, but the event is not tracking.

  • The GA code that I am using is up to date and in the correct place.
  • The site is password protected, but as the page views are being tracked I dont see this as an issue.
  • I have run the GA debugger chrome extention, but I am getting no errors

Unfortunately due to the client, I cannot provide the website.

If you could shed light on what possible reasons there could be for page views tracking, but not events, would be a great help!

Cheers

roryWolf
  • 3
  • 3

1 Answers1

1

Open Firefox and download the HTTPFox plugin. Click your links with the events on them. Are they showing up red and saying aborted? If so, you're running into an issue where the event/custom variable isn't given enough time to fire the event before the next page loads, thus aborting the request.

The solution: hitCallback

The hitCallback function will let send your visitor to the next page once it receives the callback from Google Analytics saying the event has been received.

I wrote an article on how to use it inline, like in your case. You can check that out here - When to use hitCallback.

Community
  • 1
  • 1
Blexy
  • 9,573
  • 6
  • 42
  • 55
  • Thanks Blexy. I have run HTTPFox but no errors are returned. The only corresponding GA feedback given is this line: GET http://www.google-analytics.com/collect [HTTP/1.1 200 OK 33ms]. Should I attempt hitCallback or does this mean that isnt the issue!? – roryWolf Jan 21 '14 at 20:20
  • By the way, that is a very well written article. Very easy to understand and follow. Much appreciated. – roryWolf Jan 21 '14 at 20:26
  • If you're getting a 200 OK, then you're ok. Are you seeing the event show up in real-time reports? – Blexy Jan 21 '14 at 20:56
  • Ah, I think I just realized what the issue is... in order to set a custom variable, you have send it along with a pageview or an event - more info [here](https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables#setup) – Blexy Jan 21 '14 at 20:58
  • I have added the _trackEvent snippet. When I look at the Real-Time reports, it states there is 1 visitor active, which is good, but under Events on the same page, the view is empty – roryWolf Jan 21 '14 at 22:08
  • So when you click the About link, there is no event showing up in the real-time reports? Can you take a picture of the request getting sent? – Blexy Jan 21 '14 at 22:50
  • No, no events showing up in the real-time reports. How can I get a screenshot of the request for you? Are you referring to the Network tab information? – roryWolf Jan 22 '14 at 00:12
  • Hey @roryWolf, shoot me an email and we can talk there - nicholasblexrud@gmail.com – Blexy Jan 22 '14 at 16:07