|
PHP Example Step 1. Open the result page source code and populate variables Let's assume you offer your visitors a computer monitor "LG" worth $999.99. When a visitor clicks the 'order now' link, some PHP page is called, e.g. "thank_you.php". This page contains the server-side script that handles the transaction and displays a thank-you message.
Here's a sample code that your "thank_you.php" might contain: <?php //(Here goes your code to handle the transaction | Let's make PHP store the name and the content group of the page displayed. This is how the visit to this page will be later seen in the HitLens reports. $pagename = "LG monitor thank-you-page"; $contentgroup = "TFT Monitors"; | Now let's make PHP store the transaction details. By transaction we mean any act that can be accomplished by your site visitors and requires dynamic processing: an order, a subscription, a download or a sign-up all are transactions. Your processing system probably assigns a certain number to each order / transaction. You can pass this number to the HitLens script. Each transaction ID must be unique. For instance, you may use the Auto number / Auto increment field value supported by most databases. In other words, it's a unique order number generated by your shopping cart software or database. If not applicable, you may put 0 (zero). | $transaction_id = mysql_insert_id(); // or $transaction_id = 0; | Note that this code is just a sample and in real life you might want to use completely different sources of this number. Now we capture the order details into PHP variables. HitLens is able to track 4 parameters for each order: product name, category, quantity and order amount. If a certain parameter is not applicable or unavailable, replace it with a hyphen or simply leave it blank, e.g. $order_category = ""; $order_product = "LG monitor"; $order_category = "TFT Monitors"; | In the variable 'quantity' you can pass numeric values as well as strings: $order_quantity = 1; // or: $order_quantity = "1 piece"; $order_amount = 999.99; | Let's organize the order details into one single variable | $order_details = "$order_product, $order_category, $order_quantity, $order_amount"; | Note: if your page serves several orders, you may pass them all in one variable, separating different orders with a semicolon: $order_details = " $order_product1, $order_category1, $order_quantity1, $order_amount1; $order_product2, $order_category2, $order_quantity2, $order_amount2 "; | Do not change the order of parameters. The amount may not exceed one billion (the max amount is 999999999.99) and should not be delimited by commas (only dots). Do not pass currency signs ($, Ђ) in the amount parameter. So now the PHP variable "$order_details" contains the following string: "LG Monitor, TFT Monitors, 1, 999.99" That's all we needed to do on the server side for tracking. Here's the complete code: <?php $pagename = "LG monitor thank-you-page"; $contentgroup = "TFT Monitors"; $transaction = "sales"; $transaction_id = mysql_insert_id(); $order_product = "LG monitor"; $order_category = "TFT Monitors"; $order_quantity = 1; $order_amount = 999,99; $order_details = "$order_product, $order_category, $order_quantity, $order_amount"; ?> | Step 2. Insert the tracking code The PHP script from the previous step is executed on the server when your visitor initiates an action on your site. The hosting server then sends the result to the visitor. If you want to implement HitLens tracking, you also need to the make server send the tracking code to the visitor. This code will be executed in his / her browser and report the visit details to the Seo Software's Database. For correct reporting, this tracking script must be populated with our variables we have just created, before being sent to the visitor. So we paste the HitLens tracking script into our PHP page after the PHP code itself, however, we use several fragments of PHP code in the HitLens tracking script in order to pass the information collected to the variables of the HitLens script. After the closing marker of the PHP code "?>" goes the beginning of the tracking code: <!--WEBSITE:BEGIN:{764EEF2E-BC11-45CF-8627-300CE1BA2219}--> <!-- Do NOT modify this script to avoid traffic misrepresentation! Web 4 0300/1 Code initially inserted into: “thank_you.php". --> <script type="text/javascript"><!-- // hitlens v1.2.7 function hitlens_embedded() { | Then, we pass the site ID and page ID (pc) to the script. The site ID can be found in Project Manager against the given Web site and under the HitLens column, for example, 123456. The pc variable should be 0 (zero), if you use specialized tracking instead of standard Wizard-driven setup (this is our case). var id = 123456; var pc = 0; | The PAGENAME variable stores the user-friendly name under which this page will appear in the HitLens reports. Earlier we have initialized the PHP variable $pagename with the value "LG monitor thank-you-page". Now we make PHP pass this value to HitLens: | var PAGENAME = escape(' <?php echo $pagename; ?> '); | As a result, after the PHP page is executed, the visitor's browser receives the following: | var PAGENAME = escape('LG monitor thank-you-page'); | Now HitLens knows that the visitor has opened the page "LG monitor thank-you-page" and will report it to the Datacenter. The same happens to the content group. Earlier we have assigned the value " TFT Monitors" to the variable $contentgroup. Now we pass it to the HitLens script. | var CONTENTGROUP = escape(' <?php echo $contentgroup; ?> '); | The variable "TRANSACTION" stores the type of the transaction: it may be sales, trials, subscriptions, downloads, or anything you like: | var TRANSACTION = escape(' <?php echo $transaction; ?> '); | In our case it will be "Orders", because earlier we have assigned such value to $transaction. The same happens to transaction ID and order: var TRANSACTION_ID = escape(' <?php echo $transaction_id; ?> '); var ORDER = escape(' <?php echo $order_details; ?> '); | As you remember, the variable "order_details" lets HitLens know the order details: "LG Monitor, TFT Monitors, 1, 999.99" After that, you may safely insert the ending of the HitLens tracking code: return "id="+id+"&pc="+pc+"&p="+PAGENAME+"&gr="+CONTENTGROUP+"&tr="+TRANSACTION+"&trid= "+TRANSACTION_ID+"&ord="+ORDER; } //--></script> <script type="text/javascript" src="/tracking.js"></script> <!--WEBSITE:END:{764EEF2E-BC11-45CF-8627-300CE1BA2219}--> | So here's the entire sample tracking script: <!--WEBSITE:BEGIN:{764EEF2E-BC11-45CF-8627-300CE1BA2219}--> <!-- Do NOT modify this script to avoid traffic misrepresentation! Web 4 0300/1 Code initially inserted into: “thank_you.php". --> <script type="text/javascript"><!-- // hitlens v1.2.7 function hitlens_embedded() { var id = 123456; var pc = 0; var PAGENAME = escape(' <?php echo $pagename; ?> '); var CONTENTGROUP = escape(' <?php echo $contentgroup; ?> '); var TRANSACTION = escape(' <?php echo $transaction; ?> '); var TRANSACTION_ID = escape(' <?php echo $transaction_id; ?> '); var ORDER = escape(' <?php echo $order_details; ?> '); return "id="+id+"&pc="+pc+"&p="+PAGENAME+"&gr="+CONTENTGROUP+"&tr="+TRANSACTION+"&trid= "+TRANSACTION_ID+"&ord="+ORDER; } //--></script> <script type="text/javascript" src="/tracking.js"></script> <!--WEBSITE:END:{764EEF2E-BC11-45CF-8627-300CE1BA2219}--> |
|