Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Changelog

All notable changes to this project will be documented in this file.

### 0.1.1 - 2025-11-19

- Added: Filter `admin_session_recording_should_load_frontend` to allow programmatic enabling of frontend tracking scripts after UI-configured path checks.

### 0.1.0 - 2025-09-17

- Initial plugin release with:
- Admin settings page
- Hotjar and Microsoft Clarity support
- Role-based admin tracking
- Optional frontend tracking with path matching (contains/starts_with/ends_with/regex)
27 changes: 24 additions & 3 deletions admin-session-recording.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Admin Session Recording
* Plugin URI: https://github.com/TheCodeCompany/admin-session-recording
* Description: Allows Hotjar and Microsoft Clarity to be enabled within the admin area, with front-end being optional.
* Version: 0.1.0
* Version: 0.1.1
* Author: The Code Company
* Author URI: https://thecode.co
* License: ISC
Expand All @@ -20,7 +20,7 @@
}

// Define plugin version.
define( 'ADMIN_SESSION_RECORDING_VERSION', '0.1.0' );
define( 'ADMIN_SESSION_RECORDING_VERSION', '0.1.1' );

/**
* Main plugin class.
Expand Down Expand Up @@ -314,12 +314,33 @@ public function maybe_add_frontend_tracking_scripts(): void {
$current_path = wp_parse_url( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) ), PHP_URL_PATH );
$frontend_paths = $this->options['frontend_paths'];

// First, check UI-configured paths (user-friendly, simple cases).
foreach ( $frontend_paths as $path_config ) {
if ( $this->path_matches( $current_path, $path_config['path'], $path_config['match_type'] ) ) {
$this->output_tracking_scripts( false );
break;
return;
}
}

/**
* Filter to allow custom programmatic logic for enabling frontend tracking scripts.
*
* This filter runs after checking UI-configured paths, allowing for complex
* programmatic conditions that can't be expressed as simple path patterns.
* Examples: query parameters, user meta, custom post types, dynamic conditions.
*
* @param bool $should_load Whether to load tracking scripts for this path (default: false).
* @param string $current_path The current URL path.
* @param array $options The plugin options.
*
* @return bool True to load tracking scripts, false otherwise.
*/
$should_load = apply_filters( 'admin_session_recording_should_load_frontend', false, $current_path, $this->options );

if ( $should_load ) {
$this->output_tracking_scripts( false );
return;
}
}

/**
Expand Down