Conduct Web experiments using PHP, Part 1
By Paul Meagher2005-03-16
Demo source code
Listing 9. Source code of demo_2d.php script
<?php
/**
* Script demonstrating how to integrate the VLOG package
* with the SR package to log visitor state transitions,
* visitor accesses, and visitor responses to Web offers.
*/
require_once "config.php";
// 1. Instantiate VisitorLog class and start timer.
require_once PHPMATH . "/VLOG/VisitorLog.php";
$vlog = new VisitorLog;
$vlog->setStartTime();
// 2. Instantiate TransitionMatrix class before calling start method.
require_once PHPMATH . "/VLOG/TransitionMatrix.php";
$tm = new TransitionMatrix();
// 3. Start method sets an identity cookie (such as, $_COOKIE['vis_id') and
// updates the TransitionMatrix object. $SITE_STATES is defined in the
// config.php file and corresponds to the name of each page in the demo site.
$vlog->start($SITE_STATES);
// 4. Instantiate StimulusResponse2D class for two factor experiments.
require_once PHPMATH . "/SR/StimulusResponse2D.php";
$sr = new StimulusResponse2D;
// 5. Set the stimulus-response table you will use.
$sr->setTable("WebOffer");
// 6. Set stimulus factors and levels.
$factors["image"] = array("person", "product");
$factors["text"] = array("short", "long");
$sr->setFactors($factors);
// 7. Log any responses to the $response_field.
$response_field = "joined";
$sr->logResponse($_COOKIE['vis_id'], $response_field, $_GET['response']);
// 8. If stimulus code is not already generated for visitor then get one.
if (!$sr->generated) {
$sr->getRandomStimulusCode($_COOKIE['vis_id']);
}
// 9. Use stimulus codes to control Web offer presentation.
$demo_offer = "<img src='".$sr->code["image"]."_". $sr->code["text"].".gif'>";
// 10. Give the demo site a title, then load it.
$demo_title = "Two Factor Web Offer Demo";
require_once "demo_site.php";
// 11. Log visitor accesses using the end method.
$vlog->end();
?>
The value of a visitor tracking cookie (such as, $_COOKIE['vis_id']) is
set in the $vlog->start() method and passed into the $sr->logResponse()
method. The last part of the script sets the $demo_title and $demo_offer
values that are used in the demo_site.php script that is included. The
last line of the script ($vlog->end()) indicates where many visitor-logging
details are recorded.
Tutorial pages:
|
First published by IBM developerWorks
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "Conduct Web experiments using PHP, Part 1"
You must be logged in to post a comment.
Link to This Tutorial Page!

