Events from code.
On a custom-built website you send events with optimads.track(). Each event goes to the pixels in the browser and from our server with the same code, so it is counted only once.
What you need
- The Optimads code placed in
<head>, on every page. See Any other website.
Syntax
JavaScript
optimads.track('EventName', { /* fields */ });The script loads asynchronously. If you send an event before window.optimads exists, put it in the queue. The queue empties on its own when the script starts:
Before the script loads
window.__oaQ = window.__oaQ || [];
__oaQ.push(['Lead', { content_name: 'Quote request' }]);Standard events
These are sent both from the browser and from the server:
| Event | When you send it |
|---|---|
PageView | Automatically, don't send it yourself. |
ViewContent | A product page. |
AddToCart | A product added to the cart. |
InitiateCheckout | The start of checkout. |
AddPaymentInfo | The payment method chosen. |
Purchase | The order placed, only once. |
Lead | A request sent successfully. |
CompleteRegistration | An account created. |
Subscribe | A newsletter signup. |
Contact | Automatically, on a click on phone, email, WhatsApp. |
Search | A search on the site. |
Any other name goes only to the pixels in the browser. To send it from the server too, make it a custom action of the “From code” type.
Fields
| Field | What you put |
|---|---|
value | The value, as a number: 249.90. |
currency | The 3-letter currency code: RON, EUR. |
order_id | The order number. |
content_ids | The product IDs, as a list: ['SKU-1']. |
contents | The products, with quantity and price: [{ id, quantity, item_price }]. |
content_name | The name of the product or of the form. |
content_category | The category. |
num_items | The number of products. |
search_string | The search text, for Search. |
To match the buyer, you can also send em (email), ph (phone), fn, ln (first name, last name), ct (city), country. We turn them into code (a hash) on the server, and the browser pixel doesn't receive them.
Examples
Product page
optimads.track('ViewContent', {
content_ids: ['SKU-1'],
content_name: 'Black T-shirt',
value: 89,
currency: 'RON'
});Thank-you page
optimads.track('Purchase', {
value: 249.90,
currency: 'RON',
order_id: '10234',
contents: [{ id: 'SKU-1', quantity: 2, item_price: 89 }],
em: 'client@exemplu.ro',
ph: '0722123456'
});Form sent
optimads.track('Lead', { content_name: 'Quote request' });Purchase, only once per order. Don't send it every time the thank-you page reloads. On connected stores (Shopify, WooCommerce, Gomag, MerchantPro, PrestaShop) you don't need to send it at all: the real order is sent from the server.
Stuck?Send us your website address and the step you're on. We'll help you.
contact@optimads.ai