Shopify
Track e-commerce visitors and conversions from AI traffic
Loamly helps you understand how AI recommendations drive e-commerce sales. This guide shows you how to add Loamly to your Shopify store.
Add the tracking script
Method 1: Theme settings (recommended)
- Go to your Shopify admin → Online Store → Themes
- Click Customize on your current theme
- Click Theme settings (gear icon) in the left sidebar
- Scroll down to Custom code or Additional scripts
- Find the Head section and add:
<script
src="https://app.loamly.ai/t.js?d=yourstore.myshopify.com"
defer
></script>Method 2: Edit theme code
- Go to Online Store → Themes
- Click the ... menu → Edit code
- Open
theme.liquidin the Layout folder - Find the closing
</head>tag - Paste the script just before it
- Click Save
Custom domain
Enable AI verification (recommended)
The client-side script tracks page views, but to unlock the full power of Loamly you need server-side setup. This enables AI bot crawl detection, RFC 9421 signature verification, bot-to-click temporal matching, and prompt-to-crawl correlation with your Intelligence data. Without it, you miss the connection between AI bots crawling your site and the humans who visit after.
See the AI Visitor Verification guide for setup instructions.
Verify installation
- Visit your Shopify store in a new incognito window
- Browse a few products
- Check your Loamly dashboard for the visits
- Verify that page views are being tracked correctly
Track purchases
To track completed purchases, add tracking code to your checkout success page:
- Go to Settings → Checkout
- Scroll to Order status page → Additional scripts
- Add the following code:
{% if first_time_accessed %}
<script>
if (window.loamly) {
window.loamly.event('purchase', {
order_id: '{{ order.order_number }}',
total: {{ total_price | money_without_currency | remove: ',' }},
currency: '{{ currency }}',
items_count: {{ line_items.size }}
});
}
</script>
{% endif %}Revenue attribution
Track cart events
For deeper e-commerce insights, you can track add-to-cart events. Add this to your theme's JavaScript:
// Add to your theme.js or a custom JS file
document.addEventListener('click', function(e) {
const addToCartButton = e.target.closest('[data-add-to-cart]');
if (addToCartButton && window.loamly) {
const form = addToCartButton.closest('form');
const productTitle = form?.querySelector('[name="product-title"]')?.value
|| document.querySelector('.product-title')?.textContent;
window.loamly.event('add_to_cart', {
product: productTitle,
page: window.location.pathname
});
}
});Note: The exact selectors may vary depending on your theme. Adjust the selectors to match your theme's HTML structure.
Need help? Email hello@loamly.ai