1

We have Lightning Community with lightning components. We have created Google Analytics account and copied/pasted GA script and tracking code into Community. We are getting some tracking in GA for this Community. But we would like to attach some tracking to button clicks and other events on the Community pages.

As I understand so far, somehow ga('send', 'pageview'); should be called on button click for example.

Am I correct. What would be the major steps to implement it for existing Community?

Many thanks

0

I haven't implemented Analytics in Communities, so there may be an easier way to do this - however, the following technique should work:

Download my custom Analytics component from github.

Add a public <aura:method> to the component, which would be in this form:

<aura:method name="logclick" action="{!c.logclick}">
  <aura:attribute name="payload" type="Object" default="{}"/>
</aura:method>

Controller:

logclick : function(component, event, helper) {
  var params = event.getParam("arguments");
  var payload = params.payload;
  ga('send', 'pageview');
  //at this point you can send anything in your payload object also
}

If you look at the rest of my component, you can see it takes care of initializing google analytics.

Just include this analytics component in your other lightning components and call it like this (assuming you've given your analytics component an aura id of analytics:

logClick : function(component, event, helper) {
  component.find("analytics").logClick({item1:"test1",item2:"test2"});
}

You will also need to upload the static resource to your org as my github component requires it. It's the same analytics code that you already stored in communities.

You can send a heap of stuff to google, eg:

ga('send', 'event', {
  'eventCategory': 'Category',
  'eventAction': 'Click',
  'eventValue': 55
});
| improve this answer | |
0

I've found most recent to date solution. You don't need to download any js file. See this link: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_forceCommunity_analyticsInteraction.htm Of course you still need to create Google Analytics account and copy/paste GA script and tracking code into Lightning Community, as this guide mentions also.

| 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.