gtm-support / vue-gtm

Simple implementation of Google Tag Manager for Vue
https://www.npmjs.com/package/@gtm-support/vue-gtm
MIT License
198 stars 23 forks source link

Bug: last custom property is persisted #323

Open fogx opened 1 year ago

fogx commented 1 year ago

Info

When sending an event with custom parameters, the last parameters will be persisted to further calls if they are not overwritten. I'm not sure if this is intentional, but it's very annoying, since this makes other events send totally irrelevant data. The dataLayer push is correct, but the actual values transmitted to GA4 are not.

Tool Version
Plugin v2
Vue v3.2.45

Input

  gtm.trackEvent({
    event: "test",
    event_parameter: "format",
    event_parameter_value: "test_value",
    user_property: "test_property",
    user_property_value: "test_prop_value"
  });
gtm.trackEvent({event: "test_followup"});

Output or Error

DataLayer - everything is correct here

dataLayer.push({
  event: "test",
  target: null,
  action: null,
  target-properties: null,
  value: null,
  interaction-type: false,
  event_parameter: "format",
  event_parameter_value: "test_value",
  user_property: "test_property",
  user_property_value: "test_prop_value",
  gtm.uniqueEventId: 1
})
dataLayer.push({
  event: "test2",
  target: null,
  action: null,
  target-properties: null,
  value: null,
  interaction-type: false,
  gtm.uniqueEventId: 2
})

gtag output - you can see the second test event also has the format property, eventhough it was not defined.

gtag("event", "test", {
  format: "test_value", // this is correct and as specified
  user_properties: {test_property: "test_prop_value"},
  send_to: "G-XXXX"
})

gtag("event", "test_2", {
  format: "test_value", // this should not be here!
  user_properties: {test_property: "test_prop_value"},
  send_to: "G-XXXXX"
})

Expected Output

gtag("event", "test", {
  format: "test_value",
  user_properties: {test_property: "test_prop_value"},
  send_to: "G-XXXX"
})

gtag("event", "test_2", {
  user_properties: {test_property: "test_prop_value"},
  send_to: "G-XXXXX"
})

Additional Context

If i send three events after each other, only the last custom parameter is persisted -> makes it seem even more like a bug 🤔 Since GA4 does not use action, category etc. anymore, the user has to specify their own parameter name and values.

Shinigami92 commented 1 year ago

Please add a test here: https://github.com/gtm-support/core/blob/main/tests/gtm-support.test.ts and try to reproduce it

But I see you are using GA / gtag, this is not related to this repo :thinking:

fogx commented 1 year ago

Please add a test here: https://github.com/gtm-support/core/blob/main/tests/gtm-support.test.ts and try to reproduce it

Ok ill do that

But I see you are using GA / gtag, this is not related to this repo 🤔

i don't understand. I'm using this repo (see input) to send the data to the datalayer. It uses gtag under the hood. The outputs that i pasted are from the GTM preview, not code snippets.