Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Tweeted twitter.com/StackSalesforce/status/1313131854388776960
edited tags
Link
Robs
  • 9.4k
  • 21
  • 119
  • 224
Source Link
Robs
  • 9.4k
  • 21
  • 119
  • 224

Google Analytics Event Tracking in Community using LWC

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?