From 75ca1ed51dd4dfd091a07501da38ea568a418ae5 Mon Sep 17 00:00:00 2001 From: Peter Adams Date: Tue, 14 Jan 2020 19:02:36 -0800 Subject: [PATCH] Fixes for feed trackung in WordPress --- modules/base/handlers/feedRequestHandlers.php | 7 -- modules/base/module.php | 7 ++ owa_wp.php | 8 +-- wp_plugin.php | 69 +++++++++++++------ 4 files changed, 59 insertions(+), 32 deletions(-) diff --git a/modules/base/handlers/feedRequestHandlers.php b/modules/base/handlers/feedRequestHandlers.php index a57680e58..5d8a205b9 100644 --- a/modules/base/handlers/feedRequestHandlers.php +++ b/modules/base/handlers/feedRequestHandlers.php @@ -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 diff --git a/modules/base/module.php b/modules/base/module.php index 36fd38259..1cbefb90d 100644 --- a/modules/base/module.php +++ b/modules/base/module.php @@ -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', diff --git a/owa_wp.php b/owa_wp.php index 72037ad8d..86000145f 100644 --- a/owa_wp.php +++ b/owa_wp.php @@ -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; + } } } diff --git a/wp_plugin.php b/wp_plugin.php index 9ba099ef5..74c850d8a 100644 --- a/wp_plugin.php +++ b/wp_plugin.php @@ -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'); @@ -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. @@ -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'); } @@ -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() { @@ -793,6 +815,11 @@ function addTrackerToPage() { //Output the script } + + function generateUniqueNumericId() { + + return crc32(getmypid().microtime()); + } } ?> \ No newline at end of file