-1

I have a problem with GA4 and GTM, which i cant solve already for 3 days :(

I created a GA4 tag and event, called it "login". It has a parameter "method" which default value is "00000000000000000000". i need to call this event and set "method" value to my custom (for example, "ZZZZZZZZZZZZZZZZZZZZ" - it will always be random). Here is javascript code, which calls my event:

window.dataLayer = window.dataLayer || [];

var x = null;

x=window.dataLayer.push('js',new Date());console.log('js '+x);
x=window.dataLayer.push('config','G-*******');console.log('config '+x);

x=window.dataLayer.push('set','login',{'method':'ZZZZZZZZZZZZZZZZZZZZ'});console.log('set '+x); 
x=window.dataLayer.push({'event':'login','method':'ZZZZZZZZZZZZZZZZZZZZ'});console.log('event '+x); 

here is the result:

js false

config true

set true

event false

only the default value of "00000000000000000000" is sent to the server instead of "ZZZZZZZZZZZZZZZZZZZZ". always! when calling an event, a request always send default value of "method" parameter. i don't understand why

GET /g/collect?v=2&tid=G-*******'&gtm=45je48r0v9193929697z89192937461za200&_p=1724944900794&gcd=13l3l3l3l1l1&npa=0&dma=0&tag_exp=0&cid=476783039.1711069035&ul=ru-ru&sr=2560x1440&uaa=x86&uab=64&uafvl=Not)A%253BBrand%3B99.0.0.0%7CGoogle% 2520Chrome%3B127.0.6533.120%7CChromium%3B127.0.6533.120&uamb=0&uam=&uap=Windows&uapv=15.0.0&uaw=0&are=1&pae=1&frm=0&pscdl=label_only_1&_s=3&sid=17249 42914&sct=18&seg=1&dl=https%3A%2F%2Fmyweb.com%2F&dt=Search&en=login&_c=1&ep.method=00000000000000000000&_et=2&tfd=3996

here is dataLayer content from DebugView:

{
  0: "l",
  1: "o",
  2: "g",
  3: "i",
  4: "n",
  5: "T",
  6: "S",
  7: "Y",
  8: "V",
  9: "T",
  10: "L",
  11: "H",
  originalLocation: "https://myweb.com/index.html?" +
                    "gtm_debug=1724949731136",
  event: "login",
  gtm: {
    uniqueEventId: 47,
    start: 1724949732880,
    allowlist: undefined,
    blocklist: undefined,
    whitelist: undefined,
    blacklist: undefined,
    scrollThreshold: 90,
    scrollUnits: "percent",
    scrollDirection: "vertical",
    triggers: "17",
    priorityId: 8
  },
  tagTypeBlacklist: undefined, 
  propertyName: "x",
  method: "ZZZZZZZZZZZZZZZZZZZZ" 
}

help, whats the problem? i'am newbie to GTM/GA4.

1
  • thnx, i have made some fixes Commented Aug 29, 2024 at 18:17

1 Answer 1

2

To get my custom integration working, I had to take several steps in Tag Manager (GTM), Analytics (GA4), and code (the Data Layer call). There were lots of “names,” which I broke into two distinct types: technical JS-friendly variable/property names that you need to keep in sync, and human-friendly titles used in GTM’s user interface that GTM keeps in sync. Those titles are the “names” (Google’s confusing term) that appear at the top of the GTM panes.

  • decide an Event Name (#1, technical)
  • define custom GTM Variables of the Data Layer type, each with a title (#2) and a Data Layer Variable Name (#3, technical)
  • define a Trigger of the Custom Event type with #1 as the Event Name to tell GTM that events with #1 needed to be recorded
  • set up a custom Tag in GTM
    • specify #1 as the Event Name
    • specify Event Parameters (#4, technical), some of which were custom, and some of which were canonical (“known,” in Google’s terminology) GTM/GA4 Event Parameters
    • assign each Parameter my GTM Variable (using #2 in double curly braces) as its value
    • assign my Trigger to it
  • write the Data Layer call with #1 as the event, and collecting values for all the #3’s
  • define Custom Dimensions (event-scoped) in GA4 each with a Dimension Name (#5, human-friendly title) and using #4 for the Event Parameter (confusingly called User Property/Parameter in the definition list table)

Only then could I generate reports with data in GA4.

Example

#1 (what GTM looks for): async_login

#2 (what I see in lists in GTM): Login Method, Page Theme

#3 (what I send GTM): method, theme

#4 (what I see in lists in GA4): Method of Login, Aesthetic

window.dataLayer.push({ 
    event: 'async_login', 
    method: 'passkey',
    theme: 'Avante-garde',
});

Differences from your scenario

  • I configured GTM and GA4 from within GTM, without writing custom code on the page (your first and second dataLayer calls).
  • I didn’t set the value before triggering the event (your third dataLayer call).
Sign up to request clarification or add additional context in comments.

2 Comments

thank u very much! great post, but i've just solved the problem by using datalayer variables several minutes ago, just like u wrote in your post :) anyway, great answer! thnx thnx thnx
Awesome! Can you "accept" it so other people know it worked?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.