holidaycheck / react-google-tag-manager

This repository contains a react based implementation for Google's Tag Manager snippet.
MIT License
192 stars 31 forks source link

wrong how to use?? #70

Open toriumi0118 opened 6 years ago

toriumi0118 commented 6 years ago

Hi.

Google Tag Manger Quick Start Guide said script tag should be in a head tag and noscript tag should be placed just after body tag.

but https://github.com/holidaycheck/react-google-tag-manager#how-to-use looks different with Quick Start Guide said.

Does it need to fix it?

yepstepz commented 6 years ago

you can change Quick Start component like this:

if (isBody) {
  return gtm.noScriptAsReact();
}

if (isHead) {
  return gtm.scriptAsReact();
}

and send isHead and isBody props to GTM like this:

in head component: <GoogleTagManager isHead={true} gtmId='GTM-...' />

in body component: <GoogleTagManager isBody={true} gtmId='GTM-...' />

AdrienLemaire commented 6 years ago

except that in some cases, the backend server isn't node and doesn't run react. Client react is already within the body.

@yepstepz can I assume that you not modifying the readme example implies that Google Tag Manager works just as fine when called from the body and not from the head ?

EDIT: oh, actually, it's being set in the head with document.head.appendChild(script);