Third-Party Analytics Libraries Blocked by LWS
Analytics libraries such as Google Analytics and Adobe Analytics require access to the entire page unrestricted. This requirement conflicts with the LWS requirement that code belonging to one namespace isn’t allowed to access data from a different namespace.
LWS prevents the third-party analytics scripts from accessing code running in the browser outside the JavaScript sandboxes. Only platform code is allowed to run outside sandboxes. LWS also prevents analytics scripts from accessing global objects in JavaScript sandboxes because the scripts don’t belong to the namespaces reserved for the sandboxes.
Experience Cloud sites can use a workaround to enable analytics libraries to work with Lightning Locker. This approach can also work if LWS is enabled in the org instead of Lightning Locker. The workaround applies only to Experience Cloud sites because Experience Builder gives admins access to the head
markup of the sites. Other Salesforce applications and components don’t allow such access. For more information, see the Experience Cloud Developer Guide.