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
- Is it possible to track events using Google Analytics inside LWC in a Community?
- If so, how can I achieve it?