0

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 /> 
    <script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function()
        {
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
        ga('create', 'UA-xxxxxx-x', 'auto');
        ga('require', 'ecommerce');
        ga('send', 'pageview',['sidebarSearchText']);
});
    </script>
  • 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 May 14 '17 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. – Varun Gupta May 16 '17 at 8:15
2

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 -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');</script>
<!-- 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.

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.