DocumentationTarget Developer Guide

adobe.target.trackEvent(options)

Last update: July 17, 2023
  • Topics:
  • at.js

CREATED FOR:

  • Developer

This function fires a request to report user actions, such as clicks and conversions. It does not deliver activities in the response.

These event-tracking mbox calls can then be used to define metrics in activities. For more information, see Success Metrics and Track Conversions.

Here are the API details:

KeyTypeRequiredDescription
mboxStringYes

Mbox name

Note: If a trackEvent() call is fired with an mbox name that has already fired on the page, the SDID of trackEvent() is reset and will be different than the Target calls on the page. However, firing a trackEvent() call with a different mbox name keeps the trackEvent() call’s SDID consistent with the Page Load Request/triggerView() calls on the page.

selectorStringNoCSS selectors used to find the HTML elements. The event listeners will be attached to found elements.
typeStringNoRepresents a registered event type. It can be both HTML known events like: click, mousedown ,etc., as well as custom HTML events.
preventDefaultBooleanNo

Indicates whether to use event.preventDefault() in the event listener callback. Defaults to false.

Note: Only form[submit] and a[click] are supported. Other scenarios are not supported due to complexity and huge amount of scenarios to support.

paramsObjectNo

Mbox parameters. An object of key-value pairs that has the following structure:

{ "param1": "value1", "param2": "value2"}

timeoutNumberNo

Timeout in milliseconds.

If not specified, default value is used:

...timeoutInSeconds: 0.15...}

successFunctionNoA callback function used to signal that event has been reported.
errorFunctionNoA callback function used to signal that event could not be reported.

Example

<a href="https://asite.com">click me!</a>

plus javaScript code to assign trackEvent:

<script>
$('a').click(function(event){
  adobe.target.trackEvent({'mbox':'homePageHero'})
});
</script>

Or:

adobe.target.trackEvent({
    "mbox": "clicked-cta",
    "params": {
        "param1": "value1"
    }
});
WARNING
If the mandatory fields are not set, no request is executed, and an error is thrown.
recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3