Plugin Directory

Changeset 3408647


Ignore:
Timestamp:
12/03/2025 12:40:08 AM (4 months ago)
Author:
searchifyai
Message:

Release version 1.1.0 - Improved tracking reliability

Location:
searchify-ai
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • searchify-ai/trunk/README.txt

    r3407116 r3408647  
    55Requires at least: 5.0
    66Tested up to: 6.9
    7 Stable tag: 1.0.0
     7Stable tag: 1.1.0
    88License: GPLv2
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    1313== Description ==
    1414
    15 Searchify Tracker automatically sends request data from your WordPress site to the Searchify API. 
     15Searchify Tracker automatically sends request data from your WordPress site to the Searchify API.
    1616This helps you understand how your content is being cited and referenced across the web in AI conversations.
    1717
     
    32321. Upload the plugin files to the `/wp-content/plugins/searchify-tracker` directory, or install directly from the WordPress plugins screen.
    33332. Activate the plugin through the 'Plugins' screen in WordPress.
    34 3. Thats it! Tracking starts automatically.
     343. That's it! Tracking starts automatically.
    3535
    3636== Frequently Asked Questions ==
    3737
     38= Does the plugin modify my site's content? =
     39No. The plugin does not modify or alter your website's content in any way.
     40
    3841= Does this plugin slow down my site? =
    39 No. Tracking requests are sent asynchronously and do not delay page loading.
     42The plugin may add a minimal delay (less than 1 second) while sending data.
    4043
    4144= What data is sent? =
     
    4750== Changelog ==
    4851
     52= 1.1.0 =
     53* Improved tracking reliability with multiple WordPress hooks
     54* Added output buffering support for cached pages
     55
    4956= 1.0 =
    5057* Initial release
     
    5259== Upgrade Notice ==
    5360
     61= 1.1.0 =
     62Improved tracking reliability and security fixes. No action required.
     63
    5464= 1.0 =
    5565Initial release.
     66
  • searchify-ai/trunk/searchify-tracker.php

    r3368070 r3408647  
    33Plugin Name: Searchify AI
    44Description: Tracks live citations from AI conversations.
    5 Version: 1.0.0
     5Version: 1.1.0
    66Author: Searchify
    77Author URI: https://searchify.ai/
     
    99*/
    1010
    11 add_action('init', 'searchify_track_request');
     11// Define tracking function
     12if (!function_exists('searchify_track_request')) {
     13    function searchify_track_request() {
     14        // Avoid tracking admin, cron, or AJAX requests
     15        if (is_admin() || wp_doing_cron() || wp_doing_ajax()) {
     16            return;
     17        }
    1218
    13 function searchify_track_request() {
    14     // Avoid tracking admin, cron, or AJAX requests
    15     if (is_admin() || wp_doing_cron() || wp_doing_ajax()) {
    16         return;
     19        // Avoid duplicate tracking by checking if we've already tracked this request
     20        static $tracked = false;
     21        if ($tracked) {
     22            return;
     23        }
     24        $tracked = true;
     25
     26        // Collect and sanitize request info
     27        $scheme     = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https' : 'http';
     28
     29        $host       = isset($_SERVER['HTTP_HOST']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST'])) : '';
     30        $uri        = isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : '';
     31        $full_url   = esc_url_raw($scheme . '://' . $host . $uri);
     32
     33        $domain     = $host; // already sanitized
     34        $user_agent = isset($_SERVER['HTTP_USER_AGENT'])
     35            ? sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT']))
     36            : 'unknown';
     37
     38        $data = array(
     39            'full_url'   => $full_url,
     40            'domain'     => $domain,
     41            'user_agent' => $user_agent,
     42        );
     43
     44        // Send POST request to API
     45        // Use blocking with short timeout to ensure request completes before PHP exits
     46        // Short timeout (1s) minimizes page load impact while ensuring delivery
     47        wp_remote_post(
     48            'https://api.searchify.ai/v1/track/citation',
     49            array(
     50                'headers'  => array('Content-Type' => 'application/json'),
     51                'body'     => wp_json_encode($data),
     52                'timeout'  => 1, // Short timeout to minimize delay
     53                'blocking' => true, // Blocking ensures request completes before PHP exits
     54            )
     55        );
     56
    1757    }
     58}
    1859
    19     // Collect and sanitize request info
    20     $scheme     = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https' : 'http';
     60// Start output buffering immediately to ensure we can track even cached pages
     61if (!headers_sent() && !ob_get_level()) {
     62    ob_start('searchify_output_buffer_handler');
     63}
    2164
    22     $host       = isset($_SERVER['HTTP_HOST']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST'])) : '';
    23     $uri        = isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : '';
    24     $full_url   = esc_url_raw($scheme . '://' . $host . $uri);
     65// Track on the earliest possible hooks - before any caching logic
     66// These fire in order: muplugins_loaded -> plugins_loaded -> init -> setup_theme -> template_redirect
     67add_action('muplugins_loaded', 'searchify_track_request', 1);
     68add_action('plugins_loaded', 'searchify_track_request', 1);
     69add_action('init', 'searchify_track_request', 1);
     70add_action('setup_theme', 'searchify_track_request', 1);
     71add_action('template_redirect', 'searchify_track_request', 1);
    2572
    26     $domain     = $host; // already sanitized
    27     $user_agent = isset($_SERVER['HTTP_USER_AGENT'])
    28         ? sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT']))
    29         : 'unknown';
     73// Track on shutdown hook - ALWAYS fires if PHP executes at all
     74add_action('shutdown', 'searchify_track_request', 999);
    3075
    31     $data = array(
    32         'full_url'   => $full_url,
    33         'domain'     => $domain,
    34         'user_agent' => $user_agent,
    35     );
    3676
    37     // Send POST request to API
    38     wp_remote_post(
    39         'https://api.searchify.ai/v1/track/citation',
    40         array(
    41             'headers'  => array('Content-Type' => 'application/json'),
    42             'body'     => wp_json_encode($data),
    43             'timeout'  => 1,
    44             'blocking' => true,
    45         )
    46     );
     77/**
     78 * Output buffer handler - ensures tracking happens even with output buffering
     79 */
     80function searchify_output_buffer_handler($buffer) {
     81    // Track when buffer is processed
     82    searchify_track_request();
     83    return $buffer; // Return buffer unchanged
    4784}
Note: See TracChangeset for help on using the changeset viewer.