how to check google analytics code fired through python - javascript

I have a website on which Google Analytics code fires (through Google Tag Manager). The site has a lot of pages and I want to check if Google Analytics code fires on all pages. One way would be to open the URL, open GA debugger and check the pageview firing in the console.
Since there are a lot of URLs which need to be checked, is there a way to automate this process (preferably by Python)
Edit:
What I've tried so far:
I've managed to get the fetch the source code of the pages and then regexing my way to find specific code snippets (of GA and GTM) You can find the code here. But the problem is this will fetch just the static code. Any pixels/codes firing after the page actually loads will not be captured.
The issue with using Selenium is that I will be performing this test for possibly thousands of URLs. Selenium will slow the process down considerably.

Related

Why gtag.js is loading 2 scripts instead of 1?

When I install my gtag.js code in <head> I'm surprised that I have two scripts loaded. I don't understand why. One is from analytics and the other from googletagmanager:
I cant find any info about that. Anybody knows why this happens?
Gtag.js is Google's "global" tag, a sort of scaled down tag manager that only serves Google scripts (and uses the same infrastructure as the tag manager proper, hence googletamanager.com as origin domain).
So gtag is the delivery and configuration mechanism, but to do any actual work, the assets for Google Analytics (Google Ads etc, whatever Google script you chose to implement via gtag.js) still have to be loaded.
The tag manager is a general utility used to load different resources for Google stuff. There are dozens of different resources, including adwords, surveys, A/B testing stuff, analytics, etc (see your tag manager dashboard). In your case, you are only using analytics, so the tag manager only loads the analytics code.
Furthermore, each asset is only loaded when a certain "trigger" happens. In most cases, the trigger for analytics is "Page Load", which is why you are seeing the two requests happen pretty much right next to each other. You could update the trigger to be something like a form submission, youtube video watch, etc... and you would only see the resource loaded when that trigger happens.

Same Web Property ID is Tracked Twice - Google Analytics

All,
I have recently run into an issue where my bounce rate on my website www.x3tradesmen.com dropped significantly (less than 10% and sometime even 0%). I have read multiple threads trying to solve the issue and have downloaded a chrome extension "Google Tag Assistant". The extension is telling me "Same web property ID is tracked twice."
I cannot find how or where the web id is being tracked twice because I only have the GA script installed one time within the Avada theme options. I do have Google tag manager connected as well, however, it has been connected for a while and I never noticed a drop after installing it.
The most recent changes that I have made to our website is:
Installing SSL certificate and "Really Simple SSL" plugin so my website is now https://www.x3tradesmen.com instead of http://www.x3tradesmen.com
I have an old website x3staffing.com that I recently 301 redirected to go to https://www.x3tradesmen.com via the .htaccess file (GA script was removed from this website just in case)
Installed W3 Total Cache plugin for basic cacheing features
Can anyone assist me with solving this issue and how I can make sure that web property id is only being fired once??
Thanks in advance!
See Image
After receiving detailed information from Codeseer, I was able to identify that I was tracking all of my pageviews with a Google Tag Manager tag. I also had the Google Analytics script installed on my website, therefore, the web property ID was firing twice. I never made any changes to my original GTM tag so I am not sure why it all of the sudden started tracking twice but ultimately the solution was to remove the Google Analytics script and only use Google Tag Manager to fire the GA script. Thanks for all the help!
Bounce rate issue is occurring because the page view is being fired twice.
Bounce is calculated based on when a user has a pageview and then no other interactive actions. So Google Analytics is thinking user navigated to homepage and then navigated to homepage again. Thus user did not bounce.
(Your Exit Rate should be a more accurate representation of bounce rate if you are looking for a temporary solution to get that data.)
Looking at the network requests it appears that a pageview is being fired by the original Google Analytics script as well as by Tag Manager.
Perhaps something changed recently in your Tag Manager to add a GA tag?

How can I get page timings for a SPA in Google Analytics using GTM?

