Understanding Lytics / Product Documentation / Lytics Javascript Tag

Receiving Profile Data

In addition to collecting behavioral data related to a users visit, the Lytics JavaScript tag also can be configured to delivery real-time profile information back to the browser for a single user. By default, Lytics will only return the current audiences a visitor is a member of. However, through field white-listing, managed by Lytics Customer Support, additional fields can be returned for a user. Information such as product id for items left in a users cart, car model, userid, and an infinite number of other general or brand specific fields open up game changing personalization opportunities.

Getting the User's Profile

Once the Lytics JavaScript tag has initialized you can access the current user's profile by calling window.lio.data. The response will contain the slugs of the audiences a user is currently a member of and any white-listed fields. For example:

{
  "email": "[email protected]",
  "segments": [
    "all",
    "employees",
    "known_users"
  ]
}

Keep in mind, only audiences that have been marked as Enable API Access will be surfaced to the browser. In the example above you'll see an example of a white-listed field, email, that is not normally returned as well as the array of audiences.

Create a Callback

In practice, calling window.lio.data is not recommended as it assumes the entity has been loaded. Since this process is asynchronous we recommend always registering a callback to get a users entity from the JavaScript tag. Our callbacks are fired when the users profile is returned or immediately on registration if the profile has already been loaded.

To initialize a callback add the custom parameter handler:

<script type="text/javascript">
  !function (l, a) { a.liosetup = a.liosetup || {}, a.liosetup.callback = a.liosetup.callback || [], a.liosetup.addEntityLoadedCallback = function (l, o) { if ("function" == typeof a.liosetup.callback) { var i = []; i.push(a.liosetup.callback), a.liosetup.callback = i } a.lio && a.lio.loaded ? l(a.lio.data) : o ? a.liosetup.callback.unshift(l) : a.liosetup.callback.push(l) } }(document, window);
</script>

Followed by the registration of your callback function. Of course, in practice these two lines of JS can exist within the same <script> tag.

<script type="text/javascript">
  window.liosetup.addEntityLoadedCallback(function (data) {
    console.log(data.segments);
  });
</script>

Customization Options

When it comes to customization there are a lot of options. If you do not see what you are looking for please reach out to your support representative. Lytics prides itself on flexibility and is happy to work with you on identifying the best approach for your use case.

Custom User Identifier

In some cases it is desired to use an identifier different than the Lytics cookie, userid for a logged in user for example. Doing so is as simple as once again ensuring the custom parameter handler has been initialized just as it was before the callback. Note: this only needs to be done once, not before each call.

Then you will need to set a field name, which refers to the name of the Lytics field you are matching against and a value, such as the actual user id.

<script type="text/javascript">
  !function (l, a) { a.liosetup = a.liosetup || {}, a.liosetup.callback = a.liosetup.callback || [], a.liosetup.addEntityLoadedCallback = function (l, o) { if ("function" == typeof a.liosetup.callback) { var i = []; i.push(a.liosetup.callback), a.liosetup.callback = i } a.lio && a.lio.loaded ? l(a.lio.data) : o ? a.liosetup.callback.unshift(l) : a.liosetup.callback.push(l) } }(document, window);
</script>
<script type="text/javascript">
    window.liosetup.field = "userid";
    window.liosetup.value = "myactualuserid";
</script>

When using custom identifiers it is important that the above information is loaded prior to loading the core Lytics tag as the profile is only requested once and will default to _uid if another parameter has not been set.