You are here:  » Tracking keywords through Price Tapestry


Tracking keywords through Price Tapestry

Submitted by npaitken on Tue, 2008-09-02 13:15 in

Hi David,

I'm thinking of using PPC advertising to drive traffic to my Price Tapestry site. I want to track keywords from Adwords Ad URLs through my site and pass into the outgoing affiliate link, so that I can track commissions at the keyword level.

In the past I've used the following technique to do this

1)Embed relevant keyword in Adwords Ad outgoing URL - http://mysite.com/landing_page.php?keyword=red+widget
2)Grab keyword from referer URL and set in a cookie as variable ($kwd)
3)Pass cookie keyword ($kwd) into outgoing affiliate link - http://affiliatewindowlink?clickref=$kwd

Is it possible to employ a similar approach in Price Tapestry?

Many thanks,
Neil

Submitted by support on Tue, 2008-09-02 15:26

Hello Neil,

The method you describe should be straight forward to implement, although it can get quite involved. Search the forum for "tracking" etc. and you will find some quite lengthy threads involving new tables etc.

As you describe above, it's probably easiest to "work backwards". Firstly, we can modify jump.php to look for "clickref=" in the Buy URL and replace it with "clickref={keyword}" if the cookie is present. To do this, look for the following code on line 14 of jump.php:

header("Location: ".$product["buy_url"]);

...and REPLACE this with:

if ($_COOKIE["keyword"] && strpos($product["buy_url"],"clickref="))
{
  $product["buy_url"] = str_replace("clickref=","clickref=".urlencode($_COOKIE["keyword"]),$product["buy_url"]);
}
header("Location: ".$product["buy_url"]);

(if you're not already using Price Tapestry's jump.php; you will need to enable tracking using $config_useTracking = TRUE; in config.php)

So, with that in place, all that's needed is to set the "keyword" cookie whenever the keyword parameter is present in the URL of one of your landing pages. That's straight forward too, so taking products.php as an example (which would be the landing page for your main product pages) simply add the following code right at the top (after the opening PHP tag):

if ($_GET["keyword"])
{
  $expire = mktime(0,0,0,1,1,2010);
  setcookie("keyword",$_GET["keyword"],$expire,"/");
}

That's pretty much all there is to it. The $expire variable will set the cookie length, which you can see I've constructed using mktime and a date sometime in the year 2010, which is to all intents and purposes a "permanent" cookie, but you can use any date you like.

Hope this helps!

Cheers,
David.

Submitted by npaitken on Tue, 2008-09-02 19:24

Hi David,

I'll try it out and let you know how I get on.

Many thanks again,
Neil

Submitted by npaitken on Wed, 2008-09-03 15:00

Hi David,

Working through the above to see if I can get it to work.

The affiliate link URLs in the product feed don't actually have "clickref=" in them as default, rather they look like this:

http://www.awin1.com/pclick.php?p=29479359&a=71066&m=1375
where
p=productID
a=affiliateID
m=merchantID

So, I think your code needs to be amended to APPEND &clickref={keyword} on the end of the affiliate link URL, rather than REPLACE "clickref=" with "clickref={keyword}".

Can you let me know what you think the code should be.

Many thanks
Neil

Submitted by support on Wed, 2008-09-03 15:05

Hi Neil,

Assuming that you want to check that it is an Affiliate Window link before adding clickref; instead of:

if ($_COOKIE["keyword"] && strpos($product["buy_url"],"clickref="))
{
  $product["buy_url"] = str_replace("clickref=","clickref=".urlencode($_COOKIE["keyword"]),$product["buy_url"]);
}

use:

if ($_COOKIE["keyword"] && strpos($product["buy_url"],"awin"))
{
  $product["buy_url"] = $product["buy_url"]."&clickref=".urlencode($_COOKIE["keyword"]);
}

If you want to test that all is working, one option would be to print $product["buy_url"] and then exit rather than redirect, so as a test version, something like this would help:

if ($_COOKIE["keyword"] && strpos($product["buy_url"],"awin"))
{
  $product["buy_url"] = $product["buy_url"]."&clickref=".urlencode($_COOKIE["keyword"]);
  print $product["buy_url"];exit();
}

Cheers,
David.

Submitted by npaitken on Wed, 2008-09-03 16:05

Beautiful :-)

Thanks once again David

The print test version worked perfectly. Also, I've just done an end-to-end test (did a test purchase) and the keyword tracked from initial referral URL right through to Affiliate Window commission reporting.

PPC ££millions here we come!!

Many thanks again David.

Submitted by mally on Sun, 2008-09-14 13:40