I've been wresteling with this a few days and can't really find any good information on it. I am a novice with respect to Google Analytics and Google Tag Manager.
I have a client website which is a Single Page Application using Marionette. The client would like timings on how long it takes to load different pages in the application, specifically they want to know what pages to focus on for optimizations. They also want more analysis on user interaction in GA.
I've installed the google tag manager and setup the page view tag to show the individual page paths via the History trigger properly as described here:
https://www.pmg.com/blog/tracking-single-page-web-apps-google-tag-manager-analytics/
That is working fine, I can see the history fragments/page paths in GA.
The problem is when I go to Page Timings in the Behavior reports in GA all the timings are 0. Avg page load, server load, etc.
I've tried installing a page timing recipe from Luna Metrics:
https://www.lunametrics.com/labs/recipes/page-load-timing/
This did not work as the custom javascript in it depended on window.performance which after some research does not appear to work well for SPAs.
function() {
var timing = window.performance.timing;
var ms = timing.loadEventStart - timing.navigationStart;
return Math.round(ms / 100) / 10;
}
I've also tried setting the siteSpeedSampleRate to 100 in the PageView tag for google analytics. This appears to have had no affect either.
i've also been messing with the tags and using the GTM preview and GA Debug and I can see the custom timings being set but with the same value on every subsequent link click (Its using the same page load value on the initial page load I think) which is why I don't think window.performance is an option here.
I've not been able to find any definitive way to get google analytics to track page timings for an SPA and would love any suggestions!
I guess I just needed to be a little patient after the siteSpeedSampleRate change. That seems to have resolved the timing issues for me.

Artificial pageview pushed to Analytics is changing PPC traffic source

So basically, we are having issues with a website (https://thesoundshop.com) in which the PPC traffic source (it only seems to be PPC traffic that is affected) is being changed by the pageview that we are pushing through to analtics.
The website runs on Ajax so we have to use Javascript to emulate pageviews through to Analytics whenever a link is clicked on the website. We are not using Google Tag Manager to implement the analytics or javascript because of this so we are using the gtag method exactly as Google's documentation recommends:
gtag('config', 'GA_TRACKING_ID');
I have tested this by visiting the website through a PPC ad and watching the real-time reports in Analytics. The first page load attributes the correct source to the traffic (cpc) as expected but then when I click on a link to go to a different page, the traffic source changes to Google Organic search. I then complete an action that I know will trigger an event or a goal and then when this appears in the Goal Reports, it attributes the goal as organic, too.
We know that this has to be down to the Javascript pageview that is being pushed to analytics to simulate that a new page has loaded but we can't work out why it would be changing the traffic source. The gtags are implemented exactly as Google recommends; just wondering if anyone else has had this problem and if so, how did they go about fixing it?
We had the same issue and after some more research found the problem along with the solution, thanks to Simo.
Basically, you need to manually set the document.referrer of the first session to make sure it persists and does not get over-written half way through the session. It's a known issue with GTM and single page applications.

Triggering site in new tab or window in Google Sheet

I use autocrat to mail merge legal documents with a database in Google Sheet. Autocrat does instantaneously trigger when a Google Form is submitted, which is great, but I also require the task to perform automatically. Through some searching, I learnt that a modified Google Form link can submit Google Forms with pre=filled answer.
This is where I am stuck.
I have set up (or I think I have) the script in Google Sheet to onChange (Insert_row, edit). I'd like that to trigger a new window or tab to open, going to the modified Google Form link, thereby triggering the form, which then triggers autocrat, then I can have my documents mail merged automatically.
This is the code I am using, which isn't working.
function openWindow(url) {
window.open('url', '_blank');
window.focus();
}
Is this a coding error, or is this a limitation within Google Script? Most of the codes I found involves using a button and then clicking it, I also read that there are browser limitations for auto pop-ups.
Short answer
While Google Sheets and Google Forms use HTML, JavaScript and related things to work, there are some restrictions. See the guides to learn about what could be done.
Explanation
JavaScript window object doesn't work on your script because the code on .gs files runs on Google servers (server-side) not on the user browser (client-side).
See Dialogs and Sidebars on Google Apps Script to learn the basics about how to show a dialog.

Categories