function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Borislav StoilovBorislav Stoilov 

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? 

HarshHarsh (Salesforce Developers) 
Hi Borislav,
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.
 
Borislav StoilovBorislav Stoilov
That is what I followed. The script is available only to the component that loads it and not for the whole page