diff --git a/README.txt b/README.txt index f29158e..82cfc9e 100644 --- a/README.txt +++ b/README.txt @@ -29,7 +29,7 @@ Choose the server version under OWA > Settings. * The user name of logged-in users, if Track Named Users is on. * WordPress admin pages, if Track WP Admin Pages is on (1.x only). -Previews, the Customizer and logged-in users are not tracked. Turn off Don't Track Logged-in Users (on by default) to track logged-in users. +Previews, the Customizer and logged-in users are not tracked. For a logged-in user the tracker still loads, paused, so OWA's heatmap and Domstream player open on the site. Turn off Don't Track Logged-in Users (on by default) to track logged-in users. = Multisite = @@ -76,6 +76,10 @@ Application passwords are sent only over https. To use an http OWA server, turn == Changelog == += 2.4.1 = + +* Don't Track Logged-in Users: a logged-in user now gets the tracker paused instead of no tracker, so OWA's heatmap and Domstream player open on the site. Nothing is sent to OWA for them, but their browser still loads the tracker from the OWA server. Admin pages still get no tracker. + = 2.4.0 = * Don't Track Logged-in Users is on by default. A site that never saved this setting (last saved before 2.3.0) stops tracking logged-in users; turn the setting off to track them again. diff --git a/owa-plugin.php b/owa-plugin.php index f7abdf7..2fc4ab5 100644 --- a/owa-plugin.php +++ b/owa-plugin.php @@ -566,13 +566,22 @@ function insertTrackingTag() { return; } + // An excluded logged-in user gets the tracker paused rather than no + // tracker: it sends nothing, and the overlays OWA's reports open on + // the site (the heatmap, the Domstream player) start from it. The + // pause is queued first, so it is applied before the page view. + // No overlay opens on an admin screen, so those get no tracker. if ( $this->getOption( 'excludeLoggedInUsers' ) && is_user_logged_in() ) { - - return; - } + + if ( is_admin() ) { + + return; + } + + $this->cmds[] = $this->makeCmd( 'pause' ); // set user name in tracking for names users with wp-admin accounts - if ( $this->getOption( 'trackNamedUsers') ) { + } elseif ( $this->getOption( 'trackNamedUsers') ) { $this->setUserNameCmd(); } @@ -980,7 +989,7 @@ public function registerOptions() { 'title' => 'Don't Track Logged-in Users', 'page_name' => 'owa-wordpress', 'section' => 'tracking', - 'description' => 'No tracking tag for visitors who are logged in to WordPress.', + 'description' => 'The tracker loads paused for visitors who are logged in to WordPress: it sends nothing, and OWA\'s heatmap and Domstream player still open on the site.', 'label_for' => 'Do not track logged-in users', 'error_message' => '' ) diff --git a/tests/OwaV2Test.php b/tests/OwaV2Test.php index bdc9e0a..16fc2b1 100644 --- a/tests/OwaV2Test.php +++ b/tests/OwaV2Test.php @@ -97,18 +97,33 @@ public function testASiteIdThatCannotBeABundleFileGetsNoTag(): void { $this->assertSame( '', $this->renderTag( $this->v2( [ 'siteId' => '../owa-config' ] ) ) ); } - public function testLoggedInUsersCanBeExcludedInBothVersions(): void { + /** + * An excluded logged-in user gets the tracker, paused before anything is + * sent: OWA's overlays (the heatmap, the Domstream player) start from the + * tracker, so without it they never open for the site's own admins. + */ + public function testAnExcludedLoggedInUserGetsAPausedTrackerInBothVersions(): void { $this->stubConditionals( [ 'is_single' ] ); Functions\when( 'wp_title' )->justReturn( 'Post' ); Functions\when( 'is_user_logged_in' )->justReturn( true ); + Functions\when( 'wp_get_current_user' )->justReturn( (object) [ 'user_login' => 'editor1' ] ); + + $v2 = $this->renderTag( $this->v2( [ 'excludeLoggedInUsers' => true, 'trackNamedUsers' => true ] ) ); + $cmd = array_column( $this->pushedCmds( $v2 ), 0 ); + + $this->assertStringContainsString( 'https://owa.example.com/public/tracker/OWA-9b62dc7ce78a6934.js', $v2 ); + $this->assertSame( 'pause', $cmd[0], 'Queued before the bundle\'s page view.' ); + $this->assertNotContains( 'setUserName', $cmd, 'Nothing is sent, so there is no user to name.' ); - $this->assertSame( '', $this->renderTag( $this->v2( [ 'excludeLoggedInUsers' => true ] ) ) ); + $v1 = $this->renderTag( $this->makePlugin( [ 'owaEndpoint' => 'https://owa.example.com/', 'siteId' => 'abc123', 'excludeLoggedInUsers' => true ] ) ); + $cmd = array_column( $this->pushedCmds( $v1 ), 0 ); - $v1 = $this->makePlugin( [ 'owaEndpoint' => 'https://owa.example.com/', 'siteId' => 'abc123', 'excludeLoggedInUsers' => true ] ); - $this->assertSame( '', $this->renderTag( $v1 ) ); + $this->assertSame( 'pause', $cmd[0] ); + $this->assertLessThan( array_search( 'trackPageView', $cmd ), array_search( 'pause', $cmd ) ); - $this->assertNotSame( '', $this->renderTag( $this->v2() ), 'Logged-in users are tracked unless excluded.' ); + $this->assertNotContains( 'pause', array_column( $this->pushedCmds( $this->renderTag( $this->v2() ) ), 0 ), + 'Logged-in users are tracked unless excluded.' ); } public function testTheApplicationPasswordGoesToTheSdk(): void { diff --git a/tests/TrackingTagTest.php b/tests/TrackingTagTest.php index e154168..f7ee0a9 100644 --- a/tests/TrackingTagTest.php +++ b/tests/TrackingTagTest.php @@ -139,6 +139,25 @@ public function testAdminPagesAreNotTaggedUnlessEnabled(): void { $this->assertSame( '', $this->renderTag( $this->plugin() ) ); } + public function testAdminPagesAreNotTaggedForAnExcludedLoggedInUser(): void { + + Functions\when( 'is_admin' )->justReturn( true ); + Functions\when( 'is_user_logged_in' )->justReturn( true ); + Functions\when( 'get_current_screen' )->justReturn( (object) [ 'id' => 'dashboard' ] ); + $this->stubConditionals(); + Functions\when( 'wp_title' )->justReturn( 'Dashboard' ); + + $plugin = $this->plugin(); + $plugin->setOption( 'trackAdminPages', true ); + $plugin->setOption( 'excludeLoggedInUsers', true ); + + $this->assertSame( '', $this->renderTag( $plugin ), 'No overlay opens on an admin screen, so no paused tracker.' ); + + $plugin->setOption( 'excludeLoggedInUsers', false ); + + $this->assertNotSame( '', $this->renderTag( $plugin ), 'Admin pages are tagged when logged-in users are tracked.' ); + } + public function testOwnSettingsScreenIsNeverTagged(): void { Functions\when( 'is_admin' )->justReturn( true );