> ## Documentation Index
> Fetch the complete documentation index at: https://docs.launchmystore.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Store Analytics

> The built-in first-party analytics on every storefront: what it records, how themes add goals, and how it respects consent

# Store Analytics

Every LaunchMyStore storefront records its own traffic: visitors, sessions,
traffic sources, pages, products viewed, add-to-cart, checkout and purchases.
Merchants see it under **Analytics → Traffic** in the admin. Themes don't need
to add anything for this to work.

## How it is loaded

`content_for_header` includes one small, asynchronous script:

```html theme={null}
<script async data-lms-analytics src="/.well-known/lms/a.js?v=…" data-pt="product" data-pid="9001"></script>
```

* It is served from the **store's own domain** and posts events back to the
  same domain at `/.well-known/lms/events`, so it works on custom domains and
  is not a third-party request.
* It never blocks rendering. The file is versioned (`?v=`) and cached for a
  year.
* `data-pt` is the page type (`product`, `collection`, `search`, `cart`,
  `checkout`). `data-pid`, `data-pn` and `data-ph` carry the product id, the
  product title, and the collection handle or search terms for that page. The
  tag holds no store id and no visitor data, so it is safe in cached pages.

> [!NOTE]
>
> Keep `{{ content_for_header }}` in your layout's `<head>`. Without it the
> store's analytics (and app embeds, pixels and other platform scripts) stop
> working.

## What it records automatically

| Event | When |
| - | - |
| Page view | Every page, including client-side navigation (`history.pushState`) |
| Product view | Product pages |
| Collection view / search | Collection and search pages |
| Cart view | The cart page |
| Add to cart | Any successful AJAX `POST /cart/add(.js)`, and plain `/cart/add` form posts |
| Checkout started | The checkout page, once per session |
| Purchase | Recorded by the platform when the order is paid (never by the browser) |
| Outbound link | Clicks on links to other sites |
| Engaged time | Time the tab was visible, sent when the visitor leaves |

The source of a visit is taken from the referrer and from `utm_source`,
`utm_medium`, `utm_campaign`, `utm_content`, `utm_term`, `ref`, and Google / Meta
click ids. It's kept for the whole session and credited to the order, so a
sale from an Instagram ad shows up under Instagram / Paid.

Add-to-cart detection reads the browser's resource timing: the request counts
once its response body has been read. All standard theme cart code already
reads it. If you write custom cart code, read the response
(`await res.json()`), as you would to update the cart drawer anyway.

## Goals

Count a click as a goal by adding `data-lms-goal` to any element:

```liquid theme={null}
<a href="/pages/wholesale" data-lms-goal="Wholesale enquiry">Become a stockist</a>
```

Or from JavaScript (calls made before the script loads are queued):

```js theme={null}
window.lmsAnalytics = window.lmsAnalytics || function () {
  (window.lmsAnalytics.q = window.lmsAnalytics.q || []).push(arguments);
};
lmsAnalytics('goal', 'Size guide opened', { product: 'classic-tee' });
```

Goal names are up to 64 characters; properties are a small flat object
(up to 1 KB as JSON).

## Privacy and consent

* The visitor id lives in first-party storage (`localStorage`). No cookie is
  set for analytics, and nothing is shared with third parties.
* URLs are recorded **without** their query string, so emails, tokens or codes
  in a URL never leave the browser.
* No IP address is stored. The country, region and city come from the
  network edge at the time of the visit.
* The tracker checks `window.LMS.customerPrivacy.analyticsProcessingAllowed()`
  before recording. If your theme or a consent app sets it to return `false`,
  nothing is sent.
* Bots, headless browsers and automated test browsers are not counted.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.