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.
Related
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
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');
I am new to web development and I would like to verify site ownership using javascript, similar to what Google does with their analytics code. I have a django app that lets users sign up for a service, but I need to validate that they own the site. Here's a very high level description of what needs to happen:
The user signs up and is given a verification code
I generate a snippet of code to put on their site
They return to my site and click 'Verify'
Here's googles code. Can someone break down for me what this is doing and how it's used to verify site ownership?
<script type='text/javascript' id="verification code">
(function(){
// create a new script element
var script = document.createElement('script'),
script.src = '//www.google-analytics.com/analytics.js';
script.async = true;
// insert the script element into the document
var firstScript = document.getElementsByTagName('script')[0];
firstScript.parentNode.insertBefore(script, firstScript)
})();
</script>
Let's ignore the js for the moment. Your core question is how to verify site ownership. So I'm going to tackle that first.
What Google is doing is having you insert some code into a webpage that you have control of. The assumption is that if you have control of www.example.com, you can get that bit of code served at www.example.com to someone. And that's a pretty safe bet.
Now back to that code snippet you gave. For one thing, it didn't look familiar to me whatsoever. It must be an older format, because what's current is below:
<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-123456-7', 'auto');
ga('send', 'pageview');
</script>
In any any case, there's a great read here on why Google has changed their approach over time for how it loads this script: http://www.stevesouders.com/blog/2010/05/11/appendchild-vs-insertbefore/
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.
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.