I'm trying to use google anayltics events but so far without any success..
What I'm doing is loading 5 pages using jQuery load function
and I want to track the "Next button" for each load. but looks like i'm doing something wrong..
This is the next button event code:
$('.NextButton').click(function () {
_gaq.push(['_trackEvent', 'fz_main_page', 'clicked']);
installation.load_page({ inner_page: next_page, comid: data.comid, outerid: data.outerid, single_app: "1" });
});
Analytics Code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25162785-2']);
_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>
What am I doing wrong?
It's possible that the installation.load_page function is preventing the trackEvent from firing. Try wrapping your load function in a setTimeout:
setTimeout('installation.load_page({ inner_page: next_page, comid: data.comid, outerid: data.outerid, single_app: "1" })', 100);
Install the Google Analytics Debugger. Look in the console (control, shift, j) for the event tracking processing.
If you don't see all of your events tracking there, then something else is up with the tracking code.
Related
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 !
Im working on setting up event tracking on a website, the user visits index.php, where he completes a quizz built with javascript, after answering each question i track the event with something like :
_gaq.push(['eventTracker._trackEvent', "myCategory", question_number.toString()]);
After the user completes the quizz he's redirected to another page : result.php where i track the landing event with :
_gaq.push(['eventTracker._trackEvent', 'myResult', myScore.toString()]);
The problem is that on analytics i can see the events with category = "myCategory" but not events with category "myResult".
Here is the code (this part is present in both index.php and result.php):
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-2']);
_gaq.push(['_trackPageview']); //an account for tracking page views
(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>
//the account we attach events to
_gaq.push(['eventTracker._setAccount', 'UA-XXXXXXX-3']);
//..... racking code as posted before
I have used _trackEvent for several links. But in google analytics it shows as 0 events and no tracking data are displayed.
Below is the code I used. Do I have to wait 24 hours to view the tracking data? or anything wrong with this?
<a href="https://sites.google.com/site/example/"
onClick="_gaq.push(['_trackEvent', 'Links', 'Bags', 'Mainlinkbags']);"
target="_parent">
tracking code
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-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)
();
Sometimes it is good practice to use "onmousedown" event instead of "onclick" because "onmousedown" is fired sooner, so GA script has more time to execute event tracking (it's only a few milliseconds difference, but can help). Try it.
http://www.w3schools.com/jsref/event_onmousedown.asp
I have been running this code for some time now on all pages. This custom variable has never shown up.
Sorry to ask this again, I don't see another post that solves my case. This has to be the simplest case in the world, this is the same code with only the UA changed:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345678-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setCustomVar', 1, 'User', 'jc', 3]);
(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>
I did not modify the (function()...) .. Do you see the problem? I'm using slot 1 with the page level (3) scope. The same code appears on each page for a given user.
_setCustomVar does not trigger a request to GA. _trackPageview does. You have to move the _setCustomVar above the _trackPageview.
I have a "Download" button on my webpage(page1). Onclick of this button, a downloadFile.php page(page2) opens and a zip file automatically downloads.
I want to track the onclick event in page1. So I have set up the Google analytics event tracking on click. The code is below:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx-1']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setDomainName', 'mydomain.com']);
_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>
Download
I also store the user(USER_AGENT) info on page load. So I get the number of downloads.
The google analytics event data shows up but, the onclick event number and the download number do not match. That is, if on click event is 85, the download count that I have recorded is 700. That big difference. I feel that the analytics click event tracking is not accurate. Is this possible? Or have I made a mistake in setting up the tracking code?