getNewVisitObject hook in plugin

I am trying to create a function doing something when a new visit happens. If I use the newVisitorInformation hook, it records stuff but that is only when a new visitor comes for the first time, not when he returns (correct?). So, trying to use getNewVisitObject instead:


public function getNewVisitObject($notification) {

$visit =& $notification->getNotificationObject();
$raw_data = serialize($visit);
... record into DB...

Then when I read it from DB, it is “null”.

In the Piwik source matomo/Tracker.php at 1.0 · matomo-org/matomo · GitHub , we have:


$visit = null;
Piwik_PostEvent('Tracker.getNewVisitObject', $visit);

  • looks like it deliberately passes “null” to the hook. Why, and how can I get a visit’s info?

You can use the hook ‘Tracker.newVisitorInformation’

to get the visitor information

Yes, but if the same person returns again and is no longer a new visitor, but has a new visit?

You said you are interested in “new visit only”
“I am trying to create a function doing something when a new visit happens.”

You can use the hook: ‘Tracker.knownVisitorInformation’

Yes, a new visit. But, this also includes when the same person returns again. If he comes back ten times in two weeks, I want to record something each of these ten times. He will be a “new visitor” the first time only, then the hook will not be called if I understand correctly?

So, using Tracker.knownVisitorInformation and Tracker.newVisitorInformation will give me what I want?

What about Tracker.saveVisitorInformation?

It should give you what you want, just try them ok? :wink: