The gatsby-plugin-google-tagmanager plugin adds GTM code to all pages of a Gatsby site. Is there any way to exclude a page from having the GTM snippet applied to it?
Adding a blank page on a website so a service like Uptime Robot can check if our site is live (as opposed to pinging the homepage).
Instead of a custom .txt or .html file added to the public folder that could get wiped out during a gatsby build, I created a blank Gatsby page in _/src/pages/_ to be generated. It is literally just this...
import React from 'react'
const CheckIfIAmLive = () => <div>Live</div>
export default CheckIfIAmLive
Yes, the page could be excluded from Google Analytics, but it would be great if there was a feature or a way to exclude this page from featuring the GTM code in the source and unnecessarily adding all the tags to the page.
I can think of multiple applications for excluding GTM from pages other than website uptime monitoring: admin areas, custom promo pages, easter eggs.
@SimonIMG Currently gatsby-plugin-google-tagmanager does not provide an option of excluding a page from having the GTM snippet applied to it.
But like you said it would be really useful.
The required changes needs to be done in this file. onRenderBody function gets a parameter called pathname, we can provide an option in gatsby-plugin-google-tagmanager to accept a list of excluded paths which we can compare with the pathname and exclude a page from having the GTM snippet.
Would you like to work on this and raise a PR?
I can give it a try on the weekend if you could wait.
My JS skills are pretty noob level at the moment (trawling through Scott Tolinksi/Web Bos tutorials to up my JS and React skills :) ).
But I rate myself pretty good at testing, UX and documentation. More than happy to wait and happy to pitch in to updating docs.
@SimonIMG You should be able to that in GTM console. GTM works differently than GA and excluding GTM script can cause weird behaviours. See discussion in #9413
@SimonIMG I hope that answers your question. Feel free to open a new one if you need more help 馃憤
Most helpful comment
I can give it a try on the weekend if you could wait.