I'm working on the LWC that sends an event to Google Tag Manager via window.dataLayer.push()
.
I have the Lightning Locker service enabled, so I cannot access the window property fully.
I can push to dataLayer
via the CustomEvent
though:
const pushToDataLayer = new CustomEvent('pushToDataLayer', {
detail: {
...
},
bubbles: true,
composed: true
});
this.dispatchEvent(pushToDataLayer);
It works just fine.
The task that I try to accomplish is to register a callback. The goal is
- Push an event to
dataLayer
from the LWC - Get the response from Google
- Do something in the LWC based on that response
Is there a way to achieve that?
Could we send a CustomEvent
down to the LWC? Could we invoke Apex from the window (custom JS in the <head>
section)? Rest API? EMP API?
I ran out of ideas :( Any help is much appreciated!