Skip to content

ptag Publisher Integration

Track ad impressions and viewability. Production script URL: https://cdn.thrad.ai/ptag.min.js.

Setup (one-time, in <head>)

<script>
  window.ptag = window.ptag || function() { 
    (window.ptag.q = window.ptag.q || []).push(arguments); 
  };
  window.ptag.trackImpressions = window.ptag.trackImpressions || function() { return { disconnect: function() {} }; };
</script>
<script async src="https://cdn.thrad.ai/ptag.min.js"></script>
<script>
  // Use your publisher/tag id here so collect payloads carry a stable tag_id.
  ptag('config', 'pub_001', {});
  ptag.trackImpressions('.thrad-ad-container');
</script>

Requirements

Ad container

Must have class thrad-ad-container and contain an <a href="..."> with the redirect URL (I believe you're already doing both):

<div class="thrad-ad-container">
  <a href="https://ssp.thrads.ai/api/v1/tracking/redirect?token=abc123">
    <img src="ad.jpg" />
  </a>
</div>

ptag extracts the token from the href to identify the ad (bid_id). No extra data attributes needed. Also configure a stable target id with ptag('config', '<tag_id>', {}) (or pass params.send_to) so collect events include non-empty tag_id.


What gets tracked

Event When
rendered Ad element exists in DOM
in_view Ad enters viewport
viewable 50% visible for 1 second (IAB standard)
view_end Ad leaves viewport or page closes

Options

ptag.trackImpressions('.thrad-ad-container', {
  max: 10,                 // limit ads tracked (default 20)
  sendOnInView: true,      // send event when ad enters viewport
  sendOnViewable: true,    // send event when ad is viewable (50% for 1s)
  sendOnViewEnd: true,     // send event when ad exits viewport
  params: {                // custom metadata for all events
    send_to: 'pub_001',    // optional if already set via ptag('config', ...)
    placement_id: 'feed_top'
  }
});

How it works

  1. ptag finds all .thrad-ad-container elements
  2. Tracks visibility via IntersectionObserver
  3. Sends events to backend
  4. Sends collect with tag_id from send_to/config (if omitted, server falls back to site:<host>).

New ads added dynamically are auto-tracked.


Stop tracking

const handle = ptag.trackImpressions('.thrad-ad-container');
handle.disconnect();

Google Tag Manager (GTM)

If you use GTM, you can install ptag without touching your codebase:

  1. Go to GTMTagsNew
  2. Choose Custom HTML
  3. Paste:
<script>
  window.ptag = window.ptag || function() { 
    (window.ptag.q = window.ptag.q || []).push(arguments); 
  };
  window.ptag.trackImpressions = window.ptag.trackImpressions || function() { return { disconnect: function() {} }; };
</script>
<script async src="https://cdn.thrad.ai/ptag.min.js"></script>
<script>
  ptag('config', 'pub_001', {});
  ptag.trackImpressions('.thrad-ad-container');
</script>
  1. Set trigger: DOM Ready
  2. Save and Publish

Same functionality, managed via GTM dashboard instead of code.