Campaign Tracking via PHP Tracker API


#1

Hello everybody,

first of all thank you very much for this great product!

Right now, I have a little problem and I hope you can help me solving it: I want to track campaigns using the PHP Tracker API and I can’t get campaigns to show up in my reports. Here is my code:


require_once './PiwikTracker.php';
  
  PiwikTracker::$URL = 'http://192.168.1.1';
  
  $t = new PiwikTracker( 19 );
  
  
  $cp[0] = 'min_test';
  $cp[1] = 'min_test';
  
  $t->setAttributionInfo(json_encode($cp));


    // Mandatory: set the URL being tracked
    $t->setUrl( 'http://example.org' );

   $t->doTrackPageView('TEST_Z');
...

and the api call:


http://192.168.1.1/piwik.php?idsite=19&rec=1&apiv=1&rand=1679400080&cip=192.168.1.22&_id=10233ece08fdae63&url=http%3A%2F%2Fexample.org&urlref=&_rcn=min_test&_rck=min_test&action_name=TEST_Z

Please note that tracking actually works for sitename e.g. Sitename “TEST_Z” actually shows up in report, but just campaigns doesn’t.

Since it didn’t work I also added pk_campaign and pk_kwd to the api call url:


http://192.168.1.1/piwik.php?idsite=19&rec=1&apiv=1&rand=1679400080&cip=192.168.1.22&_id=10233ece08fdae63&url=http%3A%2F%2Fexample.org&urlref=&_rcn=min_test&pk_campaign=min_test&_rck=min_test&pk_kwd=min_test&action_name=TEST_Z

But still no luck :frowning: I hope you can help me.

Thank you!


#2

Hello,

I was wondering if anyone can tell me if the functionality in the PHP Tracker API for tracking campaigns already exists? Can setAttributeInfo only be used for goal tracking?

Thank you.


(Matthieu Aubry) #3

Yes you can, you have to call setUrl() with the URL containing campaign parameters as per http://piwik.org/docs/tracking-campaigns/url-builder/


#4

Thanks a lot, Matt!

This actually worked out great! I would love to see that in the Piwik Tracker API as I couldn’t get any result using setAttributeInfo (I assume this is just used for goal tracking).

Here ist my minimal tracking example. Be sure to fill $pk_ vars on the top.


define('PIWIK_INCLUDE_PATH', dirname(__FILE__));  
require_once PIWIK_INCLUDE_PATH . '/libs/PiwikTracker/PiwikTracker.php';
    
PiwikTracker::$URL = 'http://urltopiwik';
      
$t = new PiwikTracker($pk_siteid);
  
$t->setUrl('http://example.com/?pk_campaign='.$pk_campaign.'&pk_kwd='.$pk_kwd);
    
$t->doTrackPageView($pk_campaign);

With the example above, campaigns show up in reports of the defined site ($pk_siteid).

Thank you.