Depending on how you integrate LiftIgniter, you may want to manually set the user identifier to a form that you can recognize. For example, if you are using LiftIgniter on both mobile and web, then you want to set the user ID on the web side to match the user when he/she is on mobile so that our system can recognize that it's the same person. Using this function does require that you have a way to pull the userID value from your own system in order to populate the "USER_ID" argument.
We generally recommend using this function once a user has logged in or signed up for your service or platform, and is extremely useful if you are looking to implement our On-Open Email Recommendations.
Run the function after $p("init") and before the $p("send") on the JavaScript beacon. This will change the randomly generated UUID on LiftIgniter to a user identifier that you have specified.
//Function to retrieve USER_ID value from your own system // ... Main Beacon code $p("init", "JS_KEY"); $p("setUserId", "USER_ID"); // USER_ID should be a string. $p("send", "pageview");
Making use of existing user data
$p("setUserId") additionally takes an optional second parameter that specifies the method by which the user data for the specified userId is backfilled by the user data for the randomly generated UUID already in use. This is especially helpful if you have an existing integration which relies on randomly generated userIds and later decide to switch to using a customer-specified userId, as it minimizes the loss of user activity history tracked by LiftIgniter. We currently support the following two methods:
Method replaceIfEmpty (this is the generally preferred method)
When "replaceIfEmpty" is specified as the method, the user data associated with the new userId is set to the user data associated with the old userId only if LiftIgniter doesn't have any record of the new userId being used. This prevents accidental override of accumulated user data and hence we recommend using this over "replace" in most cases. It also means that if users switch devices after a while, then the small amount of behavior on the new device before logging in does not overwrite the much larger amount of data they had accumulated on their original device.
// This statement should be used in lieu of $p("setUserId", "USER_ID") in the code example above $p("setUserId", "USER_ID", "replaceIfEmpty");
Method replace (this is selectively needed when there are multiple sources of differing quality and we want one source to get preference)
When "replace" is specified as the method, the user data associated with the new userId is unconditionally set to the user data associated with the old userId, even if an entry for the new userId exists. This is useful when the user data for the new userId may be populated by multiple sources (e.g., mobile and Web, sites under two different domains) and you don't want the data from a lower quality source to prevail. In such cases, we recommend using "replace" on the highest quality source and "replaceIfEmpty" on other sources.
// This statement should be used in lieu of $p("setUserId", "USER_ID") in the code example above $p("setUserId", "USER_ID", "replace");