react-gtm icon indicating copy to clipboard operation
react-gtm copied to clipboard

How to setup properly react-gtm-module

Open vinibispo opened this issue 5 years ago • 3 comments

Hi, nice work on react-gtm-module, I'm trying to setup this library on my ecommerce, but I couldn't push my datalayer to tag manager, is there a guide or something else?

Environments:

  • Node: 12.19.0

  • React: 17.0.2

  • React GTM Module: 2.0.11

vinibispo avatar Apr 22 '21 19:04 vinibispo

I also have the same question, is there any guides or examples of real world scenario.

ghost avatar Aug 18 '21 07:08 ghost

Are you trying to push the dataLayer in the initialization itself?

I've been successful pushing the dataLayer by initializing on load, and then calling the dataLayer function as a separate event.

On load:

import TagManager from 'react-gtm-module';

const tagManagerArgs = {
    gtmId: 'GTM-xxxxxxx', // required
};

TagManager.initialize(tagManagerArgs);

Trigger the dataLayer while performing a specific action (we assume TagManager has already been initialized):

import TagManager from 'react-gtm-module';

const tagManagerArgs = {
  dataLayer: {
      event: 'eventName', // event to be picked up by GTM
      customValue1: '', // anything you want here
  }
}

TagManager.dataLayer(tagManagerArgs);

JMarchetto avatar Aug 19 '21 22:08 JMarchetto

@JMarchetto but do you know how to add environments to it?

Hamdan85 avatar May 04 '22 19:05 Hamdan85