---
url: /reference/items/Track/examples.md
---
# Examples
## Shopify product page
A product page that sets shared context once, tracks a product impression, and publishes an `add_to_cart` event through `TrackShopify` — the button only declares the event name, everything else is inherited from the context.
```liquid
{{ product.title }}
```
The `add_to_cart` click publishes:
```js
Shopify.analytics.publish('my_app:add_to_cart', {
page_type: 'product',
currency: 'EUR',
item: { item_id: 123, item_name: 'Cotton Tee', price: 29.9 },
event: 'my_app:add_to_cart',
});
```
::: tip
Author rich payloads in a ``, guard it with a `replace` filter — `| json | replace: '', '<\/'`.
:::
## GA4 item list (dataLayer)
Track a collection impression with a GA4 `ecommerce.items` array. Arrays replace on merge, so an event's list fully overrides one coming from the context.
```liquid
```
## Switching provider
The same markup targets a different destination by changing the component name — no JavaScript change:
```html
```