Single page analytics tracking - google-analytics

I am new to GOogle Analytics. I have a single page site. It has multiple tabs that are reflected in the URL. Main url is index.html and if you switch to a different tab the URL becomes index.html?FaqPage
Is there a way to setup Google Analytics to give analytics on all the tabs seperately? I tried
ga('send', 'pageview', '/index.html');
But the analytics only seem to track index.html and not any of the ther URLs.
Also tried the following (with proer tracking code) but doesnt seem to work:
ga('create', 'UX-xxxxxxx-x', 'auto');
ga('set', { page: '/index.html?FaqPage', title: 'Faq'}, { page: '/index.html?MemberPage', title: 'Member'});
ga('send', 'pageview');

You're on the right track. One solution is to send a virtual pageview whenever a tab is clicked:
ga('send', 'pageview', '/faqpage')
And do similarly for all your tabs. Here is some more info https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications.

Related

Google analytics events not showing up

New to google analytics so bear with me. I added the event tracking to my code, but when i check in the reporting behavior event tab it's blank. Here is my 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');
ga('create', 'UA-XXXXXXXXX', 'auto');
ga('send', 'pageview');
</script>
here is an example of my a tag
<a href="http://example.com/" target="_blank" class="app-logo" ga('send', 'event', 'Link', 'Click', 'example.com');>
In google-analytics, for the correct website, look on the "realtime/events" page and see if events are appearing there (they should appear here within a few seconds, after being triggered on your website).
If not, you might have added a filter, to filter out events generated by traffic from your own IP. You can find this filter under "admin" and then "all filters". If so, remove it (or temporarily change the IP-address, so it doesn't match). After that, generate a few events on your website and look again on the google-analytics page, under realtime traffic / events page.
If they work under realtime, it should also work in non-realtime (but it might take 24-48 hours to appear there!)
Not sure if this just a typo in your example, but you are missing the event handler in your link:
The event handler ("onclick") is the bit that specifies which action shall trigger the javascript code. If you just dump the event call in the HTML it will not even be recognized as JS.

Google Analytics beacon sent but Analytics shows nothing

I installed Google Analytics (UA) and added tracking code to a html page.
I ran html page from the browser file:///C:/test.html and debugged using google debugger, it ran successfully and shows sent beacon - but Analytics does not show the numbers. I waited for a day but still does not work.
**It works fine if I place the file in c:\Inetpub\wwwwroot and run as http://localhost/test.html
-------------------Code in test.html page-------
<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-******-*', 'auto',{'storage': 'none'});
ga('set', 'checkProtocolTask', null);
ga('send', 'pageview');
</script>
Can anyone tell me if google analytics works in my case.
What you want to do should definitely work, but you'll have to modify a few other things you're sending to prevent the hit from being dropped by Google Analytics.
Basically what's happening now is your hit is invalid. As you can see here using the Hit Builder tool.
I think you should be able to get around this by using the page field instead of the location field (which is auto-populated by analytics.js when you create the tracker), like so:
ga('set', 'location', null);
ga('set', 'page', '/test.html');
ga('send', 'pageview');
I've never tried this without also setting the location field, so it's possible Google Analytics will still complain that no hostname is present (Note: I tested this with Google Tag Assistant and it did complain, but it didn't say anything about the hit being invalid, so it will probably work fine.)
If using page instead of location doesn't work, you can always just modify location and give it a fake hostname, and that will definitely work.
ga(function(tracker) {
var oldLocation = tracker.get('location');
var newLocation = oldLocation.replace('file:///C:', 'http://fakehostname.com');
tracker.set('location', newLocation);
})
ga('send', 'pageview');
In either case, you won't need to unset the checkProtocolTask because you're now not using the file protocol.
Since it sounds like hostname doesn't matter in your case, giving it a fake value should have no impact on your reports.

Google Analytics UserID Tracking Code

I'm setting up UserID tracking in Google Analytics. Google's documentation displays this piece of code to push UserIDs into analytics:
ga('create', 'UA-XXXX-Y', { 'userId': 'USER_ID' });
ga('send', 'pageview');
However, when I'm in my Google Analytic's settings area, it displays the following piece of code to include UserIDs.
ga(‘set’, ‘&uid’, {{USER_ID}}); // Set the user ID using signed-in user_id.
What is the difference between set and create? Do they both achieve the same result?
Both of them should work. Including the user id in the 'create' call includes setting it as well.
ga('create', 'UA-XXXX-Y', {'userId': 'USER_ID'});
ga('send', 'pageview');
is equivalent to
ga('create', 'UA-XXXX-Y');
ga('set', '&uid', {{USER_ID}}); // Set the user ID using signed-in user_id.
ga('send', 'pageview');
If you do copy and paste provided in GA, then you will need to change the smart quotes to straight quotes, because smart quotes will break GA.

Google Analytics event tracking counting all site hits?

I have been trying to set up event tracking for our company website and have hit a bit of a stumbling block.
I am tracking clicks to our telephone number. It appears that each website visit is being counted as call and appears under the tracking tab.
All I would like to measure is how many times people are 'clicking' to call us.
Am I overseeing something?
ga('create', 'UA-48180919-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['www........com/'] );
ga('send', 'pageview');
ga('send', 'event', 'calls', 'click', 'tel:00000000000', 9);
<a href="tel:0000 000 0000" onClick=”ga(‘send’, ‘event’, ‘calls’, ‘click’, ‘tel:00000000000’, 9);”>0000 000 0000</a>
I'm currently looking on Real Time/Events
Any help is appreciated.
Apparently, this is something that is not possible through Google Analytics alone. Instead, you have to use Google Adwords.

Cross domain tracking (universal analytic) is not working

We tried to implement auto link cross domain but it doesn't seems to work. Here is the case:
We have 2 different domains:
source.com
destination.com
When user visits source.com and click on Submit button, he is automatically redirected to the destination.com (the redirection is on the server side and not the client).
We want to have the ability to track the user action on both domains and treat it as the same user.
We have the following code on the source.com domain:
ga('create', 'UA-XXXXXX-X', 'auto', {'allowLinker': true});
ga('create', 'UA-XXXXXX-X', {'name': 'newTracker'});
ga('newTracker.send', 'pageview');
ga('send', 'pageview');
ga('require', 'linker');
ga('linker:autoLink', ['destination.com'], true, true);
And this code on the destination.com domain:
ga('create', 'UA-XXXXXX-X', 'auto', {
'allowLinker': true
});
ga('send', 'pageview');
This code is not working. we tried to use the same UA id for both but the client id seems to change between the domains and therefore I move from source.com to destination.com I see in analytics 2 different users.
We also tried to pass ourselves the _ga parameter but it also doesn't seems to work
Can anyone please advice? We can't understand what we are doing wrong.
It can be great if you can show an example code and not just reference (:

Resources