Inspect or log where an Outlinks click is about to send a visitor
benecaster_outlinks_before_redirect fires on a tracked /go/ click immediately before the visitor is redirected, after benecaster_outlinks_click_logged. $country_code is the visitor’s ISO 3166-1 alpha-2 country from Benecaster’s GeoIP lookup, or null when GeoIP is off or had no answer. $redirect_data is the link’s stored settings plus target_url: the final address after the link’s expiry, its country rule, its affiliate URL and any URL parameters the visitor brought with them.
Code
<?php
add_action( 'benecaster_outlinks_before_redirect', function ( string $slug, ?int $episode_id, ?string $country_code, array $redirect_data ): void {
if ( str_contains( $redirect_data['target_url'], 'tag=' ) ) {
my_affiliate_log( $slug, $country_code, $redirect_data['target_url'] );
}
}, 10, 4 );
Hooks Used
Need this built rather than just documented? See our services →