Hello David

If possible could you explain how to add this variable to the jump buy link..

Instead of looking for the particlular network in the buy string, I've added to the buy link using the search and replace in /admin/ mmm which in in the tracking area.

i.e for affiliate future I replaced &tracking= with &tracking=mmm

So I just need to search for mmm and replace with my tracking ref code.

Could you tell me the best way to replace in jump.php any mmm in the buy link following

<?php
 
echo $ref_id."_";
?>

so basically I want to search header("Location: ".$product["buy_url"]); for any mmm and if its there replace with

<?php
 
echo $ref_id."_";
?>

cheers

Mally

Submitted by support on Mon, 2008-09-15 07:17

Hi Mally,

Sure, if you replace:

  header("Location: ".$product["buy_url"]);

...with:

  str_replace("mmm",$ref_id."_",$product["buy_url"]);
  header("Location: ".$product["buy_url"]);

...that should do the trick!

Cheers,
David.

Submitted by npaitken on Wed, 2008-09-17 19:33

Hi David,

Quick question regarding cookie setting code. I wanted to change the cookie expiry to 30 days so changed your code in products.php from

if ($_GET["keyword"])
{
  $expire = mktime(0,0,0,1,1,2010);
  setcookie("keyword",$_GET["keyword"],$expire,"/");
}

to

  if ($_GET["keyword"])
  {
  setcookie("keyword",$_GET["keyword"], time() + 2592000);
  }

Can you see anything wrong with this new cookie setting code? Based on some testing today, keywords (in Adwords URL string) don't seem to be tracking through to Affiliate Window as 'clickref'. It's probably something else but as I've changed the cookie code just wanted to check ithat first.

Thanks,
Neil

Submitted by support on Wed, 2008-09-17 19:45

Hi Neil,

The time() portion of the modification is fine, but you've missed off the path parameter in your new code; so cookies are only being set in the (virtual) directory in which the user lands! Have a go with:

  if ($_GET["keyword"])
  {
  setcookie("keyword",$_GET["keyword"], time() + 2592000,"/");
  }

Cheers,
David.

Submitted by npaitken on Wed, 2008-09-17 20:09

Hi David,

Just been doing some more testing. Adwords url to my landing page is like this (with .html extension)

http://widgetsite.co.uk/product/red-widget-page.html?keyword=red+widget

I've set up in test mode in jump.php using following code to print exit URL from my site

if ($_COOKIE["keyword"] && strpos($product["buy_url"],"awin"))
{
  $product["buy_url"] = $product["buy_url"]."&clickref=".urlencode($_COOKIE["keyword"]);
}
  print $product["buy_url"];exit();

I've confirmed that I'm arriving on my landing page with URL like this:

http://widgetsite.co.uk/product/red-widget-page.html?keyword=red+widget

BUT when when I click on affiliate link and go to jump.php, the test print gives:

http://www.awin1.com/pclick.php?p=30142919&a=12345&m=813

As you can see exit URL isn't appended with &clickref=red+widget

Any thoughts? Is it because landing page isn't a .php page?

Best regards,
Neil

Submitted by support on Wed, 2008-09-17 20:13

Hi Neil,

It looks fine (assuming that you have added the "/" parameter to the cookie() call) - do you want to email me your products.php and jump.php and i'll check them over for you...

Cheers,
David.

Submitted by npaitken on Wed, 2008-09-17 20:18

Hi Dave,

Sorted :-), "/" parameter has solved the problem.

Many thanks,
Neil

Submitted by npaitken on Thu, 2008-09-25 15:19

Hi David,

Up until now all my merchant feeds were from Affiliate Window. However, I've just added a merchant feed from Webgains and their URLs look like:

http://track.webgains.com/click.html?wgcampaignid=XXXXX&wgprogramid=323&product=1&productname=Titleist+DT%2FPTS+Solo+Refinished++Dozen+Golf+Ball+Pack&wgtarget=http://www.pargolfonline.co.uk/product/Titleist%2520DT%252FPTS%2520Solo%2520Refinished%2520%2520Dozen%2520Golf%2520Ball%2520Pack/Titleist%2520DT%252FPTS%2520Solo%2520Refinished%2520%2520Dozen%2520Golf%2520Ball%2520Pack

Like AWIN, they also use clickref parameter.

How should the code below be changed to accomodate this new feed:

if ($_COOKIE["keyword"] && strpos($product["buy_url"],"awin"))
{
  $product["buy_url"] = $product["buy_url"]."&clickref=".urlencode($_COOKIE["keyword"]);
}

Be good to have code that could accomodate any further feeds from TD, CJ etc that use parameters other than "clickref".

Many thanks,
Neil

Submitted by support on Thu, 2008-09-25 15:24

Hi Neil,

The following should work to check for awin or webgains in the URL:

if ($_COOKIE["keyword"] && (strpos($product["buy_url"],"awin") || strpos($product["buy_url"],"webgains")))
{
  $product["buy_url"] = $product["buy_url"]."&clickref=".urlencode($_COOKIE["keyword"]);
}

Then for other networks; with a different parameter; just copy the block
- changing the test string as required (use something that will always
appear in the particular network's URLs) and then the name of the parameter.

For example, to test for "example" in the URL, and add the parameter "mytracking", use:

if ($_COOKIE["keyword"] && strpos($product["buy_url"],"example"))
{
  $product["buy_url"] = $product["buy_url"]."&mytracking=".urlencode($_COOKIE["keyword"]);
}

Cheers,
David.

Submitted by npaitken on Fri, 2008-12-05 17:26

Hi David,

I'm looking at a tool just now (OptimizeMySite -OMS) that will help me to improve my tracking efforts. It sets a cookie on the visitors PC in between leaving adwords and just before they're refered to my Price Tapestry site.

I had a chat with the owner (of OMS)and he reckons I just need to reference the OMS tracking cookie in my affiliate links to make it work.

He gave me this code as an example to make this work

http://www.affiliatewindowlink.com/?clickref=<?PHP echo $_COOKIE['visitor_id'];?>

What would I now need to change in jump.php & products.php to make this work.

Many thanks if you can help.
Neil

Submitted by support on Sat, 2008-12-06 10:07

Hi Neil,

Several users are doing similar tracking. The method I recommend is to make
sure that any affiliate URLs that can be tracked in this way (for example
the clickref parameter for Affiliate Window) have the parameter added, but
without a value. You can do this using a Text After filter - add a new
Text After filter to the Buy URL field, and enter something like:

&clickref=

You can do a similar thing for different network's feeds that use a different
tracking parameter. Then, in jump.php, look for the following
code on line 14:

header("Location: ".$product["buy_url"]);

...and REPLACE this with:

$product["buy_url"] = str_replace("clickref=","clickref=".$_COOKIE["visitor_id"],$product["buy_url"]);
header("Location: ".$product["buy_url"]);

You can of course add more str_replace() lines for each different type of tracking
variable that exist in your Buy URLs (as added with the filters).

Hope this helps!

Cheers,
David.

Submitted by npaitken on Sun, 2008-12-07 22:09

Hi David,

Thanks for that. I understand your approach. Just one question: Text After Filter is a Price Tapestry feature you can use when you import feeds right? I haven't used that facility yet but remember Reading something when first bought PT.

Thanks,
Neil

Submitted by support on Mon, 2008-12-08 09:08

Hi Neil,

That's correct. To implement this for a particular feed, click "Filters" alongside the
filename on the /admin/ home page, then add a new "Text After" filter to the "Buy URL"
field. On the next page, you can then enter the text you wish to append to the field.
The changes take effect when the feed is next imported.

Cheers,
David.

Submitted by npaitken on Mon, 2008-12-08 16:02

Hi David,

Could do you do me a favour please. I've tried using the approach / code given but it doesn't seem to be picking up the cookie variable ('visitor_ID').

Would it be ok if I sent you more info via email to see if you can spot the problem? I think it must be something really basic I'm doing.

Many thanks,
Neil

Submitted by support on Mon, 2008-12-08 16:17

Hi Neil,

Certainly - use the email address on this page.

I'm assuming that visitor_ID is set by your OMS package... Using Firefox
you can easily check what cookies are being set - go to Edit > Preferences
> Privacy > Show Cookies - then enter your domain in the filter box.

In particular, check that the "Path" property of the visitor_ID cookies is
set to "/" (without the quotes) so that it is sent by the browser for every
page view and not just the original page that created the cookie...

Cheers,
David.

Submitted by npaitken on Tue, 2008-12-09 10:19

Hi David,

I'm getting much closer to solving this! Using Firefox LIVE HTTP HEADERS I can see that the cookie is being set. However, the domain is .co.uk and not the full domain of my site.

From Firefox LIVE HTTP HEADERS:

HTTP/1.x 302 OK
Date: Tue, 09 Dec 2008 09:43:22 GMT
Server: Apache
X-Powered-By: PHP/4.4.9
Set-Cookie: visitor_id=74; expires=Thu, 08 Jan 2009 09:43:23 GMT; path=/; domain=co.uk
Location: http://comparegolfprices.co.uk/shopping/product/Skycaddie-SG5-GPS-Rangefinder.html
Keep-Alive: timeout=2, max=200
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

Any ideas on why this would be set this way and where I might look to fix it. (I'll pursue OMS guy but that might be slow)

If I can't get this sorted out at the OMS end quickly, is it possible to work around this at the Price Tapestry end? Are there pitfalls in doing this?

Thanks,
Neil

Submitted by support on Tue, 2008-12-09 12:09

Hi Neil,

I just did a test and a domain value of "co.uk" on its own does not work.
I then tried .co.uk and that didn't work either (in Firefox) - I couldn't
get the cookie to set until I entered the full domain name.

Perhaps this is configuration variable somewhere in the tracking package
that you are using?

Cheers,
David.

Submitted by npaitken on Tue, 2008-12-09 12:37

Hi David,

Did you go right back to Adwords and do an end-to-end test again? or where you looking for the COOKIE from yesterday?


I just did a test and a domain value of "co.uk" on its own does not work.
I then tried .co.uk and that didn't work either (in Firefox)

What kind of test did you do?


I couldn't get the cookie to set until I entered the full domain name.

Can you explain a bit further what test you were doing..

Neil

Submitted by support on Tue, 2008-12-09 14:14

Hi Neil,

My test was simply this PHP script:

<?php
  setcookie
("visitor_id","1234"time() + 2592000,"/","example.com");
  
print_r($_COOKIE);
?>

The above works; but when using:

  setcookie("visitor_id","1234", time() + 2592000,"/",".com");

...the cookie is not accepted by the browser, so I think (although there
may be more to it) that you need to get your full domain name into the
domain value in the setcookie function.

One option would be to replace $_SERVER["HTTP_HOST"] with your full domain
name (in quotes) - that might do the trick. You can of course see if it's
working with the view headers tool that you have been using...

Cheers,
David.

Submitted by npaitken on Mon, 2009-05-04 11:50

Hi David,

I know this is a wee bit out of your PT scope but hope you can help.

I've now got some ad banners running on partner sites and I'd like to track referral traffic from those sites into my Wordpress/Price Tapestry site and through to merchants clicks/sales.

Using the system I set up to track PPC traffic (which all came in through PT product pages) I'm hoping I can just extend this system a wee bit.

I think all I have to do is this:

1) Add tracking to banner URL - e.g. http://mysite.co.uk/index.php?keyword=site_xyz+ad1

2) As the landing page for refferal traffic is going to now be my homepage (which is Wordpress), add set cookie code in appropriate wordpress file. I think the header file would be best? Just add code below

  if ($_GET["keyword"])
  {
  setcookie("keyword",$_GET["keyword"], time() + 2592000,"/");
  }

3) make cookie expire after 1 year NOT 1 month

not sure what value should be?

Any help pointers would be great.

Thanks,
Neil

Submitted by support on Tue, 2009-05-05 09:07

Hi Neil,

That should do the trick - the constant need for expiry in 1 year is 31536000 (that's the number of seconds in 1 day * 365), so you could use the code

  if ($_GET["keyword"])
  {
    setcookie("keyword",$_GET["keyword"], time() + 31536000,"/");
  }

Cheers,
David.

Submitted by Stew on Tue, 2014-10-14 07:19

Hi David,

Hope all's well, I have been using this thread to construct the code needed to set a cookie from a PPC ad and then pass the clickref through jump.php - its working well for webgains.

The issue I'm getting is with Paidonresults.

Their clickref it seems is in the middle of the URL, for example:
Here is a merchant aff link without a tracking ID (I'm using POR's deeplink creator to generate it):

{link saved}

and here's the URL where if set the tracking id as Testing123:

{link saved}

The code I'm using within jump.php is:

if ($_COOKIE["keyword"] && strpos($product["buy_url"],"paidonresults"))
{
$product["buy_url"] = $product["buy_url"]."/".urlencode($_COOKIE["keyword"]);
}

This appends the tracking keyword to the end of the URL string, which causes the page to fail & not load on the merchant site.

Any ideas of a solution here?

Submitted by support on Tue, 2014-10-14 08:39

Hello Stew,

It looks like the no tracking link case contains /0/product... so all you need to do is swap this out with your tracking ID in place of the "0" - have a go with:

  if ($_COOKIE["keyword"] && strpos($product["buy_url"],"paidonresults"))
  {
    $product["buy_url"] = str_replace("/0/product","/".urlencode($_COOKIE["keyword"])."/product",$product["buy_url"]);
  }

Cheers,
David.
--
PriceTapestry.com