The LiftIgniter tracking function is the most critical part of any integration, and is a significant development time saver as it automates the tracking of key widget events. It 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.

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 appear in the LiftIgniter Console right away.

tagPrefix (optional)
String
Prefix of tag to be added to URL that's being tracked.


Invoking $p("track")

In a purely Javascript integration, $p("track") should be invoked in the callback of $p("register") and after $p("render"). This ensures that the items recommended by LiftIgniter have been returned and displayed on the page before the tracking is added. Calling the track function before that can lead to incorrect tracking, or missing widget events, because it will be tracking the overwritten URLs instead of the items actually displayed.


In a hybrid integration, you can call $p("track") by itself, but you'll still need to make sure that the recommended items are displayed before the track function is invoked.


Using tagPrefix

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


CAUTION! Using "utm" tags in your URLs will significantly affect the pages/session calculations done by Google Analytics.

An important thing to remember if using UTM tags in your URLs: every time a user visits a page with UTM tags, Google Analytics starts a new session for that user. Therefore, if you are interested in doing a pages/session calculation, you should not add UTM tags in internal links. For more, see here.


Track function with utm tagPrefix

$p("track", {
  elements: document.querySelectorAll("ITEM_SELECTOR"),
  name: "WIDGET_NAME", // Usually Widget name
  source: "LI", // Name of recommendation source
  tagPrefix: "utm"
})