react-google-tag-manager icon indicating copy to clipboard operation
react-google-tag-manager copied to clipboard

wrong how to use??

Open toriumi0118 opened this issue 8 years ago • 2 comments

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?

toriumi0118 avatar Dec 01 '17 07:12 toriumi0118

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-...' />

yepstepz avatar May 10 '18 08:05 yepstepz

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);

AdrienLemaire avatar Jun 25 '18 09:06 AdrienLemaire