Skip to content

Commit

Permalink
Fixes for feed trackung in WordPress
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Adams committed Jan 15, 2020
1 parent dbf270b commit 75ca1ed
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 32 deletions.
7 changes: 0 additions & 7 deletions modules/base/handlers/feedRequestHandlers.php
Expand Up @@ -49,13 +49,6 @@ function notify( $event ) {

if ( ! $f->wasPersisted() ) {

// rekey Feed subscription id tracking code
// @todo check the wordpress plugin to see if this is even needed
if ( ! $event->get( 'feed_subscription_id' ) ) {

$event->set( 'feed_subscription_id', $event->get( owa_coreAPI::getSetting( 'base', 'feed_subscription_param' ) ) );
}

// needed??
$event->set('feed_reader_guid', $event->setEnvGUID() );
// set feedreader flag to true, browser flag to false
Expand Down
7 changes: 7 additions & 0 deletions modules/base/module.php
Expand Up @@ -250,6 +250,13 @@ public function setupTrackingProperties() {

),

'feed_subscription_id' => array(
'required' => false,
'callbacks' => array( ),
'default_value' => null,
'alternative_key' => 'sid'
),

'attribs' => array(
'required' => false,
'data_type' => 'json',
Expand Down
8 changes: 4 additions & 4 deletions owa_wp.php
Expand Up @@ -77,15 +77,15 @@ function add_link_tracking($link) {
* @var string the feed link
* @return string link string with special tracking id
*/
function add_feed_tracking($binfo) {
function add_feed_tracking( $binfo ) {

if ($this->config['track_feed_links'] == true):
if ($this->config['track_feed_links'] == true) {
$guid = crc32(getmypid().microtime());

return $binfo."&".$this->config['ns'].$this->config['feed_subscription_param']."=".$guid;
else:
} else {
return;
endif;
}
}
}

Expand Down
69 changes: 48 additions & 21 deletions wp_plugin.php
Expand Up @@ -28,7 +28,7 @@
require_once('owa_env.php');

// Filter and Action hook assignments
add_action('template_redirect', 'owa_main');

add_action('wp_head', 'owa_insertPageTags',100);
add_filter('the_permalink_rss', 'owa_post_link');
add_action('init', 'owa_handleSpecialActionRequest');
Expand Down Expand Up @@ -242,26 +242,6 @@ function owa_insertPageTags() {
$owa->placeHelperPageTags(true, $options);
}

/**
* This is the main logging controller that is called on each request.
*
*/
function owa_main() {

//global $user_level;

$owa = owa_getInstance();
owa_coreAPI::debug('wp main request method');

//Check to see if this is a Feed Reeder
if( $owa->getSetting('base', 'log_feedreaders') && is_feed() ) {
$event = $owa->makeEvent();
$event->setEventType('base.feed_request');
$event->set('feed_format', $_GET['feed']);
// Process the request by calling owa
return $owa->trackEvent($event);
}
}

/**
* Wordpress filter function adds a GUID to the feed URL.
Expand Down Expand Up @@ -465,11 +445,28 @@ function defineActionHooks() {
add_action( 'transition_post_status', array( $this, 'trackPostAction') , 10, 3);
// New Blog (WPMU)
add_action( 'wpmu_new_blog', array( $this, 'trackNewBlogAction') , 10, 5);


// track feeds

add_action('init', array( $this, 'addFeedTrackingQueryParams'));
add_action( 'template_redirect', array( $this, 'trackFeedRequest'), 1 );



}

// These hooks do NOT rely on OWA being accessable via PHP

}

// Add query vars to WordPress
function addFeedTrackingQueryParams() {

global $wp;

// feed tracking param
$wp->add_query_var('owa_sid');

}

Expand Down Expand Up @@ -784,6 +781,31 @@ function trackCommentEditAction( $new_status, $old_status, $comment ) {
}
}

// Tracks feed requests
function trackFeedRequest() {

if ( is_feed() ) {


$owa = $this->getOwaInstance();

if( $owa->getSetting( 'base', 'log_feedreaders') ) {

owa_coreAPI::debug('Tracking WordPress feed request');

$event = $owa->makeEvent();
// set event type
$event->setEventType( 'base.feed_request' );
// determine and set the type of feed
$event->set( 'feed_format', get_query_var( 'feed' ) );
$event->set( 'feed_subscription_id', get_query_var( 'owa_sid' ) );
//$event->set( 'feed_subscription_id', $_GET['owa_sid'] );
// track
$owa->trackEvent( $event );
}
}
}

// adds the JavaScript Tracker cmds and script tag to the page.
function addTrackerToPage() {

Expand All @@ -793,6 +815,11 @@ function addTrackerToPage() {
//Output the script

}

function generateUniqueNumericId() {

return crc32(getmypid().microtime());
}
}

?>

0 comments on commit 75ca1ed

Please sign in to comment.