Skip to content

Commit

Permalink
adding convienence functions for setting custom campaign property key…
Browse files Browse the repository at this point in the history
…s in JS and PHP Trackers.

fixed php4 style variable referencing warnings.
  • Loading branch information
padams committed Nov 10, 2011
1 parent a6d08ca commit e8c6b5d
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 20 deletions.
63 changes: 53 additions & 10 deletions modules/base/classes/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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] );
}
}
}
Expand Down Expand Up @@ -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 );
}
}

Expand Down
12 changes: 6 additions & 6 deletions modules/base/classes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions modules/base/js/owa.tracker-combined-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions modules/base/js/owa.tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,37 @@ OWA.tracker.prototype = {

},

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' );
Expand Down
2 changes: 1 addition & 1 deletion owa_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class owa_base {
*/
function __construct() {
owa_coreAPI::profile($this, __FUNCTION__, __LINE__);
$this->e = &owa_coreAPI::errorSingleton();
$this->e = owa_coreAPI::errorSingleton();
$this->c = &owa_coreAPI::configSingleton();
$this->config = $this->c->fetch('base');
}
Expand Down
2 changes: 1 addition & 1 deletion owa_coreAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e8c6b5d

Please sign in to comment.