Next.js Discord

Discord Forum

Script tag for analytics

Unanswered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
guys for analytics and the script tags im using the Script tag from nextjs i notice events are fired but the apps dont detect that the tracking is setup, has it have to do with the stragey like afterInteractive or ?
appreaciate help tahnks.

21 Replies

Can you share your script?
Carpenter wasp
but the apps dont detect that the tracking is setup

You'll have to be more specific - how the script is injected and how you observe that the "apps dont detect that the tracking is setup" - which code chekcs it and how.
Most common case would be that you initialize something like GTM or Posthog with raw scipt tag, but then use e.g. react library to interact with it. If Iguess correctly, the correct solution would be to use native library only.
American black bearOP
yeah let me share
so im using the nextjs script tag
and im using the native applications way of checking the script existence
for example:
{/* Trustpilot Widget */}
<Script
src="//widget.trustpilot.com/bootstrap/v5/tp.widget.bootstrap.min.js"
strategy="afterInteractive"
/>
i noticed that on page switch as well sometimes the widget disassperas and fallsback
i current have it in the main root layout of my nextjs app
American black bearOP
hey @WithAuth sorry to be pinging you curios if im doing something wrong here?
i was using google tag manager to detec the tag on the site and it was failing
American black bearOP
15.3.3
I'm using the script tag and after interactive strategy
strategy="beforeInteractive"
if you use after, you need to re-run when route change.
American black bearOP
oho kay
so before interactive is the best way
@WithAuth thank you
still not working on route change like the trust pilot widget disappers
maybe i need to move thse scrips to client components ?