The Event is not genrated with Track Event in Google Analytycs - google-analytics

I am generating the Event tracking in Google analytic. but i can not see the event is generated with in Behavior link -> Events -> Overview.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-46891304-1']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
_gaq.push(['_trackEvent', 'ProfileMenu', 'MenuClick', '', 1]);
</script>
</head>
<body>
<h1>This is for Tracking Event..!!!</h1>
</body>
</html>
Regards

You need to attach the event tracking script on to a event listener.
Your event tracking code does not seem to be attached to anything.
For example if I wanted to track a button click this is how I would write it with jQuery.
html
<button id='button1'>Button<button>
JavaScript/jQuery
$('#button1').click(function(){
//fires the event tracking method when button is clicked.
_gaq.push(['_trackEvent', 'Category', 'Action', 'Opt Label', Opt Value, 'Opt non-interaction'])
})
Here is all the documentation https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
And here is a post that I went in more in depth into event tracking.
Let me know if you have any other questions.

It takes 24 hours for data to be processed. Before that time you should be able to see your events in the Real-time reports under
Real-time -> events.
after 24 hours has passed the data should show up under.
Behavior link -> Events -> Overview.

Related

Event Tracking - Web Tracking (ga.js) not working on Mobile

I am trying to capture an event when the user clicks a link on my website.
I have added the tracking code at start of <body> tag
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-64301593-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
and then I am using
onclick="_gaq.push(['_trackEvent', 'landing_page', 'i_am_interested_click']);
on the <a> tag where I want to track an event.
It is working perfectly fine for all browsers on Desktop and I am able to see the events on Google Analytics Realtime -> Events tab. However same thing does not work for any browsers on mobile (I have tried Chrome and Firefox).
I have another hyper-link on the same page where I am tracking another event, this time by creating a jquery listener for the on-click event. However, that also does not work for mobile browsers (works on Desktop browsers).
The jquery code is as below:
$("#contact_me_button").click(function(){
$(this).fadeOut("slow", function() {
$(this).html("<a href='tel:+918695707070'>+918695707070</a>");
$(this).fadeIn("slow");
});
fbq('track', 'Lead');
_gaq.push(['_trackEvent', 'landing_page', 'call_attempted']);
});
Need help as I am new to this.
Thanks in advance !

GA - Experiments does not work

