You are here:  » Tracking Adwords GCLID Parameter


Tracking Adwords GCLID Parameter

Submitted by paddyman on Wed, 2015-08-12 19:56 in

Hi David,

Hope all is well with you.

Just came across this article and wondering if it would be possible to track the google gclid parameter in jump.php?

{link saved}

In the article he has

{code saved}

Currently I am tracking the Product Name, where I can see which product link resulted in a sale.

<?php
  
require("includes/common.php");
   
$sql "SELECT filename,buy_url,name FROM `".$config_databaseTablePrefix."products` WHERE dupe_hash='".database_safe($_GET["id"])."'";
  
database_querySelect($sql,$rows);
  
$product $rows[0];
  
$sql "UPDATE `".$config_databaseTablePrefix."feeds` SET clicks=clicks+1 WHERE filename = '".$product["filename"]."'";
  
database_queryModify($sql,$insertID);
  
$trackings = array("LID","clickref","EPI","sid");
  foreach(
$trackings as $tracking)
  {
  
$product["buy_url"] = str_replace(
    
"&".$tracking."=",
    
"&".$tracking."=".urlencode($product["name"]),
    
$product["buy_url"]);
  
$product["buy_url"] = str_replace(
    
"?".$tracking."=",
    
"?".$tracking."=".urlencode($product["name"]),
    
$product["buy_url"]);
  }
  
header("Location: ".$product["buy_url"]);
  exit();
?>

Anyway of passing gclid info instead of product name?

Cheers

Adrian

Submitted by support on Thu, 2015-08-13 08:28

Hi Adrian,

Sure - the first step would be to somehow persist the incoming gclid (which I assume will be to a product page) through to jump.php.

One way would be to set a cookie, using this at the top of products.php:

  if (isset($_GET["gclid"]))
  {
    setcookie("gclid",$_GET["gclid"],strtotime("+90 days"),"/");
  }

And then in jump.php, just before your foreach() loop that swaps out the tracking parameters by product name, you could use:

  if (isset($_COOKIE["gclid"]))
  {
    $product["name"] = $_COOKIE["gclid"];
  }

If you didn't want to use cookies, then you could pass through gclid in the Buy URL link. To do this, edit includes/tapestry.php and look for the following code around line 98:

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

...and REPLACE with:

  $retval = $config_baseHREF."jump.php?id=".$product["id"];
  if (isset($_GET["gclid"]))
  {
    $retval .= "&gclid=".$_GET["gclid"];
  }
  return $retval;

And in jump.php

  if (isset($_GET["gclid"]))
  {
    $product["name"] = $_GET["gclid"];
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by paddyman on Thu, 2015-08-13 19:09

Hi David,

Many thanks for your reply. I tried the second option above for the buy url link and get the following error

Parse error: syntax error, unexpected T_VARIABLE in /home/....../includes/tapestry.php on line 101.

Line 101 is $retval $config_baseHREF."jump.php?id=".$product["id"]; from the code below.

function tapestry_buyURL($product)
  {
    global $config_baseHREF;
    global $config_useTracking;
    if ($config_useTracking)
    {
      $retval $config_baseHREF."jump.php?id=".$product["id"];
      if (isset($_GET["gclid"]))
      {
        $retval .= "&gclid=".$_GET["gclid"];
      }
      return $retval;
    }
    else
    {
      return $product["buy_url"];
    }
  }

Any ideas?

Cheers

Adrian

Submitted by support on Thu, 2015-08-13 19:12

Sorry Adrian - the "=" was missing from this line:

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

(corrected above)

Cheers,
David.
--
PriceTapestry.com

Submitted by paddyman on Thu, 2015-08-13 19:21

Thanks David,

Should have spotted that myself !!!!

Cheers

Adrian

Submitted by paddyman on Sat, 2015-08-15 14:15

Hi David,

Just wondering if this only works for the second buy url option (non-cookie) when someone lands on a product page. Presume only way to get this working for a non product page is the cookie option?

Thanks

Adrian

Submitted by support on Sat, 2015-08-15 14:44

Hi Adrian,

That's correct, but then you would also need to move the cookie setting to a more generic location so that you can have non-product pages as your AdWords campaign landing pages.

No problem - instead of inserting the cookie setting code at the top of html/products.php place it at the very top of html/header.php - that way you can use any page on your site as the landing page of an AdWords campaign, the gclid cookie will be set, and used by jump.php whatever route your visitor subsequently takes throughout your site - even if they come back later (example code sets a 90 day cookie)...

Cheers,
David.
--
PriceTapestry.com

Submitted by paddyman on Sat, 2015-08-15 14:57

Excellent, makes sense!!

Many thanks

Adrian

Submitted by paddyman on Sun, 2015-08-16 14:35

Hi David,

One more thing on this. Anything else I need to do to get this working with wordpress and the PT Plug in?

Thanks

Adrian

Submitted by support on Mon, 2015-08-17 06:55

Hi Adrian,

If you put the cookie setting code at the very top of the plugin file pto/pto.php then you can use any page on your WordPress site as the landing page, the cookie should be set as expected and picked up by /pt/jump.php just as above...

Cheers,
David.
--
PriceTapestry.com

Submitted by paddyman on Mon, 2015-08-17 07:41

Many thanks David