You are here:  » Tracking clicks on merchant links in Google Analytics


Tracking clicks on merchant links in Google Analytics

Submitted by paddyman on Mon, 2009-05-18 16:15 in

Hi David,

Came across this article "How do I manually track clicks on outbound links?" http://adwords.google.com/support/bin/answer.py?answer=55527&cbid=-1h7aavbt2trys&src=cb&lev=answer and am wondering would it be possible to implement this into pricetapestry ? Not too sure if there is much involved.

Thanks

Adrian

Submitted by support on Mon, 2009-05-18 17:50

Hi Adrian,

That should be straight forward to implement, most easily as a "hack" into the function that generates a Buy URL throughout the site. This can be done by returning a string that returns the Buy URL, a closing apostrophe, and then the Google Analytics JavaScript WITHOUT the closing apostrophe...

In includes/tapestry.php look for the following function;

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

...and REPLACE this with:

  function tapestry_buyURL($product)
  {
    global $config_baseHREF;
    global $config_useTracking;
    if ($config_useTracking)
    {
      $href = $config_baseHREF."jump.php?id=".$product["id"];
    }
    else
    {
      $href = $product["buy_url"];
    }
    $href .= "' onClick='javascript: pageTracker._trackPageview(\"/outgoing/".$product["merchant"]."\");";
    return $href;
  }

That would give you a "virtual" directory structure as Google recommends of /outgoing/Merchant Name

Cheers,
David.

Submitted by paddyman on Tue, 2009-05-19 11:17

Excellent, great addition.

Many thanks :)

ADrian

Submitted by Andrewc on Thu, 2009-06-04 04:42

Hi Adrian

How do you find the click tracking that Google provides?

Could one use this for billing Merchants on a Per Click basis?

Thanks
Andrew

Submitted by npaitken on Wed, 2011-01-05 18:13

Hi David,

Happy New Year to you :-)

I was reading a really good article today about Google Analytics and it reminded me that I should really setup outbound clicks as goals!

I noticed there was another thread on implementing Google Analytics using jump.php but this seems like a much more simple setup.

Is it possible to track Goals using what you've outlined above?

Thanks
Neil

Submitted by JustJ on Tue, 2011-03-29 14:09

Just set this up (with a lot of help from David) using the event tracking in GA and thought I'd share my finished solution.

First of all I placed the following in the head section(as suggested here http://www.google.com/support/analytics/bin/answer.py?answer=55527 ):

<script type="text/javascript">
  function recordOutboundLink(link, category, action, label) {
    _gat._getTrackerByName()._trackEvent(category, action, label);
    setTimeout('document.location = "' + link.href + '"', 100);
  }
</script>

I added the "label" part so that it would track the additional data.

Then I replaced the buy_url code in tapestry.php with this:

  function tapestry_buyURL($product)
  {
    global $config_baseHREF;
    global $config_useTracking;
    if ($config_useTracking)
    {
      $href = $config_baseHREF."jump.php?id=".$product["id"];
    }
    else
    {
      $href = $product["buy_url"];
    }
    $href .= "' onClick=\"recordOutboundLink(this, 'Outgoing', '".urlencode($product["merchant"])."', '".urlencode($product["name"])."');return false;\"";
    return $href;
  }

and it seems to be working a treat.

Submitted by sirmanu on Thu, 2016-09-29 18:27

I am trying to implement this code with the new version of GA(*), but with target=_blank.
However, I think it might be missing a comma because is not working as expected.

In tapestry_buyURL I have the following code:

$retval .= "' target='_BLANK";
$retval .= "' onclick=\"trackOutboundLink('".urlencode($product["buy_url"])."'); return false;\"";
return $retval;

(*)
https://support.google.com/analytics/answer/1136920?hl=en

Submitted by support on Fri, 2016-09-30 08:55

Hi,

The onclick would need to go before the target (with intentionally missing closing single-quote) - have a go with:

$retval .= "' onclick=\"trackOutboundLink('".urlencode($product["buy_url"])."'); return false;\"";
$retval .= "' target='_BLANK";
return $retval;

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Fri, 2016-09-30 11:07

I get something like that

<a class="button tiny radius success" href="/jump.php?id=327527" onclick="trackOutboundLink('http://[...].html'); return false;" '="" target="_BLANK">Buy</a>

What is that '=""?

Submitted by support on Fri, 2016-09-30 11:22

Hi,

What's happening is your template is using double-quoted attributes rather than single quotes, so this just needs to be mirrored in the code - have a go with;

  $retval = $config_baseHREF."jump.php?id=".$product["id"];
  $retval .= "\" onclick=\" trackOutboundLink('".urlencode($product["buy_url"])."');return false;\"";
  $retval .= " target=\"_BLANK";

Cheers,
David.
--
PriceTapestry.com