It sounds like a patch was released that allows us to create a lightning component that can load up google analytics javascript.


Screenshot from https://success.salesforce.com/_ui/core/chatter/groups/GroupProfilePage?g=0F9300000001oDdCAI&fId=0D53000002I99WnCAJ

Has anyone had any luck doing this? It sounds like I just need to build a client-side controller that loads up a function with the Google Analytics code function.

Here is what I am trying:


    <ltng:require scripts="/resource/ga.js"

Client Controller:

    loadAnalytics : function(component, event, helper) {
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

        ga('create', '***API Token***', 'auto');
        ga('send', 'pageview');


1 Answer 1


As of Winter '17 Lightning communities (Napili Template) lets you enable this functionality OOTB, you just need your tracking ID and you can indicate if you authorize Google Analytics to access additional data (queries, user types and activities) enter image description here

Track, Learn, and Fine-Tune with Google Analytics

Enable page tracking by adding your Google Analytics™ tracking ID in Community Builder. Use the resulting data to learn more about the pages your customers visit. Then adjust your community’s pages to more accurately reach your customers. After you enter your Google Analytics ID in Settings | Advanced, publish a community to enable the service. Your community’s analytics data streams directly to the Google Analytics service where you can review and interpret it.

You must log in to answer this question.

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