<head> section of your page:<!-- Attribuly Event JS -->
<script>
!function(w,d,e,v,n,t,s){
if(w.AttribulyEventQueue) return;
n=w.AttribulyEventQueue=function(){
n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(Array.prototype.slice.call(arguments))
};
if(!w._aejs) w._aejs=n;
n.push=n;
n.loaded=!0;
n.version='1.0';
n.queue=[];
t=d.createElement(e);
t.async=!0;
t.src=v;
s=d.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)
}(window,document,'script','https://app.attribuly.com/sdk/tr/1.0/attribuly-eventjs.min.js');
// Initialize event tracking
AttribulyEventQueue('init', 'YOUR-PIXEL-ID');
// Track a page view event
AttribulyEventQueue('trackEvent', 'page_viewed');
</script>
// Basic initialization
AttribulyEventQueue('init', 'YOUR-PIXEL-ID');
// Track a simple event
AttribulyEventQueue('trackEvent', 'page_viewed');
// Track an event with data
AttribulyEventQueue('trackEvent', 'product_viewed', {
productVariant: {
id: "123456",
product: {
id: "789",
title: "Sample Product",
price: {
amount: 99.99,
currencyCode: "USD"
}
}
}
});
// Use a custom event ID (optional)
AttribulyEventQueue('trackEvent', 'product_viewed', {
productVariant: {
id: "123456"
// ... additional event data
}
}, {
eventId: 'custom-event-123'
});
| Event name | Description |
|---|---|
| page_viewed | Records when a user views a page. |
| product_viewed | Records when a user views a specific product. |
| collection_viewed | Records when a user views a collection, category, or series page. |
| product_added_to_cart | Records when a user adds a product to the cart. |
| product_removed_from_cart | Records when a user removes a product from the cart. |
| cart_viewed | Records when a user views the cart. |
| checkout_started | Records when a user starts the checkout flow. |
| checkout_completed | Records when a user successfully completes an order. |
| search_submitted | Records when a user submits a search. |
| lead_form | Records when a user submits a marketing or lead collection form. |
By default, EventJS automatically generates a unique event ID for each event. If you need to use your own event ID system, pass eventId in the options object.
// Use a custom event ID for a single event
AttribulyEventQueue('trackEvent', 'product_viewed', {
productVariant: {
id: "123456"
// ... event data
}
}, {
eventId: 'my-custom-event-id-123'
});
// Batch events can each have their own custom event ID
AttribulyEventQueue('trackEvents', [
{
type: 'product_viewed',
data: { productId: '123' },
eventId: 'pv-custom-1'
},
{
type: 'product_added_to_cart',
data: { productId: '123', quantity: 1 },
eventId: 'cart-custom-2'
},
{
type: 'page_viewed',
data: { pageUrl: '/products' }
// No eventId is provided, so an auto-generated ID is used.
}
]);
// Use a global default eventId for batch events and override it per event when needed
AttribulyEventQueue('trackEvents', [
{
type: 'product_viewed',
data: { productId: '123' }
},
{
type: 'product_added_to_cart',
data: { productId: '123' },
eventId: 'special-cart-event'
}
], {
eventId: 'global-default'
});
eventId has higher priority than the global options eventId.eventId is provided, the system generates an ID in the format sh- + UUID.// Initialize
AttribulyEventQueue('init', 'YOUR-PIXEL-ID');
// Track page view
AttribulyEventQueue('trackEvent', 'page_viewed');
// Track product view
AttribulyEventQueue('trackEvent', 'product_viewed', {
"productVariant": {
"price": {
"amount": 3999,
"currencyCode": "HKD"
},
"product": {
"title": "iphone 13",
"vendor": "attribuly woo test",
"id": "64",
"untranslatedTitle": "iphone 13",
"url": "https://woo.test.attribuly.com/product/apple/",
"type": ""
},
"id": "64",
"image": {
"src": ""
},
"sku": "P-13",
"title": "iphone 13",
"untranslatedTitle": "iphone 13"
}
});
// Track lead form submission
AttribulyEventQueue('trackEvent', 'lead_form', {
"email": "xxx@cc.com"
});
// Track search submission
AttribulyEventQueue('trackEvent', 'search_submitted', {
"searchResult": {
"query": "dqwdqw"
}
});
// Track product added to cart
AttribulyEventQueue('trackEvent', 'product_added_to_cart', {
"cartLine": {
"cost": {
"totalAmount": {
"amount": 3999,
"currencyCode": "HKD"
}
},
"merchandise": {
"id": 64,
"image": {
"src": ""
},
"price": {
"amount": "3999",
"currencyCode": "HKD"
},
"product": {
"id": 64,
"title": "iphone 13",
"vendor": "",
"type": "simple",
"untranslatedTitle": "iphone 13",
"url": "https://woo.test.attribuly.com/product/apple/"
},
"sku": "P-13",
"title": "iphone 13",
"untranslatedTitle": "iphone 13"
},
"quantity": 1
}
});
// Track product removed from cart
AttribulyEventQueue('trackEvent', 'product_removed_from_cart', {
"cartLine": {
"cost": {
"totalAmount": {
"amount": 9.49,
"currencyCode": "USD"
}
},
"merchandise": {
"id": "43728958423253",
"image": {
"src": ""
},
"price": {
"amount": 9.49,
"currencyCode": "USD"
},
"product": {
"id": "7897433309397",
"title": "APPLE PINK LADY ORGANIC - 1.0KG",
"vendor": "Test-Dmap",
"type": "",
"untranslatedTitle": "APPLE PINK LADY ORGANIC - 1.0KG",
"url": "/products/apple-pink-lady-organic-1kg?variant=43728958423253"
},
"sku": "apple-01",
"title": "1.0KG",
"untranslatedTitle": "1.0KG"
},
"quantity": 1
}
});
// Track collection view
AttribulyEventQueue('trackEvent', 'collection_viewed', {
"collection": {
"id": "413566009557",
"title": "Groceries",
"productVariants": [
{
"price": {
"amount": 4.3,
"currencyCode": "USD"
},
"product": {
"title": "ABBOTTS BAKERY SOURDOUGH RYE 760G",
"vendor": "Test-Dmap",
"id": "7878527156437",
"untranslatedTitle": "ABBOTTS BAKERY SOURDOUGH RYE 760G",
"url": "/products/abbotts-bakery-sourdough-rye-760g",
"type": ""
},
"id": "43661439271125",
"image": {
"src": ""
},
"sku": "G-03",
"title": "Default Title",
"untranslatedTitle": "Default Title"
}
]
}
});
// Track cart view
AttribulyEventQueue('trackEvent', 'cart_viewed', {
"cart": {
"cost": {
"totalAmount": {
"amount": 7998,
"currencyCode": "HKD"
}
},
"lines": [
{
"cost": {
"totalAmount": {
"amount": 7998,
"currencyCode": "HKD"
}
},
"quantity": 2,
"merchandise": {
"id": "64",
"title": "iphone 13",
"untranslatedTitle": "iphone 13",
"sku": "P-13",
"price": {
"amount": 3999,
"currencyCode": "HKD"
},
"image": {
"src": ""
},
"product": {
"id": "64",
"title": "iphone 13",
"untranslatedTitle": "iphone 13",
"url": "https://woo.test.attribuly.com/product/apple/",
"type": "simple",
"vendor": ""
}
}
}
],
"totalQuantity": 2,
"id": "c669ead13c880a2b0c4718cfa652888a"
}
});
// Track checkout started
AttribulyEventQueue('trackEvent', 'checkout_started', {
"checkout": {
"lineItems": [
{
"id": "ea5d2f1c4608232e07d3aa3d998e5135",
"quantity": 2,
"title": "iphone 13",
"variant": {
"id": "64",
"title": "iphone 13",
"untranslatedTitle": "iphone 13",
"sku": "P-13",
"price": {
"amount": 3999,
"currencyCode": "HKD"
},
"image": {
"src": ""
},
"product": {
"id": "64",
"title": "iphone 13",
"untranslatedTitle": "iphone 13",
"url": "https://woo.test.attribuly.com/product/apple/",
"type": "simple",
"vendor": ""
}
},
"finalLinePrice": {
"amount": 7998,
"currencyCode": "HKD"
}
}
],
"billingAddress": {
"firstName": "",
"lastName": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"country": "",
"phone": "",
"countryCode": "",
"province": "",
"provinceCode": "",
"zip": ""
},
"shippingAddress": {
"firstName": "",
"lastName": "",
"address1": "",
"address2": "",
"city": "",
"state": "HONG KONG",
"country": "HK",
"phone": "",
"countryCode": "",
"province": "",
"provinceCode": "",
"zip": ""
},
"currencyCode": "HKD",
"email": "example@example.com",
"phone": "",
"totalPrice": {
"amount": 7998,
"currencyCode": "HKD"
},
"totalTax": {
"amount": 0,
"currencyCode": "HKD"
},
"totalShipping": {
"amount": 0,
"currencyCode": "HKD"
},
"subtotalPrice": {
"amount": 7998,
"currencyCode": "HKD"
},
"shippingLine": {
"price": {
"amount": 0,
"currencyCode": "HKD"
}
},
"discountsAmount": {
"amount": 0,
"currencyCode": "HKD"
}
}
});
// Track checkout completed
AttribulyEventQueue('trackEvent', 'checkout_completed', {
"checkout": {
"lineItems": [
{
"id": "4",
"finalLinePrice": {
"amount": 7998,
"currencyCode": "HKD"
},
"quantity": 2,
"title": "iphone 13",
"variant": {
"id": "64",
"title": "iphone 13",
"untranslatedTitle": "iphone 13",
"sku": "P-13",
"price": {
"amount": 3999,
"currencyCode": "HKD"
},
"image": {
"src": false
},
"product": {
"id": "64",
"title": "iphone 13",
"untranslatedTitle": "iphone 13",
"url": "https://woo.test.attribuly.com/product/apple/",
"type": "simple",
"vendor": ""
}
}
}
],
"billingAddress": {
"firstName": "jie",
"lastName": "zhang",
"address1": "121212",
"address2": "",
"city": "212",
"province": "HONG KONG",
"provinceCode": "HONG KONG",
"zip": "1212",
"country": "HK",
"countryCode": "HK",
"phone": "1212"
},
"shippingAddress": {
"firstName": "jie",
"lastName": "zhang",
"address1": "121212",
"address2": "",
"city": "212",
"province": "HONG KONG",
"provinceCode": "HONG KONG",
"zip": "1212",
"country": "HK",
"countryCode": "HK",
"phone": "1212"
},
"currencyCode": "HKD",
"email": "xxx@xxxx",
"phone": "1212",
"order": {
"id": 78,
"customer": {
"id": 1,
"isFirstOrder": false
}
},
"totalPrice": {
"amount": 7998,
"currencyCode": "HKD"
},
"totalTax": {
"amount": 0,
"currencyCode": "HKD"
},
"totalShipping": {
"amount": 0,
"currencyCode": "HKD"
},
"subtotalPrice": {
"amount": 7998,
"currencyCode": "HKD"
},
"shippingLine": {
"price": {
"amount": 0,
"currencyCode": "HKD"
}
},
"discountsAmount": {
"amount": 0,
"currencyCode": "HKD"
},
"transactions": [
{
"amount": {
"amount": 7998,
"currencyCode": "HKD"
},
"gateway": "Cash on delivery",
"paymentMethod": {
"type": "Cash on delivery",
"name": "Cash on delivery"
}
}
]
}
});