Code Examples | Yext Hitchhikers Platform
Below we list some code examples to help you customize the guide to your specific situation. If you need guidance on what to do for your site, please post in the Community!
Using Multiple Visitor Methods
You may have a case where not all users will be identified in the same way. For example, users may still be able to use your search experience even if they haven’t logged in, so you’ll use the login for some users and a cookie for others.
Below is an example of a subdomain integration that creates the visitor object using:
- The user ID from local storage if the user is logged in or
The Yext conversion tracking cookie if the user is not logged in.
/* insert code to retrieve and generate cookie */ let user_id = window.localStorage.getItem("visitor"); if (user_id) { var visitor = { "id": JSON.parse(user_id)["id"], "idMethod": "USER_AUTH" }; AnswersExperience.runtimeConfig.set('visitor', visitor); } else if (getCookie("_yfpc") != null) { var visitor = { "id": getCookie("_yfpc"), "idMethod": "YEXT_CONVERSION_TRACKING_COOKIE" }; AnswersExperience.runtimeConfig.set('visitor', visitor); } AnswersExperience.init();
Feedback
<% elem.innerText %>