
Using the AutoScan, AnyTrack crawls all your website pages and finds all the elements you may want to track. You can then select each element from the scan result and assign it a custom conversion event. You can learn more about the AutoScan here.
If you can't find the element you're looking for via the AutoScan, you may ask a developer to trigger a custom event for you according to your needs. For convenience, we attached below some code samples that can be used when triggering those events.
Trigger Events On-Click
You can add to each HTML element an onclick
attribute that will generate an event for you every time a user click on that element.
For example, the following will trigger a Lead event every time a use clicks on the "View Details" button:
<button onclick="AnyTrack('trigger', 'Lead')">View Details</button>
Trigger Events on Specific Element Classes
You can use the following code to find and trigger an event for all HTML elements matching a specific CSS class name:
<script>
AnyTrack(function() {
document.querySelectorAll('div.my-class').forEach(function(elm) {
elm.addEventListener('click', function() {
AnyTrack('trigger', 'MyEventName');
});
});
});
</script>
If those elements only existing after a certain time or after the user make an action (ie. on a popup modal) you can use the following code to keep searching for those elements every a few hundreds milliseconds:
<script>
setInterval(function() {
document.querySelectorAll('div.my-class').forEach(function(elm) {
if (elm.tracked) return;
elm.tracked = 1;
elm.addEventListener('click', function() {
AnyTrack('trigger', 'MyEventName');
});
});
}, 800);
</script>
Comments
0 comments
Please sign in to leave a comment.