Google analytics not tracking outbound links - google-analytics

I've got the following code in the head which isn't tracking outbound links:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxxx-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>
<script>
/**
* Function that tracks a click on an outbound link in Google Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label.
*/
var trackOutboundLink = function(url) {
ga('send', 'event', 'outbound', 'click', url, {'hitCallback':
function () {
document.location = url;
}
});
}
</script>
And have added the event tracking on outbound links as stated on the analytics site:
onclick="trackOutboundLink('/WEBSITE/www.something.com')
What am I doing wrong? No outbound links are being tracked.
Update - changed the tracking code to universal; which event outbound tracking do I use?
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxx-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->

uname12, the issue is that you are mixing "old" Google Analytics tracking code and "new" Universal Analytics tracking code syntax.
UPDATE to my original answer to reflect changes to original question:
I would try using the correct address, so instead of:
onclick="trackOutboundLink('/WEBSITE/www.something.com')
try this:
onclick="trackOutboundLink('http://www.something.com')
ORIGINAL answer:
That's the reason why the tracking doesn't work. Here is the correct documentation for event tracking (always look GA.js).
If you change your code to something like this:
var trackOutboundLink = function(url) {
_gaq.push(['_trackEvent', 'Outbound', 'Click', this.href]);
setTimeout('document.location = "' + this.href + '"', 100);
return false;
}
That should do the trick.
Hope this helps :-)

Related

Event goal not getting recorded in Google analytics

I have set up a form through contact form 7 in a website. I have added Google analytics tracking code to set up a event goal on form submission. The event seems to get monitored on real time basics as in every form submission is triggering a event under the events tab. But the data seems to not get recorded as a goal under the conversion tab. Can someone find a solution to this.
I have used the following tracking code:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore (a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
analytics.com/analytics.js','ga');
ga('create', 'UA-18282623-2', 'auto');
ga('send', 'pageview');
</script>
and have set this code under the additional setting bar of contact form 7 to trigger the goal event:
on_sent_ok: "ga('send', 'event', 'contact-form', 'click', 'submit form',1);"
where I have set
contact-form = Category
Action = click
Label = submit form
Value = 1
I have also tried with this code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18282623-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>
along with:
on_sent_ok: "_gaq.push(['_trackEvent', 'contact-form', 'click', 'submit form']);"
Nothing seems to work. Please help
enter image description here
enter image description here
Your goal configuration includes a value greater than 1, but your event is sending a value exactly equal to 1. You will either need to adjust your goal configuration to convert when the value is equal to one or send a value for your event greater than one.

Google Analytics - Event Goal Conversions not tracking

I am trying to implement google analytics and I'm running into a problem where the tracking beacons are being sent, and the conversion goals are not being recorded. What I'm trying to do is show a modal and record whether the modal is submitted or closed. The goal setup I'm using is this:
Category: SignUp
Action: Newsletter
Label: Manual
Value: GreaterThan 1
These are the two things I've tried for the analytics code:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'MyAccountNumber']);
_gaq.push(['_setDomainName', 'MyDomainName']);
_gaq.push(['_setAllowLinker', true]);
_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);
})();
function _trackEvent(category, action, label, value, nonInteraction){
nonInteraction = nonInteraction || false;
_gaq.push(['_trackEvent', category, action, label, parseInt(value), nonInteraction]);
};
And this
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'MyAccountNumber', 'auto');
ga('send', 'pageview');
function _trackEvent(category, action, label, value){
ga('send', 'event', category, action, label, value);
};
I am calling _track event as such:
_trackEvent('SignUp', 'Newsletter', label, 0);
$('#modalSubmit').click(function() {
_trackEvent('SignUp', 'Newsletter', 'Manual', 1);
});
As I previously said, the tracking beacons are being sent, but there is no data showing up in the Reporting section. The dates for the report are set to yesterday through tomorrow. Also, if I'm not handling the abandonment rate correctly, what is the correct way to handle this? Thanks in advance!
You should only use the universal tracker. It's more accurate.
Make sure you're receiving data then troubleshoot events accordingly. You can check the tracking code status in the Admin section of GA: https://support.google.com/analytics/answer/1008083?hl=en
Google Analytics generally updates your reports every 24 hours, so it can take at least that long for data to appear in your account after you first install the tracking code: https://support.google.com/analytics/answer/1009219?hl=en

Google Analytics tracking code not installed

i am using google analytics to track my site. They said to add a tracking.js code to my site in every page to track the site. For which i made a google_analytics.js file, wrote the code there and included this file in everypage i need to track. But Google Analytics page is saying that track is not installed!
Google analytics provide this service through two js - ga.js and another is analytics.js
For ga.js, you need to write following code in each html page of your site -
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-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>
if you are using analytics.js, you need to write below code in each page of your site -
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXX-Y');
ga('send', 'pageview');
</script>
please see this link for more info -

Google Analytics Tracking GA.js vs Analytics.js

I'm trying to use this code to track an event in Google Analytics
_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
This seems to be meant to be use with the GA.js Analytics "package", however I'm using the Analytics.js
Like this
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
Is there a way I can do even tracking with this code only ?
Or do I have to use
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-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);
})();
Do I need both of these codes?
Or is there some different way using only Analytics.js
Thanks in advance
**EDIT:
Indeed I probably didn't explain what I want, it might not even possible.
I want to work with Funnels on Events, and I want to use _trackEvent (that's what I thought it would do) to mark a user as having Entered the Funnel, if the event is send then we will have the normal funnel.
So if 10 users enter the page and 1 clicks on the button, I would have 10 events on the Funnel with 1 success
analytics.js will report to GA same as the old code, but it has different syntax, so you can't use _trackEvent.
Here is a link to the basic on-page syntax with analytics.js, and here is a link for event tracking with analytics.js
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXX-Y'); // GA account ID goes here
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'category', // Required.
'eventAction': 'action', // Required.
'eventLabel': 'opt_label',
'eventValue': opt_value,
'nonInteraction': opt_noninteraction
});
</script>
<!-- End Google Analytics -->

Confused between Google's Universal Analytics and Async Analytics. Are we supposed to use both?

After setting up Google analytics for the first time I went to Admin > Tracking Code:
So apparently this is Universal Analytics given to me.
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('send', 'pageview');
</script>
I can't find my asynchronous tracking code (which would look like this):
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-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>
Am I only supposed to use one?
Do they both go right before </head>?
As universal is in beta, I would continue using ga.js tracker on your primary web properties.
If you want to try out the new functions (e.g. custom dimensions/metrics) of Universal, you can create a new property specifically for it.
Also, to simplify deployment, try Google Tag Manager.

Resources