Frequently Asked Questions
Powered By GitBook
Trigger Events Programmatically
How to programmatically trigger engagement & conversions events in AnyTrack.
Once you have added the AnyTrack tag on your webpage, a programmer can trigger programmatically any event via the following scripts:
1
<script>
2
// trigger an outbound click event
3
var click_id = AnyTrack('OutboundClick');
4
</script>
Copied!
The event name could be any standard event name AnyTrack supports:
  • PageView
  • OutboundClick
  • FormSubmit
  • Lead
  • CompleteRegistration
  • Purchase
The return argument is the event {click_id} as string (for example: MAbFl0fhrE5EfBu6fX0FnL02LfS), and it can be used later on to attribute conversion events.

Event Properties

If you want to send additional properties along with the event, you can do so following the below format:
1
<script>
2
AnyTrack('Purchase', {
3
id: 'my-link-id', // link id
4
url: 'https://apple.com/referral', // the target link url
5
label: 'iPhone X', // link label
6
brand: 'Apple', // product brand name
7
value: 2.99, // event monetary value / commission
8
currency: 'EUR', // optional currency (default to propery currency)
9
transactionId: 'XJW0047', // transaction id
10
});
11
</script>
Copied!
All fields are optional, but the data provided can be useful if you want to create your custom audiences with rich content.

Full Code Example

1
<button type="button" onclick="handleBuyMe">Buy Me</button>
2
​
3
<script>
4
// handle the button click event
5
function handleBuyMe() {
6
// generate the click id
7
var click_id = AnyTrack('OutboundClick', { label: 'Buy Me' });
8
9
// redirect the browser to the store location with the click id param
10
window.location = 'https://some-store.com/?sub1=' + encodeURIComponent(click_id);
11
}
12
</script>
Copied!

E-Commerce Support

AnyTrack supports e-commerce parameters to track purchase of specific item ids:
1
<script>
2
var click_id = AnyTrack('Purchase', {
3
value: 29.9, // the total purchase value
4
shippingPrice: 5.9, // optional shipping price
5
taxPrice: 2.9, // optional taxes
6
currency: 'EUR',
7
transactionId: 'XJW0047',
8
items: [{
9
id: '20291', // the item catalog id (required)
10
name: 'Sony MDRZX110/BLK ZX Series Stereo Headphones',
11
quantity: 1,
12
price: 19.9, // the item price (required)
13
}, {
14
id: '49292', // the item catalog id (required)
15
name: '6.35mm Male to 3.5mm Female Headphone Stereo Audio Connector',
16
quantity: 1,
17
price: 4.1, // the item price (required)
18
}],
19
});
20
</script>
Copied!
Last modified 7mo ago