fullstory-browser-sdk icon indicating copy to clipboard operation
fullstory-browser-sdk copied to clipboard

_fs_script is not defined

Open sanathfp opened this issue 4 years ago • 6 comments

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.

sanathfp avatar Oct 15 '20 01:10 sanathfp

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.

van-fs avatar Oct 15 '20 15:10 van-fs

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 avatar Oct 15 '20 16:10 sanathfp

@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

van-fs avatar Oct 15 '20 16:10 van-fs

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!

sanathfp avatar Oct 15 '20 16:10 sanathfp

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

patrick-fs avatar Oct 15 '20 17:10 patrick-fs

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

dalmia avatar Oct 17 '22 05:10 dalmia