Skip to content
Permalink
Browse files

adding support for priorVisitsCount dimension at the request and visi…

…t and visitor levels.

added support for daysSinseFirstVisit dimension
added support for daysSinsePriorVisit dimension
  • Loading branch information
padams
padams committed Jul 9, 2010
1 parent 333d456 commit dead5b4d21d9df936e3808a9d71f5d8954d55ff7
@@ -69,17 +69,17 @@ class ini_db extends owa_base {
* @access public
* @return ini_db
*/
function ini_db($ini_file, $sections = null, $return_format = 'object') {
$this->owa_base();
function __construct($ini_file, $sections = null, $return_format = 'object') {

parent::__construct();
$this->ini_file = $ini_file;
$this->return_format = $return_format;

if (!empty($sections)):
if (!empty($sections)){
$this->db = $this->readINIfile($this->ini_file, ';');
else:
} else {
$this->db = file($this->ini_file);
endif;
return;
}
}

/**
@@ -200,37 +200,37 @@ function fetch_replace($haystack) {
* @return array
*/
function readINIfile ($filename, $commentchar) {
$array1 = file($filename);
$section = '';
foreach ($array1 as $filedata) {
$dataline = trim($filedata);
$firstchar = substr($dataline, 0, 1);
if ($firstchar!=$commentchar && $dataline!='') {
//It's an entry (not a comment and not a blank line)
if ($firstchar == '[' && substr($dataline, -1, 1) == ']') {
//It's a section
$section = strtolower(substr($dataline, 1, -1));
}else{
//It's a key...
$delimiter = strpos($dataline, '=');
if ($delimiter > 0) {
//...with a value
$key = strtolower(trim(substr($dataline, 0, $delimiter)));
$value = trim(substr($dataline, $delimiter + 1));
if (substr($value, 1, 1) == '"' && substr($value, -1, 1) == '"') { $value = substr($value, 1, -1); }
$array2[$section][$key] = stripcslashes($value);
}else{
//...without a value
$array2[$section][strtolower(trim($dataline))]='';
}
}
}else{
$array1 = file($filename);
$section = '';
foreach ($array1 as $filedata) {
$dataline = trim($filedata);
$firstchar = substr($dataline, 0, 1);
if ($firstchar!=$commentchar && $dataline!='') {
//It's an entry (not a comment and not a blank line)
if ($firstchar == '[' && substr($dataline, -1, 1) == ']') {
//It's a section
$section = strtolower(substr($dataline, 1, -1));
} else {
//It's a key...
$delimiter = strpos($dataline, '=');
if ($delimiter > 0) {
//...with a value
$key = strtolower(trim(substr($dataline, 0, $delimiter)));
$value = trim(substr($dataline, $delimiter + 1));
if (substr($value, 1, 1) == '"' && substr($value, -1, 1) == '"') { $value = substr($value, 1, -1); }
$array2[$section][$key] = stripcslashes($value);
} else {
//...without a value
$array2[$section][strtolower(trim($dataline))]='';
}
}
} else {
//It's a comment or blank line. Ignore.
}
}
return $array2;
}
}

return $array2;
}

}

?>
@@ -87,15 +87,11 @@ function set($date, $format = 'yyyymmdd') {
$this->num_days_in_month = date('t', $this->timestamp);
$this->label = date('m/d/Y', $this->timestamp);
$this->label_formal = date('F jS Y', $this->timestamp);

return;

}

function get($name){

return $this->$name;

}

function getDay() {
@@ -156,16 +156,14 @@ function timeSinceLastRequest() {
*/
function setProperties($properties = null) {

if(!empty($properties)):
if(!empty($properties)) {

foreach ($properties as $key => $value) {
if (!empty($value)):
$this->properties[$key] = $value;
endif;

if (empty($this->properties)) {
$this->properties = $properties;
} else {
$this->properties = array_merge($properties, $this->properties);
}

endif;
}
}

function replaceProperties($properties) {
@@ -93,13 +93,18 @@ function setState($store, $name = '', $value, $store_type = '', $is_perminent =
// set values
if (empty($name)) {
$this->stores[$store] = $value;
//owa_coreAPI::debug(print_r($this->stores, true));
} else {
$this->stores[$store][$name] = $value;
//just in case the store was set first as a string instead of as an array.
if (array_key_exists($store, $this->stores) && !is_array($this->stores[$store])) {
$this->stores[$store] = array($name => $value);
} else {
$this->stores[$store][$name] = $value;
}

}

$this->dirty_stores[] = $store;

return;
}


@@ -45,28 +45,14 @@ function __construct() {

$this->startDate = owa_coreAPI::supportClassFactory('base', 'date');
$this->endDate = owa_coreAPI::supportClassFactory('base', 'date');


return;
}

function owa_timePeriod() {

return owa_timePeriod::__construct();
}

function set($value, $map = array()) {
function set($value = '', $map = array()) {

$this->period = $value;

$this->_setDates($map);

$this->_setLabel($value);

$this->_setDifferences();

return;

}

function getStartDate() {
@@ -99,8 +85,6 @@ function _setLabel($value) {
$periods = $this->getPeriodLabels();
$this->label = $periods[$value]['label'];
}

return;
}

/**
@@ -256,8 +240,6 @@ function _setDates($map = array()) {

$this->startDate->set($start, 'timestamp');
$this->endDate->set($end, 'timestamp');

return;
}

function getPeriodProperties() {
@@ -302,11 +284,7 @@ function _setDifferences() {

$this->diff_years = $diff['YearsSinse'];
$this->diff_months = $diff['MonthsSinse'];
$this->diff_days = $diff['DaysSinse'];

return;


$this->diff_days = $diff['DaysSinse'];
}

function getMonthsDifference() {
@@ -404,14 +382,12 @@ function getDateDifference($StartDateString=NULL, $EndDateString=NULL) {
if (($m>0||$y>0) && $d>0) $diff2 .= ", ";
if ($d>0) $diff2 .= $d==1 ? "Days: 1" : "Days: $d";

}
}

$ReturnArray['NiceString'] = $diff;
$ReturnArray['NiceString2'] = $diff2;
return $ReturnArray;
}

}
}



?>
@@ -132,6 +132,9 @@ function __construct() {
$document_id->setForeignKey('base.document');
$this->setProperty($prior_document_id);

$nps = new owa_dbColumn('num_prior_sessions', OWA_DTD_INT);
$this->setProperty($nps);

$this->properties['is_new_visitor'] = new owa_dbColumn;
$this->properties['is_new_visitor']->setDataType(OWA_DTD_TINYINT);
$this->properties['is_repeat_visitor'] = new owa_dbColumn;
@@ -113,6 +113,10 @@ function __construct() {
$this->properties['prior_session_hour']->setDataType(OWA_DTD_TINYINT2);
$this->properties['prior_session_minute'] = new owa_dbColumn;
$this->properties['prior_session_minute']->setDataType(OWA_DTD_TINYINT2);
$this->properties['days_sinse_prior_session'] = new owa_dbColumn;
$this->properties['days_sinse_prior_session']->setDataType(OWA_DTD_INT);
$this->properties['days_sinse_first_session'] = new owa_dbColumn;
$this->properties['days_sinse_first_session']->setDataType(OWA_DTD_INT);
$this->properties['os'] = new owa_dbColumn;
$this->properties['os']->setDataType(OWA_DTD_VARCHAR255);

@@ -166,6 +170,9 @@ function __construct() {
$site_id->setForeignKey('base.site', 'site_id');
$this->setProperty($site_id);

$nps = new owa_dbColumn('num_prior_sessions', OWA_DTD_INT);
$this->setProperty($nps);

$this->properties['is_robot'] = new owa_dbColumn;
$this->properties['is_robot']->setDataType(OWA_DTD_TINYINT);
$this->properties['is_browser'] = new owa_dbColumn;
@@ -69,6 +69,9 @@ function notify($event) {
// Generate Host id
$r->set('host_id', owa_lib::setStringGuid($event->get('full_host')));

// Generate Host id
$r->set('num_prior_sessions', $event->get('num_prior_sessions'));

$result = $r->create();


@@ -81,6 +81,9 @@ function logSession($event) {

// set last_req to be the timestamp of the event that triggered this session.
$s->set('last_req', $event->get('timestamp'));
$s->set('days_sinse_first_session', $event->get('days_sinse_first_session'));
$s->set('days_sinse_prior_session', $event->get('days_sinse_prior_session'));
$s->set('num_prior_sessions', $event->get('num_prior_sessions'));

// set source

@@ -70,8 +70,8 @@ function logVisitor($event) {
$v->set('first_session_month', $event->get('month'));
$v->set('first_session_day', $event->get('day'));
$v->set('first_session_dayofyear', $event->get('dayofyear'));
$v->set('first_session_timestamp', $event->get('timestamp'));

$v->set('first_session_timestamp', $event->get('timestamp'));
$v->set('num_prior_sessions', $event->get('num_prior_sessions'));
$v->create();
}

@@ -92,7 +92,8 @@ function logVisitorUpdate($event) {
$v->set('last_session_year', $event->get('year'));
$v->set('last_session_month', $event->get('month'));
$v->set('last_session_day', $event->get('day'));
$v->set('last_session_dayofyear', $event->get('dayofyear'));
$v->set('last_session_dayofyear', $event->get('dayofyear'));
$v->set('num_prior_sessions', $event->get('num_prior_sessions'));

$id = $v->get('id');

@@ -40,15 +40,15 @@ class owa_processEventController extends owa_controller {

function __construct($params) {

$event = $params['event'];
if (!empty($event)) {
$this->event = $params['event'];
if (array_key_exists('event', $params) && !empty($params['event'])) {

$this->event = $params['event'];

} else {
owa_coreAPI::debug("No event object was passed to controller.");
$this->event = owa_coreAPI::supportClassFactory('base', 'event');
}

$this->eq = owa_coreAPI::getEventDispatch();

return parent::__construct($params);
@@ -95,10 +95,16 @@ function pre() {
$this->event->set('last_req', $state[owa_coreAPI::getSetting('base', 'last_request_param')]);

// set inbound visitor id
if (owa_coreAPI::getSetting('base', 'per_site_visitors')) {
$this->event->set('inbound_visitor_id', $state[owa_coreAPI::getSetting('base', 'visitor_param')]);
} else {

$vstate = owa_coreAPI::getStateParam(owa_coreAPI::getSetting('base', 'visitor_param'));

//check for old style visitor cookie
if (!is_array($vstate) && !empty($vstate)) {
$this->event->set('inbound_visitor_id', owa_coreAPI::getStateParam(owa_coreAPI::getSetting('base', 'visitor_param')));
owa_coreAPI::setState(owa_coreAPI::getSetting('base', 'visitor_param'), '', '', 'cookie', true);
owa_coreAPI::setState(owa_coreAPI::getSetting('base', 'visitor_param'), 'vid', $vstate, 'cookie', true);
} else {
$this->event->set('inbound_visitor_id', owa_coreAPI::getStateParam(owa_coreAPI::getSetting('base', 'visitor_param'), 'vid'));
}

// set visitor type flag if inbound visitor ID is found.
@@ -273,6 +279,13 @@ function pre() {
$this->event->set('user_email', $this->eq->filter('user_email', $email_address));
}

//read the num prior session value from cookie. set to 0 if false.
$nps = owa_coreAPI::getStateParam('v', 'nps');
if (!$nps) {
$nps = 0;
}
//set the value on the event
$this->event->set('num_prior_sessions', $nps);
}

function post() {
@@ -332,14 +345,12 @@ function setNewVisitor() {
// Create guid
$this->event->set('visitor_id', $this->getSiteSpecificGuid());

// Set visitor state
if (owa_coreAPI::getSetting('base', 'per_site_visitors') === true) {
// TODO: not sure how this will work if the config calls for maintaining state on the server....
owa_coreAPI::setState(owa_coreAPI::getSetting('base', 'site_session_param'), owa_coreAPI::getSetting('base', 'visitor_param'), $this->event->get('visitor_id'), 'cookie', true);
} else {
// state for this must be maintained in a cookie
owa_coreAPI::setState(owa_coreAPI::getSetting('base', 'visitor_param'), '', $this->event->get('visitor_id'), 'cookie', true);
}
// Set visitor state
// state for this must be maintained in a cookie
owa_coreAPI::setState(owa_coreAPI::getSetting('base', 'visitor_param'), 'vid', $this->event->get('visitor_id'), 'cookie', true);
owa_coreAPI::setState(owa_coreAPI::getSetting('base', 'visitor_param'), 'fsts', $this->event->get('timestamp'), 'cookie', true);


}

function getSiteSpecificGuid() {

0 comments on commit dead5b4

Please sign in to comment.
You can’t perform that action at this time.