When using Google's Custom-Search Overlay Layout, search data is not collected by Google Analytics

I have a Google Custom Search Element on my site configured to use "Overlay Layout":

The layout settings

And I have a Google Analytics profile associated with this Google Custom Search account installed in the corresponding section, for example:

The Analytics link settings

I use the default Google Analytics code and the Google Custom Search (Google) code. Site Search Tracking analytics is included in Report View Settings:

Google Analytics Views Settings

Problem:

Google Analytics . , Layout Layout. , , Analytics.

Div, API Google.

:

, Google Analytics ? - , ? - , ?

+4
1

:

Google Support, :

  • GCS @https://www.google.com/cse

  • Google Analytics ,

  • Async Analytics ( Universal Analytics 2014 ). . :

    <head>
    
    <!-- Your head tags, etc here -->
    
    <script type="text/javascript">
      var gaq;
      var _gaq = gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXXX-YY']);
      _gaq.push(['_setDomainName', 'yourdoamin.com']);
      _gaq.push(['_setAllowLinker', true]);
      _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);
      })();
    
    </script>
    </head>
    
  • GCS,

  • , , :

    <body>
    <script>
    
    var customUIBehaviours = function(){
        //your jQuery Post UI changes to the GCS box may come here
    };
    
    var renderSearchElement = function() {
        google.search.cse.element.render({
            div: 'gsd', 
            tag: 'search', 
            attributes:{
                linkTarget:'_self',
                gaQueryParameter: 'q',
                gaCategoryParameter:'',
                noResultsString:'No results.',
                enableAutoComplete: true
            }
        });
    
    };
    
    var myCallback = function() {
        if (document.readyState == 'complete') {
            renderSearchElement();
            customUIBehaviours();
        } else {
            google.setOnLoadCallback(function() {
                renderSearchElement();
                customUIBehaviours();
            });
        }
    };
    
    //this will make the GCS render by myCallback
    window.__gcse = {
      parsetags: 'explicit',
      callback: myCallback
    };
    
    
      (function() {
        var cx = 'YOUR GCS CODE HERE';
        var gcse = document.createElement('script');
        gcse.type = 'text/javascript';
        gcse.async = true;
        gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
            '//www.google.com/cse/cse.js?cx=' + cx;
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(gcse, s);
      })();
    </script>
    <div id="gsd" class="gsce-searchBox"></div>
    </body>
    

GCS V2 @https://developers.google.com/custom-search/docs/element#cse-element

0

Source: https://habr.com/ru/post/1538056/


All Articles