Skip to main content

Count feed downloads with Podtrac, OP3 or Podscribe

Free Beginner

No code needed for the common case. Open Show Settings → Feeds and paste the service’s prefix into Enclosure URL prefix — e.g. https://dts.podtrac.com/redirect.mp3/, https://op3.dev/e/, or your Podscribe prefix. Core (Feed\EnclosureUrlPrefixer, priority 10) then joins it onto every enclosure, in the public feed and every tier, and onto <podcast:trailer>; drops the episode URL’s leading https:// (as Podtrac and OP3 document) and keeps http://; never wraps the download proxy’s /benecaster-download/…?token=… URL — the proxy’s 302 carries the prefix instead, so the service counts the download without ever seeing the token; skips a URL that already starts with the same prefix; and clears the show’s feed cache when the setting changes.

This code example is for the advanced case: chaining a second service. One prefix per show is stored, so a second service needs its own callback at priority > 10, after core, copying core’s two rules — leave a proxy URL alone, and drop https://. One limit to know: this callback only reaches feed URLs. When download tracking is on, the proxy’s redirect carries only the show’s stored prefix, so downloads through the proxy are counted by the service in the setting and not by the chained one. If both services must count every download, put the one that matters most in the setting.

Code

<?php
add_filter( 'benecaster_feed_enclosure_url', function (
    string $url,
    int    $episode_id,
    int    $show_id,
    string $tier_slug
): string {
    $outer = 'https://op3.dev/e/';
    if ( '' === $url || str_starts_with( $url, $outer ) ) {
        return $url;
    }
    // Never wrap the download proxy URL: it carries the subscriber's feed token.
    if ( str_starts_with( $url, home_url( '/benecaster-download/' ) ) ) {
        return $url;
    }
    return $outer . preg_replace( '#^https://#i', '', $url );
}, 20, 4 );

View on GitHub →

Hooks Used

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