From e8c6b5dbfe1a8cec51b6e516986283cd56bd334d Mon Sep 17 00:00:00 2001 From: padams Date: Thu, 10 Nov 2011 07:44:29 +0000 Subject: [PATCH] adding convienence functions for setting custom campaign property keys in JS and PHP Trackers. fixed php4 style variable referencing warnings. --- modules/base/classes/client.php | 63 +++++++++++++++++---- modules/base/classes/settings.php | 12 ++-- modules/base/js/owa.tracker-combined-min.js | 4 +- modules/base/js/owa.tracker.js | 31 ++++++++++ owa_base.php | 2 +- owa_coreAPI.php | 2 +- 6 files changed, 94 insertions(+), 20 deletions(-) diff --git a/modules/base/classes/client.php b/modules/base/classes/client.php index d263d4e53..497b4cfbc 100644 --- a/modules/base/classes/client.php +++ b/modules/base/classes/client.php @@ -522,32 +522,75 @@ public function createSiteId($value) { return md5($value); } + public function setCampaignNameKey( $key ) { + + $campaign_params = owa_coreAPI::getSetting( 'base', 'campaign_params' ); + $campaign_params[ 'campaign' ] = $key; + owa_coreAPI::setSetting('base', 'campaign_params', $campaign_params); + } + + public function setCampaignMediumKey( $key ) { + + $campaign_params = owa_coreAPI::getSetting( 'base', 'campaign_params' ); + $campaign_params[ 'medium' ] = $key; + owa_coreAPI::setSetting('base', 'campaign_params', $campaign_params); + } + + public function setCampaignSourceKey( $key ) { + + $campaign_params = owa_coreAPI::getSetting( 'base', 'campaign_params' ); + $campaign_params[ 'source' ] = $key; + owa_coreAPI::setSetting('base', 'campaign_params', $campaign_params); + } + + public function setCampaignSearchTermsKey( $key ) { + + $campaign_params = owa_coreAPI::getSetting( 'base', 'campaign_params' ); + $campaign_params[ 'search_terms' ] = $key; + owa_coreAPI::setSetting('base', 'campaign_params', $campaign_params); + } + + public function setCampaignAdKey( $key ) { + + $campaign_params = owa_coreAPI::getSetting( 'base', 'campaign_params' ); + $campaign_params[ 'ad' ] = $key; + owa_coreAPI::setSetting('base', 'campaign_params', $campaign_params); + } + + public function setCampaignAdTypeKey( $key ) { + + $campaign_params = owa_coreAPI::getSetting( 'base', 'campaign_params' ); + $campaign_params[ 'ad_type' ] = $key; + owa_coreAPI::setSetting('base', 'campaign_params', $campaign_params); + } + function getCampaignProperties( $event ) { $campaign_params = owa_coreAPI::getSetting( 'base', 'campaign_params' ); $campaign_properties = array(); $campaign_state = array(); - foreach ($campaign_params as $k => $param) { + $request = owa_coreAPI::getRequest(); + foreach ( $campaign_params as $k => $param ) { //look for property on the event - $property = $event->get($param); + $property = $event->get( $param ); // look for property on the request scope. if ( ! $property ) { - $property = owa_coreAPI::getRequestParam($param); + $property = $request->getRequestParam( $param ); } if ( $property ) { - $campaign_properties[$k] = $property; + $campaign_properties[ $k ] = $property; } } // backfill values for incomplete param combos - if (array_key_exists('at', $campaign_properties) && !array_key_exists('ad', $campaign_properties)) { + if (array_key_exists('ad_type', $campaign_properties) && !array_key_exists('ad', $campaign_properties)) { $campaign_properties['ad'] = '(not set)'; } - if (array_key_exists('ad', $campaign_properties) && !array_key_exists('at', $campaign_properties)) { - $campaign_properties['at'] = '(not set)'; + if (array_key_exists('ad', $campaign_properties) && !array_key_exists('ad_type', $campaign_properties)) { + $campaign_properties['ad_type'] = '(not set)'; } if (!empty($campaign_properties)) { @@ -566,7 +609,7 @@ private function setCampaignSessionState( $properties ) { if (array_key_exists( $k, $properties ) ) { - owa_coreAPI::setState( 's', $v, $properties[$k] ); + owa_coreAPI::setState( 's', $k, $properties[$k] ); } } } @@ -686,10 +729,10 @@ function setTrafficAttribution( &$event ) { $campaign_params = owa_coreAPI::getSetting('base', 'campaign_params'); foreach( $campaign_params as $k => $v ) { - $value = owa_coreAPI::getState( 's', $v ); + $value = owa_coreAPI::getState( 's', $k ); if ( $value ) { - $this->setGlobalEventProperty( $v, $value ); + $this->setGlobalEventProperty( $k, $value ); } } diff --git a/modules/base/classes/settings.php b/modules/base/classes/settings.php index 1499b1bc2..aac2841cb 100644 --- a/modules/base/classes/settings.php +++ b/modules/base/classes/settings.php @@ -662,12 +662,12 @@ function getDefaultSettingsArray() { 'nonce_expiration_period' => 43200, 'max_prior_campaigns' => 5, 'campaign_params' => array( - 'cn' => 'campaign', - 'md' => 'medium', - 'sr' => 'source', - 'tr' => 'search_terms', - 'ad' => 'ad', - 'at' => 'ad_type'), + 'campaign' => 'owa_campaign', + 'medium' => 'owa_medium', + 'source' => 'owa_source', + 'search_terms' => 'owa_search_terms', + 'ad' => 'owa_ad', + 'ad_type' => 'owa_ad_type'), 'trafficAttributionMode' => 'direct', 'campaignAttributionWindow' => 60, 'capabilities' => array( diff --git a/modules/base/js/owa.tracker-combined-min.js b/modules/base/js/owa.tracker-combined-min.js index d01d78d3b..aace863a6 100644 --- a/modules/base/js/owa.tracker-combined-min.js +++ b/modules/base/js/owa.tracker-combined-min.js @@ -1,4 +1,4 @@ -// OWA Tracker Min file created 1308811141 +// OWA Tracker Min file created 1320902926 //// Start of json2 //// @@ -179,7 +179,7 @@ if(campaign_params['ad']&&!campaign_params['at']){campaign_params['at']='(not se if(this.isNewCampaign){} return campaign_params;},setCampaignSessionState:function(properties){var campaignKeys=this.getOption('campaignKeys');for(var i=0,n=campaignKeys.length;ithis.options.maxPriorCampaigns){var removed=this.campaignState.splice(0,1);OWA.debug('Too many prior campaigns in state store. Dropping oldest to make room.');} this.setCampaignCookie(this.campaignState);this.isTrafficAttributed=true;this.setCampaignSessionState(campaign_params);return campaign_params;}},originalAttributionModel:function(campaign_params){if(this.campaignState.length>0){OWA.debug('Original attribution detected.');campaign_params=this.campaignState[0];this.isTrafficAttributed=true;}else{OWA.debug('Setting Original Campaign touch.');if(this.isNewCampaign){this.campaignState.push(campaign_params);this.setCampaignCookie(this.campaignState);this.isTrafficAttributed=true;}} -this.setCampaignSessionState(campaign_params);return campaign_params;},setTrafficAttribution:function(event){var campaignState=OWA.getState('c','attribs');if(campaignState){this.campaignState=campaignState;} +this.setCampaignSessionState(campaign_params);return campaign_params;},setCampaignMediumKey:function(key){this.options.campaignKeys[0].public=key;},setCampaignNameKey:function(key){this.options.campaignKeys[1].public=key;},setCampaignSourceKey:function(key){this.options.campaignKeys[2].public=key;},setCampaignSearchTermsKey:function(key){this.options.campaignKeys[3].public=key;},setCampaignAdKey:function(key){this.options.campaignKeys[4].public=key;},setCampaignAdTypeKey:function(key){this.options.campaignKeys[5].public=key;},setTrafficAttribution:function(event){var campaignState=OWA.getState('c','attribs');if(campaignState){this.campaignState=campaignState;} var campaign_params=this.getCampaignProperties();switch(this.options.trafficAttributionMode){case'direct':OWA.debug('Applying "Direct" Traffic Attribution Model');campaign_params=this.directAttributionModel(campaign_params);break;case'original':OWA.debug('Applying "Original" Traffic Attribution Model');campaign_params=this.originalAttributionModel(campaign_params);break;default:OWA.debug('Applying Default (Direct) Traffic Attribution Model');this.directAttributionModel(campaign_params);} if(this.isTrafficAttributed){OWA.debug('Attributed Traffic to: %s',JSON.stringify(campaign_params));}else{if(this.isNewSessionFlag===true){OWA.debug('Infering traffic attribution.');this.inferTrafficAttribution();}} var campaignKeys=this.getOption('campaignKeys');for(var i=0,n=campaignKeys.length;ie = &owa_coreAPI::errorSingleton(); + $this->e = owa_coreAPI::errorSingleton(); $this->c = &owa_coreAPI::configSingleton(); $this->config = $this->c->fetch('base'); } diff --git a/owa_coreAPI.php b/owa_coreAPI.php index 60d9fdf2a..72377eed4 100644 --- a/owa_coreAPI.php +++ b/owa_coreAPI.php @@ -413,7 +413,7 @@ public static function subViewFactory($subview, $params = array()) { public static function supportClassFactory($module, $class, $params = array(),$class_ns = 'owa_') { - $obj = &owa_lib::factory(OWA_BASE_DIR.'/'.'modules'.'/'.$module.'/'.'classes'.'/', $class_ns, $class, $params); + $obj = owa_lib::factory(OWA_BASE_DIR.'/'.'modules'.'/'.$module.'/'.'classes'.'/', $class_ns, $class, $params); $obj->module = $module; return $obj;