fullstory-browser-sdk
fullstory-browser-sdk copied to clipboard
_fs_script is not defined
I'm using an angular app and I'm trying to render the app on the server. Here is my app.component.ts
constructor() {
FullStory.init({ orgId: '<code>',
devMode: !environment.fullstoryProduction });
}
When I try to run my application, I get an error that says _fs_script is not defined
. I tried manually setting the window element by using window['_fs_script'] = 'edge.fullstory.com/s/fs.js';
. Still no luck.
Hi @sanathfp, thanks for reaching out. Admittedly, I haven't tested a server-side rendered scenario for the browser-sdk. Is your app on a test server that I could investigate? As a stop gap, you could simply add the FullStory snippet to the <head>
tag in index.html. This obviates the browser-sdk altogether, but if you're in need to getting an SSR version of your app with FullStory, it's an immediate solution. Let me know if that test server might be available, and I'll take a look. Else, I'll need time to update our angular demo app and test.
Hey @van-fs Thanks for reaching out on such short notice. I don't have the code up on a test server yet. I could put the snippet code directly on the head tag, but then I also need it to not track while running on the staging servers. That's in fact, the main reason why I'm using your npm library!
@sanathfp Ah, so you're using the browser-sdk to selectively load FullStory, correct? If so, I think we can solve that outside of code actually. You can update FullStory admin settings to block recording for specific domains (e.g. localhost:4200 or dev.yourapp.com). See Can I disable recording for a specific domain? Let me know if that's a more appropriate solution to limiting recording for your app
This sounds like a good solution! I'm guessing it will work as it doesn't depend on the library. Thanks for this. But, it does come across as a bummer to people who want to use this library while doing SSR. Though this might be of low priority, I think it's still worth fixing later.
Thank you!
Hey @sanathfp not sure if this helps you, but check out this tip we gave someone for running FullStory in a Next.js application: https://github.com/fullstorydev/fullstory-browser-sdk/issues/51
Following @patrick-fs's comment, this is the snippet that worked for my Nuxt.js SSR app in case anyone came here looking for that (adding the fullstory SDK as a plugin and using Nuxt Lifecycle hooks to ensure that the script is added only on the client side):
import * as FullStory from '@fullstory/browser'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.hook('app:beforeMount', () => {
FullStory.init({ orgId: useRuntimeConfig().FULLSTORY_ORG_ID })
nuxtApp.vueApp.config.globalProperties.$FullStory = FullStory
})
})