You are here:  » Append extra URL parameters in buy URL


Append extra URL parameters in buy URL

Submitted by jamie on Tue, 2016-09-06 09:36 in

Hi David,

Is there a way to append extra URL parameters into the buy URLs?

The traffic coming into my PT site contains two extra parameters...

http://www.example.com/product.php?q=productname&clickref=example1&clickref2=example2

The jump.php file redirects the user to the merchant site, but ideally I would like a way to append "clickref=example1&clickref2=example2" to that buy URL.

Please could I ask how to achieve this?

As always many thanks for your help,
Jamie

Submitted by support on Tue, 2016-09-06 10:09

Hello Jamie,

You could pass clickref and clickref2 through to jump.php as follows - edit includes/tapestry.php and look for the following code at line 98:

  return $config_baseHREF."jump.php?id=".$product["id"];

...and REPLACE with:

  $jump_url = $config_baseHREF."jump.php?id=".$product["id"];
  if (isset($_GET["clickref"])) $jump_url .= "&clickref=".urlencode($_GET["clickref"]);
  if (isset($_GET["clickref2"])) $jump_url .= "&clickref2=".urlencode($_GET["clickref2"]);
  return $jump_url;

And then edit jump.php and look for the following code at line 14:

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

...and REPLACE with:

  if (isset($_GET["clickref"])) $product["buy_url"] .= "&clickref=".urlencode($_GET["clickref"]);
  if (isset($_GET["clickref2"])) $product["buy_url"] .= "&clickref2=".urlencode($_GET["clickref2"]);
  print $product["buy_url"];exit();
  header("Location: ".$product["buy_url"]);

I would then do a test at this point just to double check that changes are all OK, so in the modified file where you now have:

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

...REPLACE with;

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

Visit your site with the clickref / clickref2 parameters and click a Visit Store link, and the modified buy_url will be displayed without making the redirection. Copy the URL and paste into the address bar of your browser to confirm that all working as expected, and then remove the line;

  print $product["buy_url"];exit();

...to restore normal functionality (and I would suggest a final test as well at this point!)

Cheers,
David.
--
PriceTapestry.com

Submitted by jamie on Tue, 2016-09-06 10:47

Works like a charm, thanks David.

The only slight issue is that those extra URL parameters do not propagate the other links. So for instance, if a user lands on product X with the extra URL parameters, and then clicks a related product Y at the bottom of the page, or goes elsewhere in the site (via searching, or click a merchant/category etc), I lose those parameters.

Its quite important that I try to keep those intact, because they contain information about where my traffic has come from, so is highly useful for me to determine where to allocate resources that yield the most conversions.

Is there a way to make those URL parameters constant though out the site please?

Thanks
Jamie

Submitted by support on Tue, 2016-09-06 11:20

Hi Jamie,

You could put the values into cookies, and then have jump.php check for the cookies and append to the buy_url.

To do this, as an alternative to all the above, edit products.php and look for the following code at line 6:

  $rewrite = isset($_GET["rewrite"]);

...and REPLACE with:

  if (isset($_GET["clickref"])) setcookie("clickref",$_GET["clickref"],0,"/");
  if (isset($_GET["clickref2"])) setcookie("clickref2",$_GET["clickref2"],0,"/");
  $rewrite = isset($_GET["rewrite"]);

And then in jump.php and look for the following code at line 14:

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

...and REPLACE with:

  if (isset($_COOKIE["clickref"])) $product["buy_url"] .= "&clickref=".urlencode($_COOKIE["clickref"]);
  if (isset($_COOKIE["clickref2"])) $product["buy_url"] .= "&clickref2=".urlencode($_COOKIE["clickref2"]);
  print $product["buy_url"];exit();
  header("Location: ".$product["buy_url"]);

The above includes the test code as before, so once you've checked the cookies are propagating and the buy_url being modified as expected, where you have:

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

...and REPLACE with:

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

The value 0 (zero) in the calls to setcookie() is the expire time. A value of 0 will expire at the end of the browser session but you could increase this if you wanted to track clicks over a longer period. The "+" notation supported by PHP's strtotime() function is handy for cookies, for example for 90 days you could use;

  if (isset($_GET["clickref"])) setcookie("clickref",$_GET["clickref"],strtotime("+90 days"),"/");
  if (isset($_GET["clickref2"])) setcookie("clickref2",$_GET["clickref2"],strtotime("+90 days"),"/");

Cheers,
David.
--
PriceTapestry.com

Submitted by jamie on Tue, 2016-09-06 15:05

Perfect - once again thank you very much for your help David!