
Sometimes you need more control over which events get triggered on your website and when. AnyTrack TAG supports trigger standard and custom events programmatically as needed.
⚠ Please note: Trigger custom events requires HTML and JavaScript skills. Please contact a web developer if you don’t feel comfortable doing that yourself.
📹 Tutorial video - how to trigger events via Javascript in AnyTrack
Trigger a standard event
You can use the following command to trigger a standard AnyTrack event, for example “OutboundClick”:
<script>
// trigger an outbound click event
var click_id = AnyTrack('trigger', 'OutboundClick');
</script>
A standard event is any event name from the following list:
- PageView
- OutboundClick
- FormSubmit
- AddToCart
- Lead
- InitiateCheckout
- CompleteRegistration
- Purchase
The return argument is the event {click_id}
as a string (for example: MAbFl0fhrE5EfBu6fX0FnL02LfS
), and it can be used later on to attribute conversion events on your postback URLs.
Trigger custom event names
If you need more flexibility on the naming convention for your events, you can use custom event names using the following command:
<script>
var click_id = AnyTrack('trigger', 'ViewOffer');
</script>
Please remember to configure the custom name on the Event Mapping for each pixel as well:
Example: Trigger event on button click
<button type="button" onclick="handleBuyMe">Buy Me</button>
<script>
// handle the button click event
function handleBuyMe() {
// generate the click id
var click_id = AnyTrack('trigger', 'OutboundClick');
// redirect the browser to the store location with the click id param
window.location = 'https://some-store.com/?sub1=' + encodeURIComponent(click_id);
}
</script>
Additional event parameters
It’s possible to send additional parameters on your custom events, such as value or transaction id. See here the full list of supported parameters:
<script>
AnyTrack('trigger', 'Purchase', {
value: 2.99, // event payout / commission
currency: 'EUR', // optional currency (default to properly currency)
transactionId: 'XJW0047', // transaction id
});
</script>
Comments
0 comments
Please sign in to leave a comment.