I have the following GTM already configured on my website:
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'Pageview',
'pagePath': 'https://www.googleanalytics.dev/pancakes',
'pageTitle': 'Pancake Event Signup',
'visitorType': 'customer'
});
</script>
<!-- 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-XXXXXX');</script>
<!-- End Google Tag Manager -->
As you can see, that block of code configures the window variable: dataLayer
.
Through that code I fire events to GTM where I have Triggers and Tags. All of them working properly.
Now I got a request from one of my clients about configuring a GTM block of code (I think related to AdWords). That block of code corresponds to my client's GTM account (I have no access to it).
That block of code also configures the window variable: dataLayer
as you can see below:
<!-- Global site tag (gtag.js) - Google Ads: YYYYYYYYYYY -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-YYYYYYYYYYY"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'AW-YYYYYYYYYYY');
</script>
<!-- Event snippet for Submit lead form_NDPL conversion page -->
<script>
gtag('event', 'conversion', { 'send_to': 'AW-YYYYYYYYYYY/QmRnCPYt7M4DEOLk2eKs' });
</script>
I have the following 2 questions:
Can I have the variable: dataLayer
configured on same page for 2 different GTM accounts (mine and his)? I'm worry about exposing data from my existing dataLayer
to my client's dataLayer
.
Instead of hardcoding my client's code on my page, could I maybe paste it into a new GTM Tag on my account and fire that tag which will take care of running his code above (i.e.: installing his GTM code and firing his event)? I don't like the idea of hardcoding others code on my website if not necessary.
Thanks!
Let's take an event ticket selling website for example. Event organizers want to register their events on the site, but they also want to be able to measure user activity on their event's pages on the ticket selling website, as well as, maybe, linking their GA user ids to be able to join their users' journeys when the users navigate from the ticket selling website to the event organizer's website.
Doing all the tracking implementation for the event organizer is tedious, so it's easier to just deploy their container in the few pages that "belong" to them and be done with it. On the other hand, I've seen people just using GTM API and generating a GTM account on the fly when the event organizer is onboarding their event and indicating there that they want GTM presence.