Domanda

I have a search functionality set up in my website, which uses a third party extension retrieve the search results. The search terms are not passed as query parameters.

Below is my sample URL for my search results: mysite.com/search/results/dGVzdA/

I cannot change the URL to pass the search terms as query parameters.

So I'm trying to send Async Tracking from the google analytics javascript :

<script>
var _gaq= _gaq || [];
_gaq.push(['_setAccount','UA-XXXXXXX-X']);
//Push search query into google analytics

if ({url_segment_1} == 'search' && {url_segment_2} == 'results') 
_gaq.push(['trackPageview'],['/search/?q=test']);
else
_gap.push(['trackPageview']);
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>   

The javascript logic seems to be executing fine, I've tested it by placing alert options. So is there anything that I'm implementing incorrectly with respect to _gaq.push(). Could someone throw light on the same

È stato utile?

Soluzione

A couple of errors:

  • It's _trackPageview, with an initial underscore.
  • The argument for _trackPageview needs to be inside the array, like:

_gaq.push(['_trackPageview','/search/?q=test']);

[edit] There's also typo: _gap.push should be _gaq.push

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top