alinemorelli / react-gtm

React Google Tag Manager
MIT License
658 stars 140 forks source link

How to use defer instead of async #88

Open hurifajri opened 3 years ago

hurifajri commented 3 years ago

Does this module automatically set the script to use async attribute? How can I change to defer?

tomekrozalski commented 3 years ago

We can use setTimeout, but I am not sure is it good idea 🤔

setTimeout(() => {
  TagManager.initialize({ gtmId: process.env.NEXT_PUBLIC_GTM_ID });
}, 4000);
mahmoudadly-cobalt commented 2 years ago

You can instead install react-gtm-module-defer and then in your code import TagManager from 'react-gtm-module-defer'. That will change async to defer.