we try to set up experiments in our site. We would like to testing 3 type of banner on our home page.
1. If anybody click on the banner, makes event, which si set up as a goal in GA. This goal measure clicking correctly.
2. We implement code for measuring experiments and made javascript function for changing banners, they changing well.
3. For set up whole experiments in GA and in code we follow this documentation: https://developers.google.com/analytics/solutions/experiments-client-side
Finnaly our whole GA script on site looks this:
<script src="//www.google-analytics.com/cx/api.js?experiment=sTe5dJkJTfmSO8YXsc7Kuw">
<script>
var variation = cxApi.chooseVariation();
cxApi.setChosenVariation(variation);
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript" src="http://oursite.cz/js/ga.js"></script>
<script type="text/javascript">
_gaq.push(['_trackPageview']);
</script>
Problem is, that experiment does not work. It does not measure anything. When we try to look on console, what data are sending, we realize, that ` correctly send hash Te5dJkJTfmSO8YXsc7Kuw, but that is all, There is no data of variation type, which was choosed by
<script>
var variation = cxApi.chooseVariation();
cxApi.setChosenVariation(variation);
</script>
It should sent 0 or 1 or 2, but it send nothing. What we make wrong? Thank you for answer,
You're missing the closing tag when loading the content experiment.
You have:
<script src="//www.google-analytics.com/cx/api.js?experiment=sTe5dJkJTfmSO8YXsc7Kuw">
Should be:
<script src="//www.google-analytics.com/cx/api.js?experiment=sTe5dJkJTfmSO8YXsc7Kuw"></script>

Integrating google analytics in webapp: not able to log user interactions

I have created a webapp using backbone.js and I am trying to integrate google analytics in it. The thing is script execution always stops at some point inside ga.js. The code where the execution stops is like this (beautified version) ...
var o = e == "_gat" ? K : e == "_gaq" ? Tc : K.p(e);
o[f].apply(o, b[d][ha](1))
minified version (line 21)
new ActiveXObject(d),e=c.GetVariable("$version")}catch(o){}e&&(e=e[w](" ")[1][w](","),e=e[0]+"."+e[1]+" r"+e[2])}b=e?e:"-"}Pc=b;
I am logging the events like this:
_gaq.push('_trackEvent', '[header] login', 'click');
I am seeing the code being stopped at the live above in Firebug script tab. If I disable the debugging the google analytics request is not made. The app works fine.
What could be going wrong here? Has anybody else encountered such problem.
UPDATE
It seems like the problem is not related to backbone.js. Even created the simplest of page like this gave the same problem. I checked the Net tab in Firebug - the __utm.gif does load. ga.js also loads successfully. But the pressing the button again gives the same break in execution.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'XX-XXXXXX-XX']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript">
function check() {
alert("hi");
_gaq.push('_trackEvent', 'check');
}
</script>
</head>
<body>
<input type="button" value="abc" onclick="check();"/>
</body>
</html>
You're calling _trackEvent wrong. Note that the first 2 parameters to _trackEvent are required and the last 2 optional. Also it should be inside brackets.
Check the signature of the function.
You're call should be
_gaq.push(['_trackEvent', '[header] login', 'click']);
and
_gaq.push(['_trackEvent', 'check', 'something else']);

Google Analytics: Page views tracked but not ecommerce transactions

I'm trying to figure out why the Ecommerce tracking in Google Analytics doesn't seem to work. I can see the page views correctly tracked but no transactions.
Snippet from the confirmation page:
<head>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
_gaq.push(['_setDomainName', '.mydomain.com']);
_gaq.push(['_trackPageview']);
_gaq.push(['b._setAccount', 'UA-YYYYYYYY-1']);
_gaq.push(['b._setDomainName', 'none']);
_gaq.push(['b._addTrans',
'44bbd391-ff38-4f8d-ad68-aec490666151',
'Name',
'1.00',
'',
'',
'',
'',
''
]);
_gaq.push(['b._addItem',
'44bbd391-ff38-4f8d-ad68-aec490666151',
'15',
'test',
'',
'1.00',
'1'
]);
_gaq.push(['b._trackTrans']);
_gaq.push(['b._trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
...
</head>
I'm monitoring the traffic on the page with Firebug confirming that all pixel requests were made and came back OK.
I read about having to wait a few hours, up to one day, before you can see results in GA, but I can see the page views after only waiting a few minutes.
However, the transactions tracked using the same tracker object ("b") are not to be found anywhere(could the Ecommerce reports be refreshing slower than the page views?)
And I finally found the issue. The answer is inconspicuously present on the GA docs page:
_trackTrans()
Sends both the transaction and item
data to the Google Analytics server.
This method should be called after
_trackPageview(), and used in conjunction with the _addItem() and
addTrans() methods.
It's rather easy to overlook but it has such a fundamental effect: transactions won't be tracked.
So yes, always call _trackTrans after _trackPageview!

My Custom Variables are not showing up in Google Analytics

I have been trying to setup a custom variable for the past few days and it hasn't been working.
My Google tracking code is part of a master page (asp.net concept) so I can't set the custom variable inside the second script block labeled "Async Google Code" because it is shared by many other sections.
Below is my code and the order it appears in my page. Is there any way I can set it outside the "Async Google Code" script?
<head>
<!-- Setting Custom Var -->
<script type="text/javascript">
$(function () {
_gaq.push(['_setCustomVar', 1, 'Account', 'UserType', 2]);
}
</script>
<!-- Async Google Code -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
wrap your custom variable stuff in a function to be called and insert a call to that function between the var _gaq... and _trackPageview lines in the bottom piece.
Your "setting custom var" code is missing an end bracket.
You need to set the custom variable before track pageview. You have the custom var in the jQuery document ready shortcut, making it so that it happens after the trackpageview.

Resources