Route all enclosure URLs through Podtrac
Podtrac is a podcast download measurement prefix service. By routing every enclosure URL through Podtrac’s prefix, you gain cross-platform download attribution without changing your audio host. This recipe adds the prefix to every feed tier’s enclosure URL automatically — no per-episode editing required.
Code
<?php
add_filter(
'benecaster_feed_enclosure_url',
function ( string $url, int $episode_id, int $show_id, ?string $tier_slug ): string {
if ( '' === $url ) {
return $url;
}
$parts = wp_parse_url( $url );
if ( ! is_array( $parts ) || empty( $parts['host'] ) ) {
return $url;
}
$host_and_path = $parts['host'] . ( $parts['path'] ?? '' );
return 'https://dts.podtrac.com/redirect.mp3/' . $host_and_path;
},
10,
4
);