Typeform/embed

shareGaInstance not working with NextJs

elbro opened this issue · 6 comments

elbro commented

Loading GA tag the proper way in NextJs and setting shareGaInstance prop gives this error: Whoops! You enabled the shareGaInstance feature in yourtypeform embed but the tracker with ID G-CLB8J230JC was not found. Make sure to include Google Analytics Javascript code before the Typeform Embed Javascriptcode in your page and use correct tracker ID

Google Analytics is loaded using Next's <Script> tag in _app.js, and the bundle including the npm package is loaded early on in the . I've tried to load the GA script earlier (which negatively affects the whole site) but still always get the same error.

I've also tried to Lazy load this library or via CDN script (so it loads after GA) but with no luck so far.

Has anyone managed to get this working with Next? it's a shame this is so fragile

Hello, can you please share the code of how you are loading the GA tag in your NextJS app? I will look into this.

I am currently testing with NextJS using this guide to add GA to the app.

I am passing the ID explicitly to my embed:

<Widget
  id="UukWsKxw" 
  shareGaInstance="UA-187649-16"
/>

I was not able to replicate the issue once I disabled my adblock extension.

You can find the app here: https://codesandbox.io/p/sandbox/busy-sun-m64jfo

elbro commented

Hello!

Loading Gtag the same as you as they recommend, in _app:

<Script src='https://www.googletagmanager.com/gtag/js?id=G-CLB8J230JC'
        strategy="afterInteractive"
 />
<Script id='ga' strategy="afterInteractive">
  {`
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-CLB8J230JC');
  `}
</Script>

but I am using PopUp button as it's shown on a button press, could this be the issue?

import { PopupButton } from "@typeform/embed-react";

export default function Quiz({ onComplete, playButtonClick }) {
  const ref = useRef();
  const openPopup = () => {
    ref.current?.open();
  };

  return (
    <>
      <PopupButton
        shareGaInstance
      ></PopupButton>
      <Button onClick={openPopup}>TAKE THE TEST</Button>
    </>
  );
}

elbro commented

ok the error has gone now, I think it was my ublock origin addon i didn't realise was running in my dev browser🤣 thanks!

maybe worth extending the error message to say it could be this :)

Thats a good idea. I will keep this issue open until we update the error message 😄

🎉 This issue has been resolved in version @typeform/embed-v2.13.1 🎉

The release is available on:

Your semantic-release bot 📦🚀