Skip to content
Permalink
Browse files

refactored js tracker tag generation so that cmds can be properly add…

…ed by modules.
  • Loading branch information...
Peter Adams
Peter Adams committed Feb 21, 2018
1 parent de71e40 commit 3e4058e00488a15afa14eecb904e3253c63b5667
Showing with 51 additions and 39 deletions.
  1. +13 −1 modules/base/module.php
  2. +7 −9 modules/base/templates/js_log_tag.tpl
  3. +20 −0 modules/domstream/module.php
  4. +10 −13 owa_coreAPI.php
  5. +1 −16 owa_module.php
@@ -507,10 +507,22 @@ function registerFilters() {
$this->registerFilter('post_processed_tracking_event', $this, 'anonymizeIpAddress');
}
$this->registerFilter('tracker_tag_cmds', $this, 'addTrackerCmds', 0);
}
function addTrackerCmds( $cmds ) {
$cmds[] = "owa_cmds.push(['trackPageView']);";
$cmds[] = "owa_cmds.push(['trackClicks']);";
return $cmds;
}
/**
* Register Filters
* Register Background jobs
*
* The following lines register background jobs used by the
* background daemon.
@@ -15,15 +15,13 @@ owa_cmds.push(['setSiteId', '<?php echo $site_id; ?>']);
<?php if ( isset($options) && $this->getValue( 'cmds', $options ) ): ?>
<?php $this->out($this->getValue( 'cmds', $options ), false ); ?>
<?php endif;?>
<?php if (isset($options) && ! $this->getValue('do_not_log_pageview', $options ) ): ?>
owa_cmds.push(['trackPageView']);
<?php endif;?>
<?php if (isset($options) && ! $this->getValue('do_not_log_clicks', $options ) ): ?>
owa_cmds.push(['trackClicks']);
<?php endif;?>
<?php if (isset($options) && ! $this->getValue('do_not_log_domstream', $options ) ): ?>
owa_cmds.push(['trackDomStream']);
<?php endif;?>
<?php
foreach ($cmds as $cmd) {
$this->out( $cmd );
$this->out( "\n");
}
?>
(function() {
var _owa = document.createElement('script'); _owa.type = 'text/javascript'; _owa.async = true;
@@ -48,6 +48,26 @@ function __construct() {
return parent::__construct();
}
function registerFilters() {
// adds tracking cmd to js tracker.
if ( owa_coreAPI::getSetting( 'domstream', 'is_active' ) ) {
$this->registerFilter('tracker_tag_cmds', $this, 'addToTracker', 99);
}
}
/**
* Adds domstream logging to the JS tracker tag.
* @return array
*/
function addToTracker( $cmds ) {
$cmds[] = "owa_cmds.push(['trackDomStream']);";
return $cmds;
}
/**
* Registers Event Handlers with queue queue
*
@@ -1516,24 +1516,15 @@ public static function getJsTrackerTag( $site_id, $options = array() ) {
$t = new owa_template();
//check to see if we shuld log clicks.
if ( ! owa_coreAPI::getSetting( 'base', 'log_dom_clicks' ) ) {
$options['do_not_log_clicks'] = true;
}
if ( ! owa_coreAPI::getSetting( 'base', 'log_dom_streams' ) ) {
$options['do_not_log_domstream'] = true;
}
if (owa_coreAPI::getSetting('base', 'is_embedded')) {
// needed to override the endpoint used by the js tracker
$options['apiEndpoint'] = owa_coreAPI::getSetting('base', 'api_url');
}
$t->set( 'site_id', $site_id );
$t->set( 'options', $options);
$cmds = owa_coreAPI::filter( 'tracker_tag_cmds', array() );
$t->set( 'cmds', $cmds );
$t->set_template('js_log_tag.tpl');
return $t->fetch();
}
@@ -1679,8 +1670,14 @@ public static function isIpAddressExcluded( $ip_address ) {
*/
public static function registerFilter( $filter_name, $callback, $priority = 10 ) {
$eq = owa_coreAPI::getEventDispatch();
$eq->attachFilter($filter_name, $callback, $priority);
$ed = owa_coreAPI::getEventDispatch();
$ed->attachFilter($filter_name, $callback, $priority);
}
public static function filter( $filter_name, $value ) {
$ed = owa_coreAPI::getEventDispatch();
return $ed->filter( $filter_name, $value );
}
}
@@ -333,7 +333,7 @@ function registerEventHandler($event_name, $handler_name, $method = 'notify', $d
}
/**
* Attaches an event handler to the event queue
* Hooks a function to a filter
*
* @param array $event_name
* @param string $handler_name
@@ -363,21 +363,6 @@ function registerFilter($filter_name, $handler_name, $method = '', $priority = 1
// register
owa_coreAPI::registerFilter($filter_name, array($class, $method), $priority);
}
/*
if ( ! is_object( $handler_name ) ) {
if ( ! class_exists( $handler_name ) ) {
//$handler = &owa_lib::factory($handler_dir,'owa_', $handler_name);
$handler_name = owa_coreAPI::moduleGenericFactory($this->name, $dir, $handler_name, $class_suffix = null, $params = '', $class_ns = 'owa_');
}
}
return owa_coreAPI::registerFilter($filter_name, array($handler_name, $method), $priority);
*/
}
/**

0 comments on commit 3e4058e

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