Custom JS snippet
Admin users may override certain behaviors of the Recurly Engage JavaScript SDK by supplying custom fetchUserId
and fetchAnonUserId
functions.
Overview
Required plan
This feature or setting is available to all customers on any Recurly Engage subscription plan.
Prerequisites & limitations
- You must have Company or App Administrator permissions in Recurly Engage.
- Familiarity with your site’s user identification (localStorage, cookies, dataLayer).
Definition
The Custom JS Snippet feature lets you override the default user‐identification logic in the Recurly Engage JavaScript SDK by providing your own implementations of:
fetchUserId()
(required): returns the authenticated user’s ID.fetchAnonUserId()
(optional): returns the anonymous user’s ID if your app generates one.
Key benefits
- Accurate user matching: Tie prompts and 1-click actions to your existing user IDs.
- Seamless integration: Use any client-side storage (cookies, local/sessionStorage, dataLayer).
- Enhanced reporting: Ensure downstream analytics and connector actions receive the correct user identifiers.
Key details
Admin users may override certain behaviors of the Recurly Engage JavaScript SDK. Upon deploying Recurly Engage for the first time, it is important to review and configure the following functions to ensure that users are recognized using your unique identifiers. These identifiers will be utilized for 1-click actions as well as downstream reporting.
You may need to work with your developers to determine the best method to identify users. The most common methods to retrieve a User ID are:
- localStorage or sessionStorage item
- browser cookie
- accessing an item stored in the browser’s dataLayer
Reach out to Recurly Engage Support if you need assistance.
FetchUserID (required)
This function is invoked to determine a user’s authenticated User ID when the Recurly Engage JS tag is loaded.
static fetchUserId() {
if( localStorage.getItem("ajs_user_id" )
return JSON.parse(localStorage.getItem("ajs_user_id"));
return null;
}
FetchAnonymousUserID (optional)
This function is invoked to determine a user’s anonymous User ID (if generated by your web app). If your web app does not generate an anonymous User ID, Recurly Engage will automatically assign one to unauthenticated users.
static fetchAnonUserId() {
if( localStorage.getItem("ajs_anonymous_id" )
return JSON.parse(localStorage.getItem("ajs_anonymous_id"));
return null;
}
Updated about 7 hours ago