Advanced Event Tracking

Learn how to set up custom triggers in AnyTrack to track advanced user interactions on your website.

AnyTrack.io provides a variety of advanced tracking methods to help you optimize your Return on Ad Spend (ROAS) and get the most out of your digital marketing campaigns. This article consolidates several methods including triggering events based on element visibility, triggering a webhook via JavaScript, tracking time on site, and triggering events on specific DOM elements.

❗️

Attention!

Please note that you must be familiar with JavaScript, HTML, and CSS to use these tracking snippets. If you're not familiar with all of these coding languages, please forward the article to a developer.

🚧

Reminder:

The AnyTrack Tag must be present in the head section of your site before any of the snippets can be activated.

Web Events Tracking

To track web events through Client Side Tracking you should use the following Snippet.

// trigger an lead event
var click_id = AnyTrack('trigger', 'Lead');

The snippet accepts standard Event Attributes which are used to provide contextual information about the event.

By default attributes such as the page, location, path are collected as well as the first party data such as the Google Analytics Client ID, or the Facebook Cookies.

Once an event is tracked, it is automatically forwarded through Server Side API to your connected Conversion API.

An OutboundClick event will look like this:

{
  "cid": "TZRImeinAR5B1V",
  "ts": 1686737927708,
  "pt": 1686737861561,
  "en": "OutboundClick",
  "dl": "https://readme.anytrack.io/docs/autotag",
  "dt": "AutoTag",
  "cp": [
    {
      "type": "ga",
      "id": "UA-143868881-3",
      "clientId": "1906187177.1686711792"
    },
  ],
  "id": "kv0bmJw0",
  "tgid": "calendly",
  "link": {
    "id": "content-container",
    "label": "Calendly Link.",
    "url": "https://calendly.com/anytrack/"
  }
}

The Event Tracking snippet can be combined with more advanced commands that we list below:

Trigger an Event for Element Visibility

AnyTrack enables you to trigger custom events that match your specific campaign needs using the tracking script. You can trigger an event when an element is visible to the "viewport". This function is called onViewport.

AnyTrack("onViewport", "#my-button", function() {
    AnyTrack("trigger", "ViewButton");
});

Trigger a Webhook via a JavaScript Tag

You can use JavaScript to trigger a webhook and send conversion data to AnyTrack.io for improved ROAS and better tracking of custom conversions.

🚧

Requirements:

  • Create a Custom Conversions source.
  • Get the Postback URL and insert it instead of the postback URL below.
AnyTrack('postback', 'https://t1.anytrack.io/xxxxx/collect?click_id={click_id}', {
    brand_name: 'bar',
    commission: 59.99,
    transactionId: 'asfasdf'
});

👍

Pro tip:

Enrich the event with additional attributes such as customer data, product data, currency. Check the list of Event Attributes.

Track Time on Site

The time a visitor spends on your site can give you a good indication of your content's value or the quality of your traffic. To trigger a "time on site" Event, you can use the function setTimeout.

setTimeout(function() {  
  AnyTrack('trigger', 'LongVisit');  
}, 10e3);

Trigger Events on DOM Element visibility

You can add to each HTML element an onclick attribute that will trigger an event when a user clicks on the element.

<button onclick="AnyTrack('trigger', 'click')">View Details</button>

Disable tracking for specific pages

Add the following snippet in the head section of the pages you don't want to track.

  AnyTrack('quiet');

Disable Tracking for specific elements

The AutoTrack function automatically finds and triggers OutboundClick and FormSubmit events on your website. In most cases, this is the desired behavior, but you may want to disable the AutoTrack in some sections of your website while leaving it active on the rest of the page.

Add class="at-do-not-track" on specific elements or on a container to disable tracking for all elements within this class.

<a href="https://clickfunnels.com" class="at-do-not-track">UNTRACKABLE LINK</a>