Referrer and search engine tracking doesn't work

Hello,
It seems that Piwik doesn’t track the referrer URLs. We got only 5-10 search referers per day on Piwik, which is far less than the real numbers (according to Google Analytics 6000+ visitors came from search engines a day).

Other analytics seem to work fine.

Do you have any idea what causes this issue?

Thanks.

The only thing i can thin of is a redirect (e.g. from http to https on your site) interfering with the referrer data.

Maybe check the data the browser is sending to piwik. If you visit your site, it should send a request similar to
https://demo.piwik.org/piwik.php?action_name=Contact the virtual drums dev team&idsite=3&rec=1&r=837126&h=19&m=28&s=3&url=http://virtual-drums.com/contact.php&urlref=http://virtual-drums.com/&_id=790b246e588ec1ed&_idts=1495128475&_idvc=1&_idn=0&_refts=0&_viewts=1495128475&send_image=1&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=0&java=0&gears=0&ag=0&cookie=1&res=1920x1080&gt_ms=81&pv_id=oX5oy8.

Especially look at the urlref parameter, as this is what piwik records.

We use https only on specific pages like login, signup etc, not on general sites.
However Piwik is on an https URL, can it cause any trouble?

Okay, that shouldn’t create an issue. What does the urlref parameter say?

Here it is:

urlref=https%3A%2F%2Fwww.google.hu%2F&uid=undefined&_id=d5d4cd07616a5428&_idts=1494940605&_idvc=4&_idn=0&_refts=1495130448&_viewts=1495130448&_ref=https%3A%2F%2Fwww.google.hu%2F&send_image=1&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=1&java=0&gears=0&ag=0&cookie=1&res=1440x900&gt_ms=629&pv_id=B1l4to

urlref=https://www.google.hu/ means that the referrer is correct (Google isn’t sending keywords anymore)

So how does this visit show up in piwik?

I checked the segmented visitor log which came from Google, but the visit didn’t show up.
We pass a username to piwik, do you think it has to do something with this issue?

If the user is not logged in Piwik associates the visitor with the name “undefined”. Most of the case visitors coming from Google are not logged in, maybe Piwik aggregates all these people and handles it as ONE user and this is what causes this issue?

I have not used the user ID feature, but that seams possible. After reading User ID - Analytics Platform - Piwik and JavaScript Tracking Client: Integrate - Piwik Analytics - Developer Docs - v3 I think the ID should always be unique for each logged in user.

And logged out users should just have no user ID set:

var _paq = _paq || [];

<?php
// If used is logged-in then call 'setUserId' 
// $userId variable must be set by the server when the user has successfully authenticated to your app.
if (isset($userId)) {
     echo sprintf("_paq.push(['setUserId', '%s']);", $userId);
}
?>

_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);

Another advantage is that this way you can track when your users log out.

Yes, that was the problem. If anyone who uses Tag Manager and comes across with this issue, this is what the solution looks like:

if (typeof {{userName}} !== ‘undefined’) {
_paq.push([‘setUserId’, {{userName}}]);
}

It seems that referers are correctly logged now.
Thanks!