Tracking External Traffic and using Goals with it

I have two related questions:

a. My website is abc.com and I have piwik installed on it. I place an ad on xyz.com and the landing page for that ad is affiliate.def.com.

What code should I use in the ad so that I can track the traffic going from xyz.com to affiliate.def.com in my piwik installed on abc.com? I dont have any control on xyz.com and affiliate.def.com.

b. My site is running on wordpress self-hosted and I am using a redirection plugin so that I use abc.com/affiliatedef as the landing page in the above ad, and the traffic arriving on abc.com/affiliatedef gets redirected by this plugin to affiliate.def.com. The plugin works fine, but the problem is that piwik does not record any activity when you arrive on abc.com/affiliatedef and immediately get redirected to affiliate.def.com. My guess is that because the redirection takes place before the piwik code is loaded, it does not get the hint about the traffic.

Solution of either of the above will be highly appreciated.

Hi Raza,

Without having control on website B and C , you need to define the href of your add to a redirection page on website A.

So, let’s see your second question.

Knowing which plugin could help… you should not choose one writing to .htaccess or generating it dynamically. You should choose a plugin using a php page and header messages for redirection.

That’s the right way to do but…

You’re right, if you are using htaccess to redirect, there is no way to make it.
BUT, if you use a php script, then the solution is:

[b]Piwik PHP Tracking API[/b]

You will then load the php page, insert tracking api, then redirect the page with header(whatever) function.

So, to resume:

  1. Link you add to a redirection page where u have control
  2. If using WP, choose a plugin that doesn’t use htacess to redirect
  3. Use Piwik PHP Tracking API
  4. Enjoy!

jOoL

Thank you Jool.

I am testing two different wordpress plugins. One is “WinkPress Affiliate Links Manager” by WinkPress WordPress Blog | Compete Themes , while the other is “Custom Field Redirect Mod: Link Custom Field” by Nathan Rice WordPress Plugins

You can download them from these URLs as I am not allowed to attach zip files to this message.

I am not sure exactly what approach they are taking, htaccess or otherwise.

To see the test implementation see here:
http://wentzvillehomebuyers.com/wordpress/

In piwik I have set a goal to track all outgoing traffic to Yahoo.com

If you click on the first post’s heading “Hello Yahoo”, it redirects to Yahoo through “Custom Field Redirect Mod” but piwik does not track the activity and the goal does not update.

If you click on the link “Yahoo Goal Working”, it takes you to Yahoo and the piwik goal is updated. However, this link is just a regular html link embedded in the post content.

If you click on the link http://wentzvillehomebuyers.com/wordpress/out/yah/ in the first post, it uses the “WinkPress Affiliate Links Manager” but again the piwik goal is not updated.

Please review and advise.

Best regards!

Raza

using “Custom Field Redirect Mod: Link Custom Field” should work well, if you use the PHP Piwik api instead of the regular JS tracking code.

you have to add the php code before the redirection happens. The plugin uses
The other one seems better to me though. It uses internal wordpress function “redirect(url,responsecode)”.

This way, you can first trigger goal using php, then let the page load and the plugin redirect to your affiliate.

This will work for both on page and off page links (ie banner on other sites).

The other one seems better to me though. It also uses internal wordpress function “redirect(url,responsecode)”. But it doesn’t uses custom fields.You could then insert the PHP Piwik api before the redirection to trigger goal.

The hack should be made before line 413 in file /affiliate-links-manager/walm.php.

jOoL

Thank you so much Jool.

The hack should be made before line 413 in file /affiliate-links-manager/walm.php.

:slight_smile:

Now can you tell me exactly what code should go just above line 413?

I have gone through http://piwik.org/docs/tracking-api/ several times but I am little clueless on which code snippet should go here.

Thanks again Jool.

u’re welcome!

Actually, i don’t have much time to look at it closer. But you should find the appropriate code in the doc here: http://piwik.org/docs/tracking-api/

Use this snipnet:


<?php
// -- Piwik Tracking API init --
require_once "/path/to/PiwikTracker.php";
PiwikTracker::$URL = 'http://www.example.org/piwik/';
?> 


<?php
$piwikTracker = new PiwikTracker( $idSite = {$IDSITE} );
// You can manually set the visitor details (resolution, time, plugins, etc.)
// See all other ->set* functions available in the PiwikTracker.php file
$piwikTracker->setResolution(1600, 1400);

// Sends Tracker request via http
$piwikTracker->doTrackPageView('Document title of current page view');

// You can also track Goal conversions
$piwikTracker->doTrackGoal($idGoal = 1, $revenue = 42);
?> 

jOoL

Hi Jool.

Thank you so much for the help. So far so good. I am able to redirect the traffic to the redirect url, and track the page views under the Pages tab, as well as track the goal and its revenue value hardcoded in:

$piwikTracker->doTrackGoal($idGoal = 1, $revenue = 42);

How can I:

  1. Pass the goal dynamically so that each page can have its own goal and goal value, either entered in custom fields, or passed in the url like
    www.mysite.com/pagetoyahoo/?idGoal=1&revenue=20

If we can use the custom field option, then assuming I am using a custom field “mygoal” and a custom field “mygoalrevenue”, then how can I bring those values in this:
$piwikTracker->doTrackGoal($idGoal = mygoal, $revenue = mygoalrevenue);

  1. I modified
    $piwikTracker->doTrackPageView(‘Document title of current page view’);
    to
    $piwikTracker->doTrackPageView($documentTitle);
    but it reports it as “Page Name not defined” under the Page Titles tab.

Good start.

[quote=raza]
How can I:

  1. Pass the goal dynamically so that each page can have its own goal and goal value, either entered in custom fields, or passed in the url like[/quote]
    To use custom fields, then use the plugin “Custom Field Redirect” !

First, create a category for theses articles (ads etc) ie “Affiliate”. You will then put all redirection articles to affiliate links in this cat. Additionaly, you can remove this cat from the main page and/or from category list in you blog. Wordpress documentation can help you on this.

Second, create a post in this cat. And define 3 custom fields:

redirect → URL TO AFFILIATE
myGoal → AFFILIATE NAME
myGoalRevenue → REVENUE

To retreive the custom fields, wordpress provides a function for this “get_post_meta($post_id, $key, $single);”
Ref: http://codex.wordpress.org/Function_Reference/get_post_meta.

The code here under retrives the them:


		$idPost = get_the_ID(); // this retreives the ID of the post
		$myGoal=get_post_meta($idPost, "myGoal", true);
		$myGoalRevenue=get_post_meta($idPost, "myGoalRevenue", true);

then simply set them in the piwik tracker as follow:


$piwikTracker->doTrackGoal($idGoal = $myGoal, $revenue = $myGoalRevenue); 

[quote=raza]
2. I modified
$piwikTracker->doTrackPageView(‘Document title of current page view’);
to
$piwikTracker->doTrackPageView($documentTitle);
but it reports it as “Page Name not defined” under the Page Titles tab.[/quote]

As the page is not displayed, and the title attribute not retreived, this value is blank. To retreive the page title, use worpress function “get_the_title(ID)” as follow:
Ref: http://codex.wordpress.org/Function_Reference/get_post_meta


$pageViewTitle=get_the_title($idPost); // this assumes that $idPost has been retreived first. 


Then add it to tracker:


$piwikTracker->doTrackPageView($pageViewTitle);

This should work like a charm!
Good work.
jOoL

Hey Jool.

It did work like a charm!

Very helpful indeed. And in the process I have gained good insight into piwik as well… well as a starting point :slight_smile:

Cheers.

Glad to hear this. Bye