I'd like to use Google Analytics Event Tracking inside a Community in LWC

We have Google Analytics configured in Builder > Settings > Advanced > Google Analytics

The documentation says to use something like this JavaScript command:

trackClickEvent(category, value) {

    ga("send", "event", {
        eventCategory: category,
        eventAction: "click",
        eventLabel: value


But it does not work.

I've used this code to investigate:

if (window.hasOwnProperty("ga")) {

And it looked like ga is not available.

Looking at this Knowledge Article: Limitations of web analytics and LWC in Lightning Communities, it seems like it might be impossible to achieve what I need.


  1. Is it possible to track events using Google Analytics inside LWC in a Community?
  2. If so, how can I achieve it?
  • Robs, did you ever find a solution for this? Thank you – Alex Cortes Aug 17 '20 at 18:24
  • Robs any news on our side concerning this limitation ? – David-IT Oct 5 '20 at 14:50

Robs, it is not possible to directly track events using Google Analytics inside LWC. But, you can try a workaround as follows. Embed your LWC inside a Lightning Aura Component and use this Aura component in you Community. Whatever data you want to send to Google Analytics, send it from LWC to Aura through an event. And From Aura Component, fire a Google analytics event along with data received from LWC.

Please refer below link to fire event from Aura Component.

Track Events triggered by Custom Aura Components

Please let me know if this works for you.

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.