Setup Google Analytics with Meteor App: Tracking not Installed Error - javascript

I am Trying to set up Google Analytics with Meteor and always get a Tracking not installed Error.
I have already tried to use the meteor Packets, I have tried to include the tracking code in the Head Section, in the Body section and as a rendered Callback on a template.
I always get the error from the Google Analytics Site "Tracking not Installed"
What is the best practice of GA tracking in Meteor Apps?

You don't need a package for GA, probably easier to do it yourself, like this:
First, put the GA tracker id in Meteor.settings.public. (more info about that here)
Then, create a file for the client, probably in the lib folder, for example /client/lib/google_analytics.js and add the regular GA tracker to it:
// CLIENT
/*****************************************************************************/
/* Google Analytics */
/*****************************************************************************/
if (Meteor.settings.public.GaTrackingId) {
(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');
}
Last, create another file to track the page load. You can do this in a Meteor.startup() method, but you don't have to as the tracker code is in /lib which is loaded before everything else.
// CLIENT
if (Meteor.settings.public.GaTrackingId) {
ga('create', Meteor.settings.public.GaTrackingId, 'auto');
ga('send', 'pageview');
}
That's it. Now you can also do GA event tracking, etc. from anywhere in your app if you'd like to.

Related

Google Analytics not working with Barbajs

Trying to use the latest google analytics tracking code in a site that uses Barba JS but it will not track past the first page, ie the path of the user, any ideas anybody?
The reason it is only working on the initial page is that the default GA snippet implemented using gtag.js only runs once after load. Since you're using it in a SPA setting, you need to manually re-send the page data when you route. Looking at the barbajs documentation, I think it'll be something like this:
// define a global hook, using afterEnter, but you can adjust to enter, beforeEnter, etc as you see fit.
barba.hooks.afterEnter((data) => {
// this hook will be called for each transitions
//data.current.url is the page path.
gtag('config', 'UA-#######-1', {'page_path': data.current.url});
});
use full code provide with google annalitics
https://developers.google.com/analytics/devguides/collection/analyticsjs/?hl=en
in you JS add
(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-XXXXX-Y', 'auto');
ga('send', 'pageview');

analytics.js URL Calls

I use analytics.js on a html page behind a hotspot. So the internet connection is limited to certain URLS.
I need to open on walled garden all the URLS used by analytics.js to make work correctly google analytics.
I did add:
ssl.google-analytics.com
*google-analytics*
*doubleclick*
But still need more URLs.
I've tested that adding
www.google.es and www.google.com analytics works ok and no errors appears on the urls called by analytics.js but I can NOT open www.google.es and www.google.com for other devices uncompatibility so I need to know the URLs need to be opened to have analytics working ok.
I found reading analytics.js that there is:
https://ampcid.google.com
https://www.google.%/ads/ga-audiences
google.com(:\d+)?\/optimize\/opt-launch\
I did add this URLs + Folders on walled garden but still not enought.
Can anyone help me on build all the URLS+Folder list used by analytics ?
Thanks a lot.
Added Image I can see on Network from a browser:
Added 2:
I have this script:
<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-48205710-1', 'socialwibox.com');
//ga('send', 'pageview');
</script>
And have problems just when calling ga('send', 'pageview');
without ga('send', 'pageview'); i don't have problems.
Oscar.
The basic endpoint for Google Analytics collecting data is
POST/GET /collect HTTP/1.1
Host: www.google-analytics.com
Additionally, demographics data may go to
http[s]://stats.g.doubleclick.net/r/collect
analytics.js script is loaded from
http[s]://www.google-analytics.com/analytics.js
if gtag.js or google tag manager is used they are loaded from
http[s]://www.googletagmanager.com/gtag/js?id=XXXX

How do I integrate Google Analytics into GWT applications?

I have two problems...1. I have never used google analytics, and 2. I have never used, made, or touched a GWT project until now. I am trying to get google analytics to work with a GWT application. I read through this: How to integrate Google Analytics into GWT using the asynchronous script and the question that it links to with no luck.
There is a new version of Google Analytics out which uses a new
analytics.js script. It's the same process though, just add the script
in your html header:
<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-YOUR_ACCOUNT-X', 'auto');
ga('send', 'pageview'); </script>
For my case, the project is large and I am not sure which html file I need to put the google analyics js in. I am assuming the html files in the war folder.
As for this bit:
call the new methods like so:
public static native void googleAnalyticsTrackPageView(String url)/*-{
$wnd.ga('send', 'pageview', url); }-*/;
I am totally unsure where I need to include this.
Oh, one last question. Is this still how I would test locally?
ga('create', 'UA-XXXX-Y', {'cookieDomain': 'none'});
In your war folder there should be an index.html or index.jsp file that serves the GWT JS file (xxx-nocache.js). You need to put the script there.
Alternatively you can also use Arcbee's universal-analytics library.

Google Analytics Real-Time not showing results

The following script is not generating activity when cross-checked in Google Analytics : Real-Time section : Content section --
<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-475021xx-x', 'auto');
ga('send', 'pageview');
</script>
where xx-x masks the real account code.
The script is placed just before </head>
We have upgraded our account to Universal Analytics. Google tells us that this is the script to use; directly copied and pasted here (with the masked account code).
On the Google Analytics page, the test page is loaded as an ACTIVE PAGE. I click links on the test page to trigger ga.
Is there an error in this script? For example, I see on other Stackoverflow posts that 'auto' is replaced with the real domain. But I don't see Google instructions to make that substitution.
Am I doing something else wrong?
I did the same thing as you back then.
Mine started showing data in about 12-24 hours after I put the Google Analytics code.
I suggest waiting for another day then checking if data comes up.
Given that this answer can only be verified until we wait for a certain amount of time, please hold off setting this as the correct answer until then.
For me, the issue was a dunce move. I have the Google Analytics Opt-out Add-on for Chrome enabled.
What I had to do was go to chrome://extensions/, scroll down to the Extension "Google Analytics Opt-out Add-on (by Google)" and uncheck the box that says, "Enable".
I hope this helps someone.
You can check the health of your tag using Google tag assistant, and also check with developer tools whether you can see data being sent to your GA account. Also look in your account under Property > Tracking Info > Tracking Code for the status of your tracking code. But if you are not seeing Real Time data then something could be wrong.
The third parameter in the 'create' method sets the cookie domain. It is optional and with 'auto', it sets the cookie domain to the highest domain level possible. Without it, the cookie domain will be set to the website domain without the www. prefix.
Here is what my issue was. I'm using google analytics with wordpress. I tried configuring google analytics for my website using plugin called Google Analytics Dashboard for WP (GADWP). This plugin generated a google analytics snippet that looks similarly to the one described in the question:
<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-475021xx-x', 'auto');
ga('send', 'pageview');
</script>
However, in Google Analytics console, the suggested snippet looked like this:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-110984887-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-475021xx-x');
</script>
It looks like this gtag.js is a new format for the google analytics snippet. So I disabled that wordpress plugin and I manually added the script suggested by Google Analytics to the page.
I have recently fixed the same issue. Please login to your admin dashboard and check the filters.
What I did was to make sure my valid host name filter was the correct one.
If you have copied the custom dashboard from another project or if you had an error in the filter then this would be worth your time to check out.
I have placed the value "domain.com" in the included host names filter.
Let me know if this fixed the issue for you.

Newest Google Analytics API reference?

I've got an unusual Google API code snippet:
(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-XXXXXX-1', '192.168.8.101');
ga('send', 'pageview');
This looks very similar to the older variant, however, I can't find any reference to these API. I'm looking specifically for the analogues of:
_setCustomVar
_trackPageView (is 'send', 'pageview' equivalent to it?)
_setDomainName (I want to test it on a computer on the intranet / connected to the HTTP server running locally).
Sorry, there was some confusion here. I've found the reference:
https://developers.google.com/analytics/devguides/collection/analyticsjs/domains
Here it is, for posterity, however, I can't find an analogue to _setCustomVar and _setDomainName.
UPDATE
I've found that (maybe) ga('set', { property : value }); will do the same as _setCustomVar and that ga('create', 'UA-XXXXX-1', { 'cookieDomain': 'none' }) would be similar to the _setDomainName. However, I still cannot get it to report anything when testing locally :(
You are correct, _setDomainName was replaced to be a property of create. This is useful because some people were calling _setDomainName after _trakPageview and it causes problems. So having it as a property avoid the confusion with ordering.
ga('create', 'UA-XXXXX-1', { 'cookieDomain': 'none' })
Also what were previously CustomVars are called custom metrics and dimensions. They are more powerfull in the sense that they are configured on the server side and you only send the values on the api call. Also now you can send metrics that will be aggregated.
The new API and these changes are part of a bigger update on the Google Analytics platform called Universal Analytics.
About Universal Analytics.
Note that in order to use the new tracking code your webproperty must be set to Universal Analytics. You can't change an old web property to be Universal Analytics (at least not yet). You are given the option to use Universal Analytics or not when you create a new Web Property.

Categories