Back to Installation
Shopify Installation Guide
Step-by-step guide to install TwoBucks Analytics on Shopify.
Quick Start
Method 1: Theme Customizer (Recommended)
- Go to Online Store → Themes
- Click Customize on your active theme
- Navigate to Theme Settings → Additional Scripts
- Add the script to the Head section:
<script
src="https://twobucks.ai/script.js"
data-website-id="your-website-id"
async
></script>Method 2: theme.liquid
Edit your theme's theme.liquid file:
- Go to Online Store → Themes → Actions → Edit code
- Open
theme.liquid - Add the script before
</head>:
<!-- theme.liquid -->
<head>
<!-- Other head content -->
<script
src="https://twobucks.ai/script.js"
data-website-id="your-website-id"
async
></script>
</head>Track Shopify Events
Add to Cart
<!-- templates/product.liquid or sections/product-form.liquid -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const addToCartForm = document.querySelector('form[action="/cart/add"]');
if (addToCartForm) {
addToCartForm.addEventListener('submit', function() {
if (window.twobucks) {
const productId = {{ product.id }};
const productTitle = {{ product.title | json }};
window.twobucks('add_to_cart', {
product_id: productId.toString(),
product_title: productTitle
});
}
});
}
});
</script>Purchase Tracking
<!-- templates/checkout.liquid or checkout.liquid -->
{% if checkout.order_id %}
<script>
if (window.twobucks) {
window.twobucks('purchase', {
order_id: '{{ checkout.order_id }}',
total: '{{ checkout.total_price | money_without_currency }}',
currency: '{{ checkout.currency }}'
});
}
</script>
{% endif %}Product View
<!-- templates/product.liquid -->
<script>
if (window.twobucks) {
window.twobucks('product_view', {
product_id: '{{ product.id }}',
product_title: {{ product.title | json }},
product_price: '{{ product.price | money_without_currency }}'
});
}
</script>Common Issues
Script Not Loading
- Ensure script is in
theme.liquid<head>section - Check theme customizer settings
- Verify
data-website-idis correct
Theme Updates
If your theme updates, you may need to re-add the script. Consider:
- Using a custom theme (not modifying default themes)
- Documenting where you added the script
- Using theme customizer instead of direct file edits
Checkout Pages
Shopify checkout pages are hosted separately. To track checkout, add script to checkout.liquid (if available in your plan).