Suggestion for Hook to individually split Visits


#1

Unfortunately I did not get any feedback on piwik-hackers. Perhaps no one is using this mailing list anymore, so I’ll try it here, in the forums:

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
 * @return 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.
 * @return 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;
       }
}

Is this possible, or is there any other more simple way to for me to reach my goal?

Do you think my suggestion incurres massive performance issues?


(Matthieu Aubry) #2

i haven’t seen your message on piwik-hackers.
If your change works as expected then it’s fine… :wink:


#3

thanks for your reply, matt.

how can we get it into the next release? shall i open a ticket in trac and add the code to it?


#4

I have added a ticket to trac now: http://dev.piwik.org/trac/ticket/2468


#5

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.