Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eventCallback not supported #102

Open
iskrenvankov opened this issue Apr 19, 2022 · 4 comments
Open

eventCallback not supported #102

iskrenvankov opened this issue Apr 19, 2022 · 4 comments

Comments

@iskrenvankov
Copy link

Hi,

I am trying to execute some code only after the data layer event has been successfully pushed.
The usual way to do this with the plain js gtm library is to use the eventCallback and eventTimeout properties.
For instance, checkout this SO answer here: https://stackoverflow.com/a/38976722/1507558 which shows this snippet:

window.dataLayer.push({
  'event' : 'processLink',
  'eventCallback' : function() {
    window.location = targetUrl
  },
  'eventTimeout' : 2000
});

Using react-gtm now, I can't find a way to use the eventCallback property.
If I pass a function, it gets dropped and is not present in the dataLayer event object passed.

Could you advise on how to solve this situation using react-gtm?

@kodiekenta
Copy link

what npm version did you use to install the package

@iskrenvankov
Copy link
Author

what npm version did you use to install the package

npm version 7.11.2

@github0copilot
Copy link

1+

@github0copilot
Copy link

@iskrenvankov as i read the code base there is a workaround to that (but you should use ts-ignore flag if you are using type script)

if (window[dataLayerName]) return window[dataLayerName].push(dataLayer)

as we can see in this line you should add it to dataLayer object, like this:

TagManager.dataLayer({
      dataLayer: {
        event: "event",
        eventCallback : function() {
          window.location = targetUrl;
        },
        eventTimeout: 2000
      },
      dataLayerName: "name",
 });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants