6

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:

console.log(window.hasOwnProperty("ga"));
if (window.hasOwnProperty("ga")) {
    console.log(window.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.

Questions

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

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .