I was asked to implement the Google Tag Manager scripts into the React application. I've added the scripts to head and body of my html file. I've tested the site in the Preview mode of GTM and everything seems to working fine. Clicks and route changes are tracked correctly.
I have one doubt... What about the localhost development ? Is it going to generate unnecessary logs on the analytics (which I have no access to)? Or maybe it's just enough to paste the snippets and that's it?
I can't find an answer so that's why I decided to ask here.
If someone has some experience on that topic - please let me know :)
I would advise you to map separate Google Analytics property IDs by either a datalayer variable, URL or custom JavaScript to return a separate property ID based on whether users are accessing your website from either your localhost development environment, your UAT environment (if any) and then your production environment (or others as applicable).
Essentially you're looking at having something that says "if the URL contains "localhost", return my development property ID", then use this variable name in your Google Analytics tag(s) instead of a static value.
Yes, unfortunately all your existing testing is all in your profile because if you had the production property ID configured and fired off a bunch of events and pageviews, it absolutely collected and sent there as part of the debugging experience. Generally though, that's a low concern on a production app because you make up such a small portion of overall traffic; you're just a couple of blips in the larger dataset.
Related
I am trying to use Google Tag Manager to collect event data (including page view) but it isn't feeding through to Google Analytics once its deployed to Vercel.
I have checked the following things:
GTM has a GA4 Configuration Tag with the measurement ID from GA
I have set up the GTM measurement ID as a public variable in env.local (and reflected this in Vercel)
T have added the script to _app.js
I have added the iframe to _document.js
Set up the tags required in GTM and published it
Using dev tools I have checked that the gtm script (with the correct reference) is fired in the Network tab
Also checked dataLayer in the Console tab is collecting the data expected
However, in spite of all of this I can't see any data in Google Analytics. Played around a bit yesterday expecting to see some today but nothing.
It seems to work on localhost and checking both in real time Vercel doesn't register a view but localhost does.
Previewing the Vercel URL from GTM does say its connected and I can view that in real time in GA when going this way, but if I go to the address directly it's not logging it. Checking 'Tag Coverage' on GTM also says the pages aren't connected.
Am I missing something? It seems to work in theory, just not in practice when visiting the Vercel address directly (as opposed to via GTM preview)?
Thank you in advance
I think I found an answer myself and it's rather basic. It seems a pop up blocker I had installed ('Pop up blocker for Chrome™ - Poper Blocker') was preventing it from firing. Disabling the extension seems to have done the job.
I'm trying to get GA4 e-commerce working for a client. For some reason though I cannot get the testing environment to send data over to any GA4 property. The preview and DebugView work just fine with the production website but the second I change the address in preview to the staging website nothing gets picked up anymore in GA.
The container shows in preview that it's installed correctly, you can see the events trigger like normal in GTM and when you open the tag it shows the correct measurement ID.
I created a new testing property to try and see if that made a difference, it didn't. It still only shows the events from the production site, not staging.
Tag assistant shows that the container is properly loaded on staging.
Anyone has any clue what i should be looking at? Any help would be greatly appreciated.
thanks
Double check that you're not inadvertently running AdBlock or have Firefox configured to block marketing tags. Either would result in the GTM Preview indicating conditions met and tag fired, but the browser could be prevented from actually sending the data.
Alternatively, check that your GA account/property doesn't have a filter engaged that's preempting the data from being processed in GA.
I have a React app and want to install Google Tag Manager on certain pages, but I do not want it present after a user logs in. Is it possible to disable / remove the GTM scripts after a certain user action?
I am using react-gtm-module to install Google Tag Manager but open to other options.
Well, this, basically, answers it: How to unload a javascript from an html?
But a better answer would probably be: don't unload GTM. It's not a good practice. It adds a lot more complexity to your overall logic. People don't expect someone to arbitrarily override deployed scripts' namespaces. It's very likely to cause havoc at some point and it's unlikely the one to debug it would be thankful to you for a thoughtful implementation.
Instead, consider using blocking triggers within GTM to just prevent certain tags from firing.
How can I copy setup of GA and GTM from one account to another without copying data?
According to the documentation it is not possible:
All reporting data associated with a property is moved (not copied) to the destination account.
But maybe someone knows some kind of a trick?
Thank you.
The documentation you linked is about property moving, which is basically Google's term for moving GA data from one account to another. So in that case moving the data is the whole point. It is true however that you cannot easily copy a GA configuration - the closest would be to set up properties and views programmatically via the management API, but that is a lot of work (too much if you only want to do this once) and still does not cover all the settings.
You can easily move a GTM installation from one GTM account to another. Just export the container in the admin section and import it in the admin section of the new account. This will not copy any data.
I run a standard google analytics tracking code (ga.js asynch version) on a website.
I am wondering if there is a line of js I can add to the tracking code so that I can segregate dev/prod data? e.g. when I pull in the codebase to do dev work, I can set the tag to DEV. When releasing back to production, DEV tag gets replaced with PROD tag.
Is this even possible and if so, how do i implement it?
One method I thought of is just to create a new "property" (which would generate a new ua number, which I could add during dev. that would allow me to track it all separately.)
Wondering if there are any other methods I should consider.
Alternative to mike's answer is to setup a filter in your profile based on the url or domain or based off any number of other things.
I'm not worried about collecting data from my development server, but I do want to make sure I'm not polluting my production data -- I've been using some variation of the following:
if (!/devServer|localhost/.test(window.location.hostname))
{
_gaq.push(['_setAccount', 'UA-11111111-1']);
}
On the devserver domain (or on localhost), _setAccount doesn't get executed, so the tracker defaults to the default tracker, UA-99999999-1. This allows you to still see tracking data being sent to the analytics servers (via ga_debug.js, chrome dev tools, firebug, fiddler, etc), but doesn't register against your production profiles.
Downsides -- it is an extra bit of code that get's run on the client.
If you do want analytics from your development servers, you could try something like:
gaq.push(
[ '_setAccount',
/devServer|localhost/.test(window.location.hostname) ? 'UA-11111111-1',
'UA-22222222-1']
);