Developer forum

Forum » Swift » Purchase event cant be used with GTM

Purchase event cant be used with GTM

Martin Ottesen
Martin Ottesen
Reply

Hi DW, 

Most of our customers are using Google Tag Manager for most of their tracking. Which means that both Universal analytics and Google Analytics 4 has been set up in GTM. That results in them not using the fields for either GTM or UA in website settings. 

First and foremost i'd love to see a field for my GTM tag, so we dont have to create our own.

Second is that the purchase event, maybe also other events only fires if the GA4 code is implemented, which then means we have had to create our own datalayer, see image below.


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Martin

Will gladly look into this with you.

A couple of notes though (not being a analytics pro by any means)

Your rendergtmscript renders a datalayer push - and as far as my knowledge goes, that is in the format that is being phased out in march and related to the enhanced ecommerce way of doing things. Our code is using the new recommended and built-in ga4 commerce tracking that is much easier to use than enhanced ecommerce in GA3. Using tagmanager, the events from GA4 should be proxied to UA formatted events automatically.

Also you should be able to just switch from using gtag.js to gtm.js by keeping the gtag function like this: function gtag(){dataLayer.push(arguments)};

That said - i would like some pro insights and be happy to make changes that makes GTM and GA4 alternatives that can both be used depending on preference.

BR Nicolai

 
Martin Ottesen
Martin Ottesen
Reply

Hi Nicolai, 

I am by no means not a pro either, this code could definitely be outdated. I have spoken to one of our SEO guys, and he says that the datalayer push, is the best way to get the data into GTM. Most of our customers are using GTM and through that using GA4 and UA, which means if we use the field provided in website settings we would be double tracking.

In an ideal world we would love to follow googles own recommendations from this link: https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm

Alot of our customers also use either cookiebot or cookieinformation, which means that DW cookiemanager is disabled. That would result in us also not getting the tag fired to GTM, so if the tag could be open in some way that it doesn't get blocked by DW cookie, and we would just be able to control the trigger in GTM by using our own cookie manager that would be great.

Lastly we would probably need to set up an "orderreceiptloop" around the tag so that its not able to fire multiple times if the page is being refreshed.

There are a lot of events that would be great to be able to track in a standard version of swift, such as add to cart, checkout steps and other things that would be great to be able to pick up in either GA4 or GTM.

I don't know if its possible to set up an if statement that fires one kind of event if the GTM field has been filled and another if the GA4 field has been filled. Because by the looks of it the GTM and the GA4 events are slightly different.

If you would like to set up a short meeting i'd love to bring in some stronger SEO resources. 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Martin

The google reference you link is exactly what we implement. Yes, we use the gtag function which is the exact same as using datalayer.push. Exacrtly the same. So the only difference is wether you ant to use gtm.js or gtag.js - both of which uses datalayer.push. So you do not have to insert your own events as you have showed - you only need to replace the gtag.js with gtm.js and ensure the gtag function is present as stated in my previous post.

This is a list of GA4 events that Swift currently support, including add-to-cart: https://doc.dynamicweb.com/swift/setup-project/guides/google-analytics-4#sideNavTitle1-2

Double events in GA4 is not an issue when using transactionid (which Swift uses) - see this piece: https://support.google.com/analytics/answer/12313109?hl=en

In relation to cookiemanagers, I think the best option is to actually call Dynamicweb Cookimanager when consent is given in those add-ons instead of disabling DW cookimanager. If you disable the cookiemanager it is not possible to stay legal since DW will send server side cookies no matter if consent is given.

You can use cookie banner events - i.e. from Cookieinformation - insde this method call the correct DW cookie accept URL:

<script>
    window.addEventListener('CookieInformationConsentGiven', function(event) {
        if (CookieInformation.getConsentGivenFor('cookie_cat_category')) {

            // Place cookie-setting script here. 
            // Or some other javascript function you want to fire on consent.

        }
    }, false); 
</script>
 
Martin Ottesen
Martin Ottesen
Reply

Hi Nicolai,

That sounds great, although we'd still have to in this case go through all the events and change them to gtm.js? That would mean that in all the templates where the events are present we end up with custom templates. Would there be a way for it to look at which settings field has been filled, either GTM or GA4, and that way use either gtm or gtag? that would mean we can keep all our templates standard.

Of course, that would also imply that we have a standard field to enter our GTM code into.

In terms of the cookie manager, I understand what you are saying, but would that mean we have to use the DW Cookie manager, as the popup? Or would we be able to use cookie information or cookiebot for that?

 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

No - you do not have to change any events - ever..... You can use the standard templates as is already. Without changing the events.

The GTM and GA4/GTAG events are exactly the same - gtag() is a short hand to call datalayer.push. So gtag() = dataLayer.push.

 

 
Martin Ottesen
Martin Ottesen
Reply

Alright, i mean that sounds great.

So I guess all there is to do is to actually be able to insert GTM in the settings, and not have the events look for a GA4 code or a GTM code?

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Yes - and we have added that to the backlog.

 
Martin Ottesen
Martin Ottesen
Reply

Amazing, looking forward to it :) 

Thank you for your time and explanation!

 

You must be logged in to post in the forum