File DA-010 View as Markdown
Install Double Agent on Shopify
This page puts Double Agent in your Shopify theme. Once it is in, every cart carries the visitor's label (human, bot or agent), so you can tell agent and bot orders apart. No app, no checkout pixel and no account are needed to start.
Before you start: you need permission to edit and publish the theme. Check that the theme or another app doesn't already load Double Agent; each page should load it once.
Add the snippet
- In Shopify admin, go to Online Store › Themes. On your theme, open ⋯ › Edit code.
- Open
layout/theme.liquid. - Paste these two lines inside
<head>, before other scripts. Keep the first line first.
<!-- snippet:shopify -->
<script>window.doubleagent=window.doubleagent||{q:[],push(){this.q.push(arguments)}};</script>
<script async src="https://cdn.doubleagent.so/v1/doubleagent.js" data-profile="auto"></script>
- Save. If you edited a theme that isn't live, publish it when you are ready.
If you switch themes later, add the snippet to the new theme too.
What lands on the cart
The SDK finds Shopify on its own. When a cart exists and the shopper's consent allows it, it writes these cart attributes through Shopify's Cart API. Carts made later on the same page, like an AJAX cart drawer, get them too. Shopify copies cart attributes onto the order.
| Attribute | Meaning |
|---|---|
_da_class | human, bot or agent |
_da_score | How likely the visitor is not human, 0 to 100 |
_da_agent | The agent family, or none |
_da_sid | The Double Agent session id |
_da_behavior | How it behaved: friendly, neutral or rogue |
_da_behavior_risk | Behaviour risk, 0 to 100 |
_da_authorization | Whether what it did was allowed by your agent policy: allowed, denied or unknown |
The SDK waits for consent through Shopify's Customer Privacy API. Until consent is given, or if that API doesn't load, nothing is written to the cart. The verdict still works in the browser.
Cart attributes come from the shopper's browser, so treat them as a label, not as proof.
Check it worked
- Open your live store, accept the cookie banner if there is one, and add something to the cart.
- Open the browser console and run:
fetch(window.Shopify.routes.root + 'cart.js').then((r) => r.json()).then((cart) => console.table(cart.attributes));
You should see _da_class and the other attributes. If they are missing, give it a second (the update runs in the background) and check that the snippet loads and consent was given.
Tag orders
Cart attributes alone don't add order tags. To get tags like doubleagent:bot or doubleagent:agent:openai on orders, turn on server relabel:
- Add your public key to the snippet (
data-key="pk_live_…"). See Capabilities. - Create an app for your store in Shopify's Dev Dashboard: Apps › Create app › Start from Dev Dashboard, and name it "Double Agent".
- On the app's Versions page, set the scopes to
read_ordersandwrite_orders, keep the default App URL, and click Release. - Click Install app and install it on your store.
- Open App settings and copy the Client ID and Client secret.
- In the portal, go to
Sites › your site › Settings › Server relabel credentials. Under Shopify, enter your shop domain (your-store.myshopify.com), the client ID and the client secret. - Add the checkout pixel below, so Double Agent can find each order.
Double Agent swaps the client ID and secret for a short-lived Admin API token when it needs one. The store and the app must be in the same Shopify organization. If you made a custom app in the Shopify admin before 2026, enter its Admin API token in Admin token (legacy app) instead of the client ID and secret.
When Double Agent's server changes a label the browser applied (for example, it confirms a verified agent), it tags the matching order. Tags also carry the behaviour, like doubleagent:behavior:rogue. See Relabel.
Add the checkout pixel
Double Agent finds the order by its checkout token or its cart token. The theme snippet sends only the cart token, and an order placed with Buy it now has no cart. Shopify doesn't run theme code at checkout, so the checkout token comes from a custom pixel, which Shopify runs on the checkout and thank you pages.
- In Shopify admin, go to Settings › Customer events.
- Click Add custom pixel, name it "Double Agent" and click Add pixel.
- Under Customer privacy, set Permission to Required and select Analytics only.
- Replace the sample code with the code below, and put your public key in the second line.
- Click Save, then Connect pixel.
<!-- pixel:shopify-custom -->
// Double Agent: sends this checkout's token, so Double Agent can tag the order.
const DOUBLEAGENT_KEY = 'pk_live_your_key';
analytics.subscribe('checkout_completed', async (event) => {
const checkout = event.data.checkout;
const attributes = {};
for (const { key, value } of checkout.attributes || []) attributes[key] = value;
let saved = {};
try {
saved = JSON.parse(await browser.sessionStorage.getItem('doubleagent.v')) || {};
} catch (error) {
// No verdict saved in this tab.
}
const sid = attributes._da_sid || saved.sessionId;
const verdictClass = attributes._da_class || saved.class;
if (!sid || !checkout.token || !['human', 'bot', 'agent'].includes(verdictClass)) return;
const score = Math.min(100, Math.max(0, Number(attributes._da_score) || 0)) / 100;
const probability = saved.sessionId === sid && saved.probability
? saved.probability
: { human: 1 - score, bot: verdictClass === 'bot' ? score : 0, agent: verdictClass === 'agent' ? score : 0 };
const ids = { src: 'shopify_custom_pixel', shopify_checkout_token: checkout.token };
if (checkout.order?.id) ids.shopify_order_id = checkout.order.id;
const beacon = {
v: 1, sid, sigv: 'shopify-custom-pixel', w: 0, ids,
page: { profile: 'ecommerce', action: 'checkout', payment: true, host: event.context?.document?.location?.host || '', path: '/checkout/complete' },
verdict: { class: verdictClass, probability, confidence: 0 },
signals: [], features: {}, timeline: [],
stats: { events: 0, durationMs: 0, pointer: 'none', reliability: 0 },
env: { tz: '', lang: '', screen: '', dpr: 1, mobile: false },
};
await fetch('https://api.doubleagent.so/v1/collect?k=' + DOUBLEAGENT_KEY, {
method: 'POST', body: JSON.stringify(beacon), keepalive: true, mode: 'no-cors', headers: { 'content-type': 'text/plain' },
});
});
The pixel reads the session id from the _da_sid cart attribute, or from the verdict the SDK saved in the tab. It sends that id, the checkout token and the order id, and no details about the shopper. If the SDK never ran in that visit, it sends nothing.
To check it, open the pixel under Settings › Customer events › Custom pixels and click Test. Shopify's Pixel Helper opens your store. Place a test order: checkout_completed should show a green dot, and the network tab on the thank you page shows a collect request that answered 204.
Customer events
The SDK also publishes da_classified (and da_final when there is one) to Shopify's customer events, with the same fields and the session id. A custom pixel can subscribe to them with analytics.subscribe('da_classified', …).
Next: claim your domain to see your store's visitors, then read about ecommerce data.