Forums de discussion

send searchterm to piwik

thumbnail
Sebastian Wörner, modifié il y a 8 années.

send searchterm to piwik

Junior Member Publications: 46 Date d'inscription: 18/11/14 Publications récentes
Hi,

i connected our Piwik system to our new Liferay sandbox system.
The user/visitor statistics works fine. To reach this, i used Site-Admin-> Config-> Site Settings -> Analytics and add the piwik code.

<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="<url here>";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 4]);
    _paq.push(['setCustomVariable',1,"userName",themeDisplay.getUserName(),"visit"]);
    _paq.push(['trackPageView']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript><p><img src="<url here>" style="border:0;" alt=""></p></noscript>
<!-- End Piwik Code -->


Now i tried to transfer the search terms to piwik.
We used the search application with the Solr 4 App from marketplace (the search Solr/Lucene works with Liferay).
Unfortunately, i have no idea how to hook up, so that piwik can log the search terms from the user. I found no Javascript Field to add Piwik Code. It would be perfect if I'd noticed the number of search hits too.
Is this possible?

Thanks for helping :-)
thumbnail
David H Nebinger, modifié il y a 8 années.

RE: send searchterm to piwik

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
You do it in line 11, adding your custom variable. Add one for the keywords and then pull them from the request params.
thumbnail
Sebastian Wörner, modifié il y a 8 années.

RE: send searchterm to piwik

Junior Member Publications: 46 Date d'inscription: 18/11/14 Publications récentes
Hi,

thanks for the tipp.
I add following code


if (getURLParameter('_3_keywords')){
    _paq.push(['setCustomVariable',2,"search",getURLParameter('_3_keywords'),"page"]);
}
...
function getURLParameter(name) {
  return decodeURIComponent((new RegExp('[?|&amp;]' + name + '=' + '([^&amp;;]+?)(&amp;|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
}


and it works. I get the search terms in Piwik under 'Visitors' -> 'Custom Variables'.

Is there a 'smarter' way to do this? I would like to have the sum of hits per search term.
Is there a way to get this?

Thanks
thumbnail
David H Nebinger, modifié il y a 8 années.

RE: send searchterm to piwik

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
The search tag ends up knowing the hit count, so you might be able to get access it to it to do the same as your keywords handling.