You are here:  » Incorporating Google's event tracking


Incorporating Google's event tracking

Submitted by Panos on Thu, 2016-07-28 16:09 in

Hello David,
I'm currently putting all my effort to set up the Google event tracking via a server side implementation cause i don't want to rely on clients wish to use JS or not.

Straight to the point. I found some useful code snippets to do that:
{code saved}

Both solutions work by requiring the necessary class and then fire/send the event in google analytics.
I attempted re-write the jump.php like this but it doesn't forward the visitor to products buy_url nor the event is tracked.

{code saved}

Ideally i would like to pass as the event Category the variable $product["merchant"] and as event Label the variable $product["original_name"]. Could you please point me to the right direction? Do you propose a different approach?

Thank you
Panos

Submitted by support on Fri, 2016-07-29 08:01

Hello Panos,

There was a syntax error in your modifications to jump.php that you posted - this line;

  $ssga->send()

...is missing the semi-colon.

You might still however wish to use this following the database query (as you had commented out), but changing the SELECT list of just filename,buy_url to * (all fields) so that you can pass product details through to the tracking, e.g.

<?php
  
require("includes/common.php");
  include(
"includes/ss-ga.class.php");
  
$sql "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE id='".database_safe($_GET["id"])."'";
  if (
database_querySelect($sql,$rows))
  {
    
$product $rows[0];
    
$ssga = new ssga'UA-MY-GA-ID-1''mydomain.xx' );
    
$ssga->set_event'Event''Categories''Label''Value');
    
$ssga->send();
    
$sql "UPDATE `".$config_databaseTablePrefix."feeds` SET clicks=clicks+1 WHERE filename = '".database_safe($product["filename"])."'";
    
database_queryModify($sql,$insertID);
    
header("Location: ".$product["buy_url"]);
  }
  exit();
?>

With the tracking code in this position, you could then use $product["category"] etc.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Panos on Tue, 2016-08-02 16:09

Hello David,
that did the trick ! Clicks are now being tracked as GA events, thanks so much !!

BR
Panos