Thursday, January 15, 2015

How to Implement SiteCatalyst on Server side using PHP?



This is an adhoc post I am writing on SiteCatalyst implementation, I will write a detailed series on SiteCatalyst implementation soon. Most of the Web Analytics implementation that's been done on the web is using JavaScript but there might be situations where you will not have that luxury to implement an Analytics tool using JavaScript instead you need to use a Server side approach to do that.

implement-site-catalyst-server-side




So, what is the difference between a client side and server side approach in implementation?


Client side approach is where the Analytics tool library will load on the web browser of the user viewing the website from the JavaScript library. Once the library is loaded on the browser it does series of actions, constructs an image pixel which contains all the required data that needs to be sent to the Analytics server. Finally the pixel will be sent using a HTTP request.

Server side approach is where the Analytics library will be loaded on the server side. All the data related to the user is passed using the Server side language's Global variables and the image request is constructed by the Analytics library. Once the image request is constructed it can be sent to the Analytics Server in two ways. One from the server side without the user's notice. In this method your HTTP Packet sniffers will not be able to pick up all these image requests. Second method is to send it from the client browser. In this method your HTTP Packet sniffers can read the image pixel.

How do you implement SiteCatalyst on Server side (PHP being your language for development) ?


Step 1:

Login to your SiteCatalyst console. Click on the Pancake menu on the top left which opens up your navigation menu. You should see an item called "Admin Tools". Clicking on that should open one more child menu. Click on "Code Manager".

Step 2:

On the right hand side you should see different libraries of SiteCatalyst for different platforms. We are interested in PHP library. Go ahead and click on PHP. A zip file will be downloaded. Extract the contents of the file and copy the "AppMeasurement.php" to your server root directory or the convenient directory of your choice.

Step 3:

Go to the source code of the page you want to implement SiteCatalyst on. Or if you have a common file which can be included in all the pages of your website choose that file and open it in your favorite Text editor.

Step 4:

First step is to load the Library we have just downloaded which can be done using simple require_once command of PHP as below

require_once('AppMeasurement.php');

This basically loads the AppMeasurement Class into your file.

Step 5:

Now that you have referenced the class, your next step is to instantiate a local object using AppMeasurement class which can be done as below.

$s = new AppMeasurement();

Step 6:

Next step is to configure your s object which is your $s variable so that proper data is collected. Let's say we are tracking pagename, a prop and an eVar collecting the Site section of the present page. This is done as shown below

$s->pageName = "Test Home Page";
$s->prop1 = "Home Section";
$s->eVar1 = "Home Section";

You can configure whatever variables you want to like channel, server, events, hierarchy and other standard variables.

Step 7:

Now that you have collected all your data into the local $s object, it's time to tell the $s object where the data needs to be sent. This is called your Tracking Server, you can get this information from your client care. This will look like "yourcompanyname.112.2o7.net" or if you have implemented first party cookies "metrics.yourcompanyname.com". You need to pass this information as shown below.

$s->trackingServer = "yourcompanyname.112.2o7.net";

Step 8:

There are some more important configuration steps you need to do before you send an image request. You can specify the image request dimensions as below.

$s->imageDimensions = "5x5";

I have specified 5x5 above because the most probable case where you might want to implement Sitecatalyst on server side is keeping in mind about the mobile devices. SiteCatalyst prescribes the image request should be of 5x5 if it is from a mobile device.

Also, you need to specify whether you want to send the data from server side or from the client browser. You can do that using the below line.

$s->sendFromServer = true;

If you set the above variable to false, you can see an image request on your browser's packet sniffer. Since I have set it to true, in this case I can set one more variable which might be useful to debug the tracking. I would suggest you keep it as false in your code for convenience.

$s->debugTracking = true;

Step 9:

Once you have performed all the above steps, you can make the image request using the below line of code.

$s->track();

If you are familiar with JavaScript implementation, this above line does the same thing as your s.t() call.

On the whole your page code looks like this

require_once('AppMeasurement.php');
$s = new AppMeasurement();
$s->pageName = "Test Home Page";
$s->prop1 = "Home Section";
$s->eVar1 = "Home Section";
$s->trackingServer = "yourcompanyname.112.2o7.net";
$s->imageDimensions = "5x5";
$s->sendFromServer = false;
$s->debugTracking = false;
$s->track();
I hope you understood the process. Do feel free to post your questions in the comments section.


1 comment :