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¶
- ptag finds all
.thrad-ad-containerelements - Tracks visibility via IntersectionObserver
- Sends events to backend
- Sends collect with
tag_idfromsend_to/config(if omitted, server falls back tosite:<host>).
New ads added dynamically are auto-tracked.
Stop tracking¶
Google Tag Manager (GTM)¶
If you use GTM, you can install ptag without touching your codebase:
- Go to GTM → Tags → New
- Choose Custom HTML
- 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>
- Set trigger: DOM Ready
- Save and Publish
Same functionality, managed via GTM dashboard instead of code.