Learn business growth with Google Analytics 4 Forums Google Analytics 4 Troubleshooting Challenge: Google Tag Manager's Failure to Recognize gtag.js eventModel DataLayer Variable

  • Troubleshooting Challenge: Google Tag Manager's Failure to Recognize gtag.js eventModel DataLayer Variable

    Posted by Olivia on 27 June 2022 at 9:12 am

    Hey, I’m in a bit of a pickle with Google Tag Manager (GTM) and gtag. I’m using gtag.js to send conversion data to Google Analytics 4 and I’ve got a gtag purchase event set up for purchase conversion. Now, as per Google Tag Assistant, the dataLayer setup is looking good. Here’s what it returns:

    `
    Data Layer Snippet
    `

    My next move was to add Microsoft Advertising UET via GTM and make use of the dataLayer data. All the UET tags seem to be doing their job, but the jig is that the purchase data variables aren’t getting noticed.

    I’ve created a User-Defined Variable in GTM for the purchase amount and slotted it into the GTM UET Custom purchase tag. Check it out:

    Name: dlv – eventModel.currency purchase

    Data Layer Variable Name: eventModel.currency

    Name: dlv – eventModel.value purchase

    Data Layer Variable Name: eventModel.value

    I’ve put those variables into the UET purchase tag as {{dlv – eventModel.currency purchase}} and {{dlv – eventModel.value purchase}}.

    Everything seems to be in order, but the problem is the variables data is showing up as “undefined” or “null”. So, when the UET tag fires, the gv and gc parameters are MIA. In GTM, if I manually enter a string instead of the dataLayer variable for the “value”, the parameter gets inserted into the UET tag as it should.

    I’m stumped. Why aren’t the eventModel.value and eventModel.currency variables being pulled from the dataLayer by GTM? Here’s a screenshot of my UET Purchase tag details; this one has the currency as hard-coded and not a variable:

    Screenshot of UET Purchase tag details

    John replied 12 months ago 3 Members · 2 Replies
  • 2 Replies
  • Huong

    Member
    5 May 2023 at 1:27 pm

    It seems like there might be an issue with the timing or the scope of variables in Google Tag Manager. Variables in GTM have different scopes and lifetimes depending on how they are used. For instance, if these variables are defined in a specific event and you are trying to retrieve them after the event has fired, they might not be available. Hence, the “undefined” or “null” values. This might explain why manually entering a string instead of the dataLayer variable for the “value” seems to work, as the string is available immediately.

    To debug this issue, you should verify if the variables are correctly populated by means the GTM preview mode. This allows you to see how your tags, triggers and variables load and behave in real time on your site. You should also verify whether the variables are still present in the dataLayer at the time the UET tag fires. If the variables have been lost, you might need to revisit how you’re managing your dataLayer. Moreover, ensure that the UET tag fires after the dataLayer has been populated with the required variables.

    Last but not least, always confirm your settings after making changes and conduct tests to ensure everything has been set up properly. The goal is to make sure your GTM setup fires and sends data as expected.

  • John

    Member
    22 June 2023 at 5:56 am

    Your issue may be with the timing of when your data is put into the dataLayer and when the tags are firing. The tags may be firing before the necessary data is available. The dataLayer works in a stack-like format where information is only available from the point it was added onwards. So, you may need to adjust when the purchasing data is pushed to the dataLayer.

Log in to reply.