Can someone tell me how can I access DOM dataLayer in lightning component controller? I'm using like this but its not pushing into DOM dataLayer

    window.dataLayer = window.dataLayer || [];
            'event': 'testEvent',

You can't, not directly. The global window object typically found in the DOM is replaced with a SecureWindow implementation. As such, you can set a dataLayer in your component, but it won't be globally visible. I presume you're trying to do this for Google Tag Management; you would need to import that library into your component and use whatever methods are available to manipulate the data layer.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.