simple Piwik stats integration

Solutions for other advanced phplisters

simple Piwik stats integration

Postby Chris A. » 9:51am, Sun 15 Aug, 2010

Hi,
I haven't found that topic on the forum.

I'm using Piwik http://piwik.org/ for web analytics and there is a very useful functionality where you can follow visitors and the achievement of "goals" (e.g. somebody enters the checkout page) filtered by how visitors have entered your page (referrer). One possibility here is to use campaigns, that is you append (in a newsletter or with a web banner) to the URL of your page (that is monitored by Piwik) a query like
Code: Select all
?piwik_campaign=some_name
Piwik will then tag that visitor in its logs and you can check what people who came via this link have done on your site.

Now my question: Is it possible to automatically add to every link in the newsletter that lead to one of your own URLs a predefined string, either static or with the message ID (or date/time)? This would be extremely useful to implement some kind of general click tracking, which is more oriented on goal conversion. I actually don't need to know after how many seconds subscriber X clicked on which link, it would be very useful, however, to know which users actually reached the checkout page, the petition, the contact form, a particular download page etc. or which newsletters have been most successful by comparing their IDs with the goal conversion rate.

Of course, this wouldn't substitute the click tracking since you can follow only links that lead to pages monitored by your stats software (where you must be able to embed some script into the source.)

I think that in terms of coding it shouldn't be too difficult to implement that, if it doesn't exist yet. Most convenient would, of course, be to have an extra field in the Send Message form where you can enter the string to be appended to all links, with an option for placeholders like message ID, date and time. Somewhere in the general settings you need to give a list of own URLs that are monitored.

thanks!
Chris A.
phpLister
 
Posts: 12
Joined: 9:34am, Thu 01 May, 2008
Location: Prague

Re: simple Piwik stats integration

Postby Dragonrider » 11:56am, Sun 15 Aug, 2010

According to the Piwik website, you have to use an image, bit like phpList uses?

Simple Image Tracker
The Simple HTML Image Tracker tag can be used when Javascript is disallowed but pure HTML allowed: MySpace, Ebay for example, but also email newsletters.
Note: the code doesn't use Javascript so Piwik will not be able to track some user information such as search keywords, referer websites, screen resolutions, plugin support and page titles.
My sites:- http://wharfedalefestival.co.uk, http://ilkleygardeners.org.uk, http://emergencyaid.net, http://dragonrider.co.uk
Latest phpList version is now 3.0.12 (3 February 2015) and requires a minimum of MySQL 5.0 and PHP 5.3.x
Dragonrider
Moderator
 
Posts: 3460
Joined: 6:58am, Sun 02 Jul, 2006
Location: Ilkley, West Yorkshire, United Kingdom

Re: simple Piwik stats integration

Postby Chris A. » 12:26pm, Sun 15 Aug, 2010

What you mentioned are the "alternative ways to record visitors, visits, pages and Goal conversions" if embedding Javascript is restricted. Normally you put a snippet of Javascript into the HTML-source, and there is an image for the case of <noscript>.
But this describes only the ways how you tap the information on your site. The question is now, how we can "tag" the visitors who go there. As for PHPlist, you would simple use the link plus a unique query like http://www.example.com/guest-signup/?pi ... n-to-event - in the stats you would then be able to identify all visitors who came to http://www.example.com/guest-signup/ via that particular link.

PS: the documentation about campaigning with Piwik is a bit hidden: http://dev.piwik.org/trac/ticket/604
Chris A.
phpLister
 
Posts: 12
Joined: 9:34am, Thu 01 May, 2008
Location: Prague

Re: simple Piwik stats integration

Postby duncanc » 11:39am, Mon 16 Aug, 2010

Not sure whether I am understanding your requirement properly but you might want to look at modifying the phplist link tracking code to add the message id onto the target URL. Piwik can then use that message id to identify the source.

The file lt.php redirects to the target with this line of code

Code: Select all
header("Location: " . $linkdata['forward']);


You can add the message id as a parameter with something like
Code: Select all
$target = $linkdata['forward'];
$target .= strpos($target, '?') : '&' : '?' . "piwik_campaign=$messageid";
header("Location: $target");


You probably want to add some filtering so that only targets to your web site have the parameter added.
duncanc
Moderator
 
Posts: 2440
Joined: 6:34am, Sat 08 May, 2010
Location: London

Re: simple Piwik stats integration

Postby Chris A. » 12:01pm, Mon 16 Aug, 2010

That looks good, thank you!
Chris A.
phpLister
 
Posts: 12
Joined: 9:34am, Thu 01 May, 2008
Location: Prague

Re: simple Piwik stats integration

Postby Chris A. » 1:06pm, Mon 16 Aug, 2010

I think your first ':' should be '?'.

This is what I ended up with:
Code: Select all
// URLs which are monitored by piwik
$my_webs = array(
      'burma-center.org',
      'dmsbambus.cz',
      'mikrogranty.cz'
   );

$target = $linkdata['forward'];

foreach($my_webs as $what) {
   if(strpos($target, $what)) {
      $target .= strpos($target, '?') ? '&' : '?';
      $target .= 'piwik_campaign=newsletter&piwik_kwd='.$messageid;
      break;
   }
}

header("Location: $target");


I decided to submit the message id as keyword. So far it's working.
Chris A.
phpLister
 
Posts: 12
Joined: 9:34am, Thu 01 May, 2008
Location: Prague

Re: simple Piwik stats integration

Postby duncanc » 1:30pm, Mon 16 Aug, 2010

Ah you're right about the : . I forgot to add the disclaimer that it was untested!

Glad that it's working.
duncanc
Moderator
 
Posts: 2440
Joined: 6:34am, Sat 08 May, 2010
Location: London


Return to Advanced Answers, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 2 guests