Shopify
Add Databuddy to your Shopify theme to record visits, then send product, cart and purchase events.
Add the script
Open your theme code
Go to Online Store → Themes, open the ... menu on your live theme, and choose Edit code.
Paste the script
In layout/theme.liquid, paste this just before </head>:
<script
src="https://cdn.databuddy.cc/databuddy.js"
data-client-id="YOUR_CLIENT_ID"
data-track-attributes
data-track-outgoing-links
crossorigin="anonymous"
async
></script>Your Client ID is in the Databuddy dashboard under your website's Settings → General.
Already using Google Tag Manager? Load Databuddy from a GTM tag instead, not both.
Track product views and carts
<script>
window.addEventListener("load", function () {
window.databuddy?.track("product_view", {
product_id: "{{ product.id }}",
product_name: {{ product.title | json }},
product_price: {{ product.price | divided_by: 100.0 }},
currency: "{{ cart.currency.iso_code }}"
});
});
</script>
<button
type="submit"
name="add"
data-track="add_to_cart"
data-product-id="{{ product.id }}"
data-value="{{ product.price | divided_by: 100.0 }}"
>
Add to cart
</button>The button sends add_to_cart with productId and value on each click. Older themes use templates/product.liquid instead. The same pattern works in search.liquid with search.terms and in collection.liquid with collection.title.
Track purchases
Theme scripts don't run on checkout or the thank-you page, so send purchases from a custom pixel. In Settings → Customer events, choose Add custom pixel and paste:
analytics.subscribe("checkout_completed", (event) => {
const checkout = event.data.checkout;
fetch("https://basket.databuddy.cc/track", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
name: "purchase",
websiteId: "YOUR_CLIENT_ID",
properties: {
transaction_id: checkout.order?.id,
value: checkout.totalPrice?.amount,
currency: checkout.currencyCode,
item_count: checkout.lineItems.length,
},
}),
});
});Shopify runs custom pixels through its Web Pixels API.
Identify signed-in customers
{% if customer %}
<script>
window.addEventListener("load", function () {
window.databuddy?.identify("{{ customer.id }}", {
total_orders: {{ customer.orders_count }}
});
});
</script>
{% endif %}Use the customer ID, not an email address, and keep names and emails out of traits.
Send events from Shopify Flow
Add a Send HTTP request action to a Flow, such as one triggered by Order created:
{
"name": "order_created",
"websiteId": "YOUR_CLIENT_ID",
"source": "shopify_flow",
"properties": {
"order_id": "{{ order.id }}",
"status": "{{ order.displayFinancialStatus }}"
}
}Related
How is this guide?