Than pattern is the same, but you need to find the top-level component in the app that’s always called and add that signup
there it seems

writen by Kirill Rogovoy
right. this might seem really noob but I do I call a script from inside the useEffect? XD

writen by Tiago Ferreira
Luca Restagno (ikoichi on Twitter) shared this with me
src='<https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js>'
onLoad={() => {
console.log(_.sample([1, 2, 3, 4]))
}}
/>```

writen by Tiago Ferreira
Those two are separate I think:
- Add the script tag to where the <head> things go in Gatsby (never used it)
- Call the function from the docs in useEffect

writen by Kirill Rogovoy
So I just need to make sure that the script tag is called before calling the function… Right?

writen by Tiago Ferreira
I was wondering the same recently when I wanted to import Google Analytics into my react code. I started hacking around and then realized that there is an npm component. This helped me to avoid adding the script in <head> and then calling it from the components.
FWIW I’d also ask ChatGPT for help.

writen by Pascal Bovet
If you include the script somewhere in <head>, it’s guaranteed that it will be loaded sooner than your useEffect executed

writen by Kirill Rogovoy
this is what I do in Inboxs
id='reflio-js'
async
src='<https://reflio.com/js/reflio.min.js>'
data-reflio='<your_id>'
/>```

writen by Luca Restagno (ikoichi on Twitter)
async function initReflio() {
try {
if (session?.user?.email) {
await Reflio.signup(session.user.email)
}
} catch (err) {
console.error(err)
}
}
initReflio()
}, [session?.user?.email])```

writen by Luca Restagno (ikoichi on Twitter)
Just wondering, why try-catch? I thought an unhandled exception would be printed to the console anyway?
I’d just go
if (session?.user?.email) {
return
}
Reflio.signup(session.user.email)
}, [session?.user?.email])```

writen by Kirill Rogovoy