I am using the Google Analytics snippet below
<!-- 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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', 'icantreveal.com');
</script>
<!-- End Google Analytics -->
I am sending my events on say a button click as follows
//google analytics click event hit record
if(typeof(ga) == "function")
ga('send', 'event','int_lp_btn','int_lp_findPeople_btn');
I am using Google Analytics debug Chrome addon for testing purpose. However when I test the same in my site I can see in console
Executing Google Analytics commands. Running command: ga("send", "event", "int_lp_btn", "int_lp_findPeople_btn") Sent beacon:some ga stuff
However the event report in dashborad does not have anything to show!. I have been unable to figure out what the problem is. Any help will be appreciated. thanks.
Replace your google tracking ID and set page view as ga('send', 'pageview');
Related
I am trying to integrate GA into a QT5 / QML project. For this I created a dummy GA web page project to test connectivity. First step is to test the setup with a simple web page (code below).
I had to specify a URL for the GA project. The page, however, is on my desktop, not online. I see no traffic in the real time GA view. Not sure why. Is it that my page is not on www.my-domain.com but literally on my desktop?
SETUP
On the GA settings page, this is my setup
Basic Settings
Tracking Id
UA-1234567890-1
Property Name
Default URL
http://www.my-domain.com
LOCAL TEST PAGE CODE
<html>
<head>
<!-- Global site tag (gtag.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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-1234567890-1', 'auto');
ga('send', 'TEST');
console.log(ga.q);
</script>
</head>
<body>
<button onclick="ga('send', 'BUTTON PUSH')">
PUSH ME
</button>
</body>
</html>
I have used GA before and do not remember the integration was this bumpy. Right now, I am also confused by the difference of GA view and Firebase view on the live report. However, I first need to establish proper tracking.
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');
I manage google analytics inside google tag manager and I don't have any separated script for google analytics in the head of my website.
I need to use ga() function like this:
<!-- 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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
</script>
<!-- End Google Analytics -->
See? It has created ga right after google analytics script. But as I said, I don't have any script for google analytics. I have just a script (which is located in the head of my website) from google tag manager:
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-{$google_tag_manager_token}');
ga('create', 'UA-{$google_analytics_token}', 'auto');
</script>
The problem is, it throws:
Uncaught ReferenceError: ga is not defined
Any idea where should I place ga('create', 'UA-{$google_analytics_token}', 'auto'); exactly?
It should be noted, when I run ga('create', 'UA-{$google_analytics_token}', 'auto'); in the console of the browser, it will be created as well. Do I need a settimeout() ?
By default, there is no analytics tag set up into the Google Tag Manager script.
You must configure into GTM a new tag for which you set up the type of the tag with "Google Analytics - Universal Analytics" and set up an event to launch this tag. "ga" function will then be available when GTM actually runs the tag.
One more information here, GTM send a hit with a prefix (generated tracker name). Sample:
ga('gtm1.send', 'pageview', '/page-name');
I recently implemented "Show number" option on my website, only in order to track how many users would be interested in Phone number of my clients. For Tracking this click/event i wanted to implement GA Event tracking so that i can read data in Google Analytics.
I implemented the GA snippet in my code but it does not seem to be working. i checked it on Live Event, and also i waited 48 hours to show in analytics which is sometimes suggested. Nothing happened. No tracked clicks for me. It doesnt work.
Where could i have made a mistake?
here is the code i use GA snippet in:
<div class="value" style="font-size: 14px;">
{$item.value|truncate:4:''}*** <span title="{$lang.show_more_desc}">{$lang.show_num}</span>
</div>
Thanks
To use ga() your GA implementation needs to be through analytics.js so it should look like this:
<!-- 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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
If it looks like:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-31591889-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-31591889-1');
</script>
Then you're on gtag.js and you need to do events this way.
Also would be helpful to post any console errors when you click on that link. I tested it myself with a working analytics.js implementation and the data is sending fine:
I want to implement Google analytics for an Angular SPA which is currently running in my localhost. I tried to copy the google tracking Js code to each of my view in the Angular SPA. But i don't think it actually worked.
Is this the correct way to implement Google Analytics or whats the correct way?
<div class="background">
<div class="container">
<h2 class="page-title">{{'contact-name' | translate}}</h2>
</div>
</div>
<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-XXXXXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
Don't insert the script in each of your views, instead paste it within your main HTML page.
In addition to Google Analytics you might want to consider using Autotrack and the urlChangeTracker in your SPA