File DA-008 View as Markdown
Plugins
Every integration is a plugin. So is the Double Agent cloud. You can add your own:
doubleagent.use({
name: 'mytool', // unique; a later plugin with the same name replaces it
cat: 'analytics', // consent category: 'analytics' (default) | 'ads' | 'functional'
setup(ctx) { return () => {} }, // once per session; the teardown runs on reset() and pagehide
apply(verdict, ctx) {}, // every distinct verdict; ctx.event is 'da_classified' / 'da_final' once per session
report(payload, ctx) {}, // the session payload: payload.reason is 'ready' | 'change' | 'hidden' | 'pagehide' | 'flush'
});
- Plugins you add are always active. They run only with consent for their
cat. - Before the SDK loads:
doubleagent.push('use', plugin). Orinit({ plugins: [plugin, [other, config]] }). ctx.fieldsholds theda_*properties.ctx.configis the second argument ofuse().ctx.send(url, body)posts JSON astext/plain(no CORS preflight):sendBeaconfirst, then akeepalivefetch.- A plugin that throws is logged (with
debug: true) and skipped. Other plugins and the page carry on.
A new analytics tool
Browser only: nothing leaves the page except through the tool itself.
doubleagent.push('use', {
name: 'acme',
apply(v, ctx) {
if (!ctx.allowed) return;
window.acme?.setUserProperties({ da_class: ctx.fields.da_class, da_score: ctx.fields.da_score });
if (ctx.event) window.acme?.track(ctx.event, ctx.fields);
},
});
Your own backend
The reports also go to your server, next to the Double Agent cloud.
doubleagent.push('use', {
name: 'mybackend',
report(p, ctx) {
ctx.send('https://collect.example.com/da', { reason: p.reason, sid: p.sid, verdict: p.verdict, pages: p.pages });
},
});
Cloud off, your own backend only
<script>window.doubleagent=window.doubleagent||{q:[],push(){this.q.push(arguments)}};
doubleagent.push('use', { name: 'mybackend', report(p, ctx) { ctx.send('https://collect.example.com/da', p); } });</script>
<script async src="https://cdn.doubleagent.so/v1/doubleagent.js" data-cloud="off"></script>
npm: doubleagent.init({ cloud: false, plugins: [mybackend] }).
With the cloud off, the SDK makes no request to Double Agent. Verdicts, integrations and your plugins keep working. Everything that needs the cloud stops:
check(),getToken()andstripeToken()reject withDoubleAgentErrorcodecloud_disabled.protect()fails open: the form submits without ada_token.on('final')never fires. Final verdicts come from the server.- No HQ, live presence, proof of work or Handler.
See Capabilities.