You need to sign in to do that
Don't have an account?
How to include JS library into SF
I am trying to integrate FullStory into SF.
The instalation is quite simple for regular pages, you just include a code snippet in the head ot the page, stuff gets loaded and it just works. However with Salesforce I am restricted by the shadow dom.
What I've tried is creating a static resource with the installation snippet, placed it inside a component and then placed the component inside a page.
I have logs in the script indicating that it was executed, furthermore in the component I have access to the variables declared by the script. However those variables are not present in the window object in the browser console. In order for FullStory to work (or any other third party that gets installed this way like Google Analytics) the data needs to be accessible on page global level.
This is my component
import { LightningElement } from 'lwc'; import fsScript from "@salesforce/resourceUrl/fsScript"; import { loadStyle, loadScript } from "lightning/platformResourceLoader"; export default class FullStoryTest extends LightningElement { connectedCallback() { console.log("in connect " + fsScript); loadScript(this, fsScript) .then(() => { console.log("Loaded"); console.log("FS obj " + FS); window.FS = FS; // I have the variable here console.log("window " + window); console.log("FS window " + window.FS); // setting it to the window object doesn't help }).catch((err) => console.log(err)); } }
How to properly install this library?
Please follow the below Salesforce article to achieve your requirements.
https://developer.salesforce.com/docs/platform/lwc/guide/js-third-party-library.html
Related:-
http://https://absyz.com/how-do-we-import-an-external-library-into-salesforce-lightning/ (http://https://absyz.com/how-do-we-import-an-external-library-into-salesforce-lightning/)
Please mark it as Best Answer if the above information was helpful.
Thanks.