Piwik anaylytics and contact form

Hi guys,

found Piwik by chance and I really like the idea of hosting the data myself, rather than feed Google.

Now I’d like to use the data collected on the current visitor of our website, to attach it to our contact form on submit.

How would I access the Piwik stats for a live visitor using PHP? I am interested to see the visitor log for this particular visitor.

Thanks in advance,
Bora

that’s a great question!

There are two steps to include the Visitor Details in your automatic email.

  1. in Javascript, you can call the piwikTracker.getVisitorId(); function which will return a 16 chars ID string.
  2. Pass this string to your script or add a new hidden input field with the ID visitor string
  3. Then, when you generate the email content, call the Live.getVisitsDetails API, specifying the visitor ID as a segment:

http://example.org/piwik/index.php?module=API&method=Live.getLastVisitsDetails&idSite=1&period=day&date=today&format=xml&token_auth=your-token&segment=visitorId==813b8275211e7af8

  1. this will return the following output:
    [XML] Example Live.getLastVisitsDetails for visitor w/27 pageviews - Pastebin.com

Let me know if you manage to do 1) and 2) and if so, please post the code examples here for others to reuse, I think this could be a very popular Piwik trick!