We have requirement for capturing what products a user searches for, clicks on, if it is added to their cart, if they then complete the purchase, what searches customers do that return zero results, etc. in salesforce google analytics. If anyone can help me,it would be great.I have written below code but with this I can track only pageviews and I need product searches and failures in it.

<site:googleAnalyticsTracking /> 
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        ga('create', 'UA-xxxxxx-x', 'auto');
        ga('require', 'ecommerce');
        ga('send', 'pageview',['sidebarSearchText']);
  • are you using a visulaforce page, a lightning community template? can you provide more details. Please take some time to review How to Ask and take the tour, welcome to SFDC!
    – glls
    Commented May 14, 2017 at 15:27
  • Hello thanks for quick response.Yes,i am using this on vf page and to be more specific,I am new in google analytics and not sure whether we can create search report on above requirement.We have ecommerce site and wants to search all those products which customer searches frequently and that is not in our stock and returning zero results.Can I do it through analytics. Commented May 16, 2017 at 8:15

1 Answer 1


You might want to get familiar with Google analytics E-Commerce tracking and the Tag Manager.

To Begin implementing Google Tag Manager on your website:

Copy the following JavaScript and paste it as close to the opening tag as possible on every page of your website, replacing GTM-XXXX with your container ID:

<!-- Google Tag Manager -->
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
<!-- End Google Tag Manager -->

Copy the following snippet and paste it immediately after the opening tag on every page of your website, replacing GTM-XXXX with your container ID: <

!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

The documentation above should provide further details on how to achieve what you are looking for.

You must log in to answer this question.

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