To ensure that "last cookie wins" works similar to analytics and as expected by everyone familiar with online marketing, I would like to track EVERY campaign interaction (not only the first one within a visit). This is why I would like to split a visit whenever there is a visitor coming from a search engine or a campaign.
I suggest changing core/Tracker/Visit.php from:
/**
* Returns true if the last action was done during the last 30 minutes
* <a class='mention' href='https://github.com/return'>@return</a> bool
*/
protected function isLastActionInTheSameVisit()
{
return isset($this->visitorInfo['visit_last_action_time'])
&& ($this->visitorInfo['visit_last_action_time']
> ($this->getCurrentTimestamp() -
Piwik_Tracker_Config::getInstance()->Tracker['visit_standard_length']));
}
To:
/**
* Returns true if the last action belongs to the last Visit.
* This is usually true, when the previous action was done during the last 30 minutes.
* Provides hook for individual splitting of visits.
* <a class='mention' href='https://github.com/return'>@return</a> bool
*/
protected function isLastActionInTheSameVisit()
{
$belongsToLastVisit = isset($this->visitorInfo['visit_last_action_time'])
&& ($this->visitorInfo['visit_last_action_time']
> ($this->getCurrentTimestamp() - Piwik_Tracker_Config::getInstance()->Tracker['visit_standard_length']));
Piwik_PostEvent('Tracker.isLastActionInTheSameVisit', $belongsToLastVisit,
array('visitorInfo' => $this->visitorInfo, 'request' => $this->request, 'idsite' => $this->idsite));
return $belongsToLastVisit;
}
This allows me to decide on my own, whether it is a new visit or not, e.g. somewhere in my Tracker-Plugin:
public function isLastActionInTheSameVisit($notification)
{
$belongsToLastVisit = &$notification->getNotificationObject();
$info = $notification->getNotificationInfo();
$referrer = new Piwik_Tracker_Visit_Referer();
$refererUrl = Piwik_Common::getRequestVar('urlref', '', 'string',
$info['request']);
$currentUrl = Piwik_Common::getRequestVar('url', '', 'string',
$info['request']);
$refererInfo = $referrer->getRefererInformation($refererUrl,
$currentUrl, $info['idsite']);
if(in_array($refererInfo['referer_type'], array(2,6))) # Ignores
direct entries.
{
$belongsToLastVisit = false;
}
}
I posted this Suggestion in the Forums at http://forum.piwik.org/read.php?2,77140 and would like to see it being released soon.
I guess that is not a feature request. It`s a bug! It is a basic requirement to an analytics tool (in particular campaign tracking) that it works after some basic online marketing rules. With the current implementation of campaign tracking, it make no sense to track campaigns, if you work in professionell online marketing business. Hope this issue will be fixed as soon as possible.
See the feature request at: #2624 When a campaign changes, creates a new "visit" by default