Developers
One tag, a few attributes
Colophon's units are plain elements with data attributes. One script finds them and renders each one in place. There is no build step and no framework to adopt.
<script async src="https://api.colophondigital.com/embed/colophon.js"
data-site="YOUR_SITE_KEY"></script> <div data-colophon="afterword"
data-article-id="harbour-tunnel-vote"
data-article-section="Transport"
data-article-tags="transport,harbour tunnel,council"></div> Quick start
Add the script once, with your site key from the console. Then place an element wherever a unit should render.
<!-- 1. Once per page, in the head -->
<script async src="https://api.colophondigital.com/embed/colophon.js"
data-site="YOUR_SITE_KEY"></script>
<!-- 2. Wherever the thread should appear -->
<div data-colophon="afterword"
data-article-id="harbour-tunnel-vote"></div> Or have your coding agent add it
Paste this into the agent that works on your site's code, with your own site key in place of
YOUR_SITE_KEY. It points the agent to our plain-text guide, and
asks it to show you the change before anything goes live.
Add Colophon's comment section (Afterword) and polls (CrowdSurge) to this website.
Site key: YOUR_SITE_KEY
Full instructions, written for you: https://colophondigital.com/install.md
1. In the template that every article page shares, load the script once:
<script async src="https://api.colophondigital.com/embed/colophon.js" data-site="YOUR_SITE_KEY"></script>
2. In the article template, straight after the article body, add the comment section:
<div data-colophon="afterword" data-article-id="ARTICLE_ID"></div>
Fill ARTICLE_ID from the CMS's permanent id for the article, never its URL or headline.
3. Where a poll should appear in the article, add:
<div data-colophon="crowdsurge" data-placement="article"></div>
The console decides which poll fills the "article" placement. To pin one poll instead, use data-poll="POLL_ID".
4. Leave the elements unstyled and outside any iframe. They take their typeface and colours from the page.
5. If the site sends a Content-Security-Policy, allow https://api.colophondigital.com in script-src, connect-src and img-src.
6. Show me the diff and one article URL where I can check it. Do not deploy. Units
Each unit is one element. The format of a poll, and every other setting, lives in the console.
| Unit | Element | Attributes |
|---|---|---|
| Afterword | <div data-colophon="afterword"> | data-article-id, plus any article details |
| CrowdSurge | <div data-colophon="crowdsurge"> | data-poll (a poll ID) or data-placement (a placement name) |
| Frontlist | <div data-colophon="frontlist"> | data-limit (how many stories to list) |
| Pull Quote | <div data-colophon="pull-quote"> | data-comment (a comment ID) |
| Comment count | <span data-colophon="comment-count"> | data-article-id |
<div data-colophon="afterword"
data-article-id="harbour-tunnel-vote"
data-article-section="Transport"
data-article-tags="transport,harbour tunnel,council"></div>
<div data-colophon="crowdsurge" data-poll="poll_tunnel_toll"></div>
<!-- Picks a live poll by placement, or by matching article tags -->
<div data-colophon="crowdsurge" data-placement="sidebar"></div>
<div data-colophon="frontlist" data-limit="5"></div>
<div data-colophon="pull-quote" data-comment="cmt_featured_tunnel"></div>
<span data-colophon="comment-count"
data-article-id="harbour-tunnel-vote"></span> Article details
Put these on the script tag as page defaults, or on each element. On a single-page app, or a page with several articles, put them on each element so every unit carries its own.
| Attribute | Meaning | If missing |
|---|---|---|
data-article-id | Your stable ID for the article. | Required |
data-article-title | The headline. | og:title |
data-article-url | The canonical address. | rel="canonical" |
data-article-section | The section name. Used in reports and to give ads context. | None |
data-article-tags | Comma-separated tags. Used to match polls to articles. | None |
<!-- Two articles on one page: each element carries its own details -->
<div data-colophon="afterword"
data-article-id="harbour-tunnel-vote"
data-article-title="Council backs harbour tunnel toll after six-hour debate"
data-article-url="https://example.com/transport/harbour-tunnel-vote"></div>
<div data-colophon="afterword"
data-article-id="night-bus-returns"
data-article-title="The night bus is coming back"
data-article-url="https://example.com/transport/night-bus-returns"></div> Sign-in
Readers can use Colophon's built-in accounts with no work from you. To pass readers who are
already signed in to your site, sign a short-lived HS256 token on your server with the SSO
secret from the console. The claims are sub, name, an optional
email, and an exp a few minutes ahead (ten at most).
// On your server, for a reader who is already signed in to your site.
import { SignJWT } from 'jose';
const secret = new TextEncoder().encode(process.env.COLOPHON_SSO_SECRET);
const token = await new SignJWT({ name: reader.displayName, email: reader.email })
.setProtectedHeader({ alg: 'HS256' })
.setSubject(reader.id) // sub: your stable ID for the reader
.setExpirationTime('5m') // exp: a few minutes ahead, ten at most
.sign(secret); <script>
document.addEventListener('colophon:ready', () => {
window.colophon.login(tokenFromYourServer);
});
// When the reader signs out of your site:
// window.colophon.logout();
</script> JavaScript API
The script exposes one object, window.colophon.
| Call | What it does |
|---|---|
window.colophon.login(token) | Signs a reader in with a token your server signed. |
window.colophon.logout() | Signs the reader out of every unit on the page. |
window.colophon.setConsent({ ads }) | Passes on the reader’s choice from your consent tool. With ads set to false, no unit requests an ad. |
window.colophon.on(event, handler) | Subscribes to one of the events below, named without the colophon: prefix. |
Events
Every event is dispatched on document, so your analytics can listen without touching the units.
| Event | When it fires |
|---|---|
colophon:ready | The script has loaded and mounted the units on the page. |
colophon:login | A reader signed in. |
colophon:logout | A reader signed out. |
colophon:comment-posted | A reader posted a comment or a reply. |
colophon:vote | A reader voted in a poll. |
colophon:ad-impression | An ad rendered in a Colophon placement. |
document.addEventListener('colophon:vote', (event) => {
console.log(event.type, event.detail);
});
// Or through the API, once it is ready. Here the name has no prefix
// and the handler receives the detail directly.
window.colophon.on('comment-posted', (detail) => {
console.log(detail);
}); Ads and consent
Ad slots appear inside the units once placements are switched on in the console. There are two
providers: demo, a simulated auction for local development, and
prebid, which uses your own Prebid.js build and bidder configuration.
Using a reader's sign-in to make ads addressable is off by default and needs the reader's agreement. Global Privacy Control is honoured automatically.
// Pass on what your consent tool recorded.
window.colophon.setConsent({ ads: true });
// For a reader who declines, no Colophon unit on the page
// requests an ad at all.
window.colophon.setConsent({ ads: false }); Styling
The units take their look from your page. They inherit the typeface and text colour of the element they sit in, notice whether the page behind them is dark, and take their accent from your page. To set any of it yourself, define these custom properties anywhere above the units.
/* In your own stylesheet. Every property is optional. */
:root {
--colophon-accent: darkblue; /* buttons and selected states */
--colophon-on-accent: white; /* text on an accent fill */
--colophon-link: darkblue; /* links inside the units */
--colophon-heading-font: Georgia, serif;
--colophon-radius: 4px;
} Local development
The repository runs the whole stack on your machine. The API serves the script at
https://api.colophondigital.com/embed/colophon.js, the console is at https://console.colophondigital.com, and the seeded demo site
key is pk_demo_specimen.
pnpm install
pnpm seed # loads the fictional Daily Specimen site
pnpm dev # API, embed, console and this website API base: https://api.colophondigital.com
Start with one article
Tell us about your site and we will set you up with a key. Adding Colophon for real is one script tag.