Search code examples
google-analyticsgoogle-custom-search

Connect Google Analytics and Google custom search engine?


Hi I want to connect google custom search engine to google analtycs, but are not sure of the procedure ...

I just have to add:

 var _gaq = gaq || [];

      _gaq.push(['_setAccount', 'UA-12345678-1']);

       _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script');

        ga.type = 'text/javascript';

        ga.async = true;

        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www')

                      + '.google-analytics.com/ga.js';

        var s = document.getElementsByTagName('script')[0];

        s.parentNode.insertBefore(ga, s);

      })();

????

I have to change something in the panel of google analytics?

I have to add this (the above code):

var _gaq = gaq || [];          
  _gaq.push(['_setAccount', 'UA-12345678-1']);           
  _gaq.push(['_trackPageview']);

or this? :

var gaq;
  var _gaq = gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXX-YY']);
  _gaq.push(['_setDomainName', 'yourdoamin.com']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

Solution

  • In your custom site search configuration go to: Statistics and Logs->Google Analytics and fill in the details.

    Alternatively, if you redirect all queries to a page like this:

    www.example.com/search/?q=searchquery
    

    Then you can just add this directly to Google Analytics in Admin->View Settings->Site Search Settings.

    Personally I do both just to be sure.