Leveraging User Geolocation in Sitecore CDP for Enhanced Analytics
The Sitecore Customer Data Platform (CDP) is equipped with a robust GeoLocation service that plays a crucial role in enhancing the user experience and providing valuable insights for businesses. This service automatically determines and stores the geolocation data associated with each user session. The geolocation information is comprehensive, encompassing details such as the user's country, city, region, and continent. This data can be incredibly useful for various purposes, including analytics, exporting user information, or implementing specific conditions in the Decision Model.
Understanding GeoLocation Data Storage in Sitecore CDP
Before we delve into how to retrieve and utilize this information, it's important to understand where and how it is stored within Sitecore CDP. Every time a user accesses a website or a mobile application, a new session is initiated for that user in Sitecore CDP. This session is equipped with a data extension labeled as `bxt`. It is within this extension that the current geolocation of the user is meticulously recorded.
The data stored in `bxt` enables businesses to gain a better understanding of their audience's geographical distribution. This can provide insights into regional trends, help tailor marketing strategies, offer localized content, and enhance overall user engagement.
Tip: As you can see session 'dataExtensions' contains UTM information, so you can easy extract it exact the same way.
Retrieving User Geolocation
In our scenario, the goal is to determine the user's most recent (or current) geolocation. Achieving this involves identifying the most recent WEB session associated with the user and extracting the geolocation details from this session. This process ensures that the information is up-to-date and reflective of the user's current location.
Streamlining the Process with a JavaScript Module
To streamline the retrieval of geolocation data and avoid code duplication, we can develop a custom JavaScript (JS) Module. By encapsulating the logic for fetching geolocation data, we create a reusable asset that simplifies the development process and ensures consistency across different parts of the application.
The implementation of the JS Module involves writing a script that accesses the `bxt` data extension within the user's session and retrieves the necessary geolocation details. Here’s a conceptual overview of what the implementation might involve:
function GeoLocation() {
var location = {
city: '',
region: '',
country: '',
continent: ''
};
if (guest.sessions) {
for (var i = 0; i < guest.sessions.length; i++) {
if (guest.sessions[i].sessionType == "WEB") {
var session = guest.sessions[i];
if (session.dataExtensions && session.dataExtensions.length > 0) {
for (var j = 0; j < session.dataExtensions.length; j++) {
if (session.dataExtensions[j].name == "bxt") {
var values = session.dataExtensions[j].values;
if (values['geoLocationCity']) {
location.city = values.geoLocationCity;
}
if (values['geoLocationRegion']) {
location.region= values.geoLocationRegion;
}
if (values['geoLocationCountry']) {
location.country = values.geoLocationCountry;
}
if (values['geoLocationContinent']) {
location.continent = values.geoLocationContinent;
}
return location;
}
}
}
}
}
}
return location;
}
Once the JS Module is implemented, it must be saved and published to ensure it is available for use across the application.
Utilizing the JS Module within the Decision Model
To leverage the functionality of the JS Module within the Decision Model, you need to integrate it into a Programmable node. This process involves creating a node that allows for the execution of custom JavaScript code, thus enabling dynamic decision-making based on geolocation data.
- Create a Programmable Node: Start by setting up a node within your Decision Model that supports custom JavaScript execution.
- Integrate the JS Module: Connect the previously created JS Module to this node by including it from the JS modules library. This ensures that the module's functionality is accessible within the Decision Model.
- Invoke the Function: With the JS Module integrated, you can now call the `GeoLocation` function from the node to retrieve and use the geolocation data as needed.
- Testing and Validation: After setting up the JS Module and integrating it into the Decision Model, it's crucial to test the implementation. Verify that the geolocation data is being accurately retrieved and utilized within your application's logic. This testing phase ensures reliability and helps identify any potential issues.
Audience Export
Exact the same way you can retrieve customer geolocation for Audience export:
Conclusion
By following these steps, you create a seamless process for accessing and using geolocation data in Sitecore CDP. This enhances the ability to deliver personalized experiences to users based on their geographic location, ultimately contributing to more effective engagement and improved business outcomes.