Skip to content

Auto-capture

The tag fires structured events when it encounters elements marked with data-p-* attributes. You only need to mark the elements you already have — no JS changes required. The tag walks up to 4 ancestors to inherit context, so a single set of attributes on a parent card flows through to all its children.

Mark a product card

html
<div
  data-p-product-id="123"
  data-p-product-name="Linen Shirt"
  data-p-product-price="49"
  data-p-position="0"
>
  <a href="/products/linen-shirt">…</a>
</div>

Fires product_viewed when the card is at least 50% visible in the viewport. The position becomes part of the event properties — useful for measuring CTR on grid positions.

Trigger an event on click

html
<button data-p-event="add_to_cart" data-p-quantity="1">
  Add to cart
</button>

When a parent has data-p-product-id etc., those properties are inherited automatically:

html
<div data-p-product-id="123" data-p-product-name="Linen Shirt">
  <button data-p-event="add_to_cart" data-p-quantity="1">Add to cart</button>
</div>

The resulting add_to_cart event carries product_id: 123, product_name: "Linen Shirt", quantity: 1.

Form submit

html
<form data-p-event="search">
  <input name="q" />
  <button type="submit">Search</button>
</form>

search_query is auto-extracted from inputs named q, query, or search. Other named inputs are not auto-extracted — to send their values, set them as data-p-* attributes.

Stock display

html
<div
  data-p-stock="out_of_stock"
  data-p-product-id="123"
>
  Out of stock
</div>

Fires stock_status_displayed once per element. Mutations on data-p-stock are tracked, so toggling between in_stock / low_stock / out_of_stock re-fires the event.

Form abandonment

html
<form data-p-form="address">…</form>

If the user types in the form then leaves the page (or unmounts the form) without submitting, form_abandoned fires with form: "address".

Opt out a region

Wrap any subtree with data-p-no-capture="true" to silence auto-capture for everything inside it. Useful for admin / debug widgets you don't want feeding analytics.

html
<div data-p-no-capture="true">
  <!-- nothing in here will be auto-captured -->
</div>

All data-p-* attributes

AttributeTypeNotes
data-p-eventevent nameRequired to make an element a click target.
data-p-product-id, data-p-product-name, data-p-product-slug, data-p-product-price, data-p-product-categorystring / numberInherited by descendants up to 4 levels.
data-p-positionnumberIndex within a list — pair with data-p-product-id.
data-p-variant-id, data-p-quantitystring / numberAdd-to-cart context.
data-p-sectionevent nameMark a section to fire when it scrolls into view.
data-p-stockin_stock, low_stock, out_of_stockFires stock_status_displayed.
data-p-formstringTag a form for form_abandoned tracking.
data-p-no-capturetrueSilence auto-capture for the subtree.
data-p-not-foundanyMarks a 404 / not-found page.

Any other data-p-<name> attributes you set are passed through to the event as <name> (with - converted to _).

© Periscale