# Install Privatus Analytics on Shopify

> Add cookieless analytics to your Shopify store with one snippet in your theme code, then track checkout purchases and revenue with a Shopify custom pixel.

## Storefront

> **Warning:** The app is not in the Shopify App Store. Don't install an
> app called Privatus Analytics from the store: it is not ours, whoever
> published it. Use the theme code below until this page says the app is
> listed.

Edit your theme (**Online Store → Themes → … → Edit code**), open
`layout/theme.liquid` and add the snippet before `</head>`:

```liquid
{% unless request.design_mode %}
<script defer src="https://privatusanalytics.com/js/pa.js" data-site="pa_YOURSITEID" data-modules="engage,auto,vitals,clicks"
        data-mask="/account/orders/*->/account/orders/:id"></script>
{% endunless %}
```

`data-mask` reports customers' order pages as one path, so order ids don't
appear in your reports. `request.design_mode` leaves the tracker out of the
theme editor, so editing your theme doesn't add visits. Add other options
as [attributes](/docs/tracker/attributes).

## Checkout and purchases

Shopify's checkout doesn't run theme scripts. Use a **custom pixel** under
**Settings → Customer events → Add custom pixel**:

```js
// Privatus Analytics: purchases (runs in Shopify's sandbox)
const SITE = 'pa_YOURSITEID'
const ENDPOINT = 'https://privatusanalytics.com/api/event'

function send(body) {
  fetch(ENDPOINT, {
    method: 'POST', keepalive: true, credentials: 'omit',
    headers: { 'Content-Type': 'text/plain' },
    body: JSON.stringify(Object.assign({ s: SITE }, body))
  })
}

analytics.subscribe('checkout_completed', (event) => {
  const checkout = event.data.checkout
  send({
    // A fixed path: the real checkout URL contains a checkout token.
    t: 'event', n: 'purchase',
    u: new URL(event.context.document.location.href).origin + '/checkout/thank-you',
    p: {
      revenue: Number(checkout.totalPrice.amount),
      currency: checkout.totalPrice.currencyCode,
      items: checkout.lineItems.length
    }
  })
})
```

Set **Permission** to "Not required" only if your legal assessment allows
it. Privatus Analytics sets no cookies and stores nothing on the device. Never add
order ids, emails or names as properties.

`revenue` and `currency` are read as the event's revenue, not stored as
properties. The pixel runs in Shopify's sandbox without the tracker, so it
does not see a visitor's [opt-out](/docs/privacy/opt-out) flag.

Hits are only stored for hostnames that are among the site's domains. If
your checkout runs on your `myshopify.com` domain, add it as an
[additional domain](/docs/getting-started/add-a-site#more-settings-under-site-settings-general) or the
purchase is dropped.
