Skip to main content

Send every Outlinks click to your own analytics as it happens

Premium Intermediate

benecaster_outlinks_click_logged fires each time a visitor follows a tracked /go/ link, right after Outlinks records the click, and only if it was recorded. $episode_id is the episode Outlinks checked belongs to the link’s show, never the raw ?ep value, or null.

Bot clicks are recorded too, so the action fires for them. Read is_bot from the click’s row, as below, if you only want people. It never fires for a show where Outlinks is switched off or on a lapsed site, where links redirect without being counted.

Code

<?php
add_action( 'benecaster_outlinks_click_logged', function ( int $click_id, string $slug, ?int $episode_id ): void {
    global $wpdb;
    $is_bot = (bool) $wpdb->get_var( $wpdb->prepare(
        "SELECT is_bot FROM {$wpdb->prefix}benecaster_outlinks_clicks WHERE id = %d", $click_id
    ) );
    if ( $is_bot ) {
        return; // Bot clicks are rows too, so the action fires for them.
    }
    my_analytics_queue( 'outlink_click', [ 'slug' => $slug, 'episode' => $episode_id ] );
}, 10, 3 );

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →