$p("track"): (Object) -> undefined
Technical documentation
This is technical documentation for the track function. For more information on the general context surrounding the use of tracking, see Tracking Widgets.
Tracking function takes in DOM elements and attaches an event listener/marker for any anchors on them. It also appends tags on the anchor's href. Tracked behavior such as "widget_click" is used by our system as a user feedback so it is important to implement the tracking correctly.
Argument | Type | Description |
---|---|---|
elements | DOM/DOM Array | DOM element(s) that contains the recommended items. |
name | String | Name of the widget where the recommendation will be rendered. "default_widget" is the name for a default widget. |
source | String | Name of the source that's providing the recommendation. Use "LI" for LiftIgniter and "base" for an algorithm that it's being compared against. You can add more algorithms with different names but they won't show up on the realtime tab of the lab right away. |
tagPrefix | String | Prefix of tag to be added to URL that's being tracked. |
A generic example of tracking will be:
$p("track", {
elements: document.querySelectorAll("ITEM_SELECTOR"),
name: "WIDGET_NAME", // Usually Widget name
source: "LI" // Name of recommendation source
})
With the tagPrefix:
$p("track", {
elements: document.querySelectorAll("ITEM_SELECTOR"),
name: "WIDGET_NAME", // Usually Widget name
source: "LI", // Name of recommendation source
tagPrefix: "utm"
})
tagPrefix changes the prefix of URL tag that's appended to href of anchor being tracked. For example, without the tagPrefix, the default value is set to "li", meaning that the tag parameters will look like the following:
li_medium=WIDGET_NAME&li_source=LI
However, with the tagPrefix "utm", this will change to the following:
utm_medium=WIDGET_NAME&utm_source=LI
Removing the anchor tag
Sometimes, you may not want to include our tags in the URL for various reasons - you might think it looks bad, or it affects the caching on your backend so you want it removed. You can use
$p("setNoTag")
(see the documentation) or set the configuration using$p("init")
.