Overview
Personalize APIs are a collection of endpoints that may be accessed from your website's code. These APIs offer personalization capabilities and must be invoked from your codebase for MoEngage to provide relevant data. After receiving the data, you can use the same within your website's code to personalize the content for your users.
Benefits of server-side testing
-
Speed & User Experience: If enhancing load times is a priority, server-side tests are most beneficial. They have quicker loading times than client-side experiments because they handle the variation before the page is sent from the server, eliminating any delay in page rendering that could occur with client-side testing. It avoids the flickering effect that sometimes happens in client-side testing when changes are made during or after the page load.
-
Complex Experiments: If you want to conduct a complex experiment that involves testing different algorithms, back-end processes, or core business logic, server-side testing would be the right choice. This could include things like testing a new recommendation algorithm for products or articles or trying out new pricing logic or a new checkout flow.
-
SEO-Friendly: As the content is rendered at the server level and sent to the client’s browser, server-side testing is more SEO-friendly than client-side testing. The changes made through server-side testing will be properly indexed by search engines.
-
Security: Server-side testing is more secure as the logic resides on your server, not on the client's browser. It's ideal for testing sensitive areas, like payment processing or account login that require additional security measures.
-
Consistency Across Devices: If you wish to ensure that your experiment doesn't get affected by the user's device or browser limitations, server-side testing is the best bet. This is especially useful if you're aiming for a uniform user experience across different devices, browsers & platforms like Website, Mobile or TV App & more.
When to use Server-side experimentation
While Server-side testing offers a powerful methodology to run intricate experiments at a deep level, there are several factors to consider before deciding if it’s the right approach for your requirements:
-
Technical Expertise: Server-side testing generally requires a higher level of technical knowledge than client-side testing, as modifications need to be made to the server-side code. Hence, you would need access to proficient developer resources and support.
-
Cost: Server-side testing generally demands more development time and resources compared to client-side alternatives.
-
Speed of experimentation: If you need to conduct rapid iteration tests and observe quick results, client-side testing could be more beneficial due to its higher implementation speed.
Fetch Experience
Use the Fetch endpoint to receive data on active personalization experiences. You can fetch data for one or more server-side experiences by using the experience-key field. MoEngage will evaluate targeting rules and in-session attributes automatically and return the correct variation for the user. Typically, you would make this call as part of your larger page and content rendering pipeline.
POST https://sdk-0X.moengage.com/v1/experiences/fetch
The 'X' in the API Endpoint URL refers to the MoEngage Data Center (DC). MoEngage hosts each customer in a different DC. You can find your DC number (value of X) and replace the value of 'X' in the URL by referring to the DC and API endpoint mapping here.
Authentication
The API request will be authenticated through Basic Authentication. Basic Authentication sends a Base64-encoded string containing your username and password with every API request. It encodes a 'username: password' string in Base64 and appends the encoded string with 'Basic '. This string is included in the authorization header as shown below:
{"Authorization":"Basic bmF2ZWVua3VtYXI6bW9lbmdhZ2U="}
The username and password details can be obtained from the MoEngage Dashboard.
-
Navigate to Settings -> Account -> APIs.
-
Click the Copy icon in the Personalize tile in the API Keys section to copy the API Key.
-
Use the Workspace ID as the username and the Personalize API Key as the password to generate the authentication header.
Regenerate API SECRET
The API SECRET can be regenerated on the MoEngage Dashboard in the Personalize API Settings section discussed above.
Please DO NOT regenerate the key unless there is a security breach. Once you generate a different API SECRET KEY and save it, API calls using the older SECRET KEY won't work.
Request Headers
Key |
Sample Values |
Description |
---|---|---|
MOE-APPKEY |
{"MOE-APPKEY": "Workspace ID"} |
This is the Workspace ID of your MoEngage account and needs to be passed along with the request. You can find your MoEngage Workspace ID in the MoEngage Dashboard API Settings. For more information, refer to Authentication. |
Authorization |
{"Authorization": "Basic bmF2ZWVua3VtYXI6bW9lbmdhZ2U=="} |
This authentication parameter, used for access control, must be passed along with the request. To generate the authentication header, refer to Authentication. |
Content-Type |
application/JSON |
Set the Content-Type header to application/JSON for using the Personalize API. |
Request Body
Key |
Mandatory |
Value |
Description |
---|---|---|---|
customer_id |
No |
String |
Your brand provides this field, which should be pasted in the request. Generally, this is the phone number, email ID, or any other unique ID used to uniquely identify the user in MoEngage. This is essential for fetching experiences that are configured for audiences segmented based on user attributes/user behavior/user affinity/custom segments. . |
experience_key |
Yes |
String |
This field uniquely identifies each server-side experience created using MoEngage Personalize. You can pass multiple values in a single request and receive the personalized content defined for each experience in the response. |
DAY_OF_THE_WEEK |
No |
String |
This field must contain the day of the week for evaluating IN-session attribute-based experiences. Accepted values - Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday |
TIME_OF_THE_DAY |
No |
String |
This field must contain the time of the day for evaluating IN-session attribute-based experiences. |
USER_IP_ADDRESS |
No |
String |
This field must contain the user’s IP address to fetch experiences for audiences segmented basis geo-location. |
USER_AGENT |
No |
String |
This field must contain the USER-AGENT HTTP header. |
Sample Requests
curl --location 'https://sdk-0X.moengage.com/v1/experiences/fetch' --header 'Accept: */*' --header 'Content-Type: application/json' --header 'Authorization: Basic RE1RNjFOVk0xQjJKRUs4VVNCUzFIMUNPOlVMWkI1Z3JUTTRRWmJJU0RsOFFEM0c2Vw==' --header 'MOE-APPKEY: <Your Workspace ID>' --data '{ "customer_id": "<unique user identifier like email or phone number. Eg: john@example.com>", "visitor_id": "ID generated by MoEngage for an anonymous user", "experience_key": ["<experience key>"], "Custom_attribute":"Attribute Value. Example: utm_medium: email", "DAY_OF_THE_WEEK": "Day of the week as a string in format: Monday, Tuesday etc.", "TIME_OF_THE_DAY": "Time of the day as string: 00,01,02,..,23", "USER_IP_ADDRESS": "IP address for location based experiences", "USER_AGENT": "Copy the USER-AGENT http header from the request" }'
import fetch from 'node-fetch';
var result = await fetch('https://sdk-0X.moengage.com/v1/experiences/fetch', {
method: 'POST',
headers: {
'Authorization': 'Basic RE1RNjFOVk0xQjJKRUs4VVNCUzFIMUNPOlVMWkI1Z3JUTTRRWmJJU0RsOFFEM0c2Vw==',
'Content-Type': 'application/json',
'MOE-APPKEY: <Your Workspace ID>' },
body: JSON.stringify({
"customer_id": "<unique user identifier like email or phone number. Eg: john@example.com>",
"experience_key": ["<experience key>"],
"Custom_attribute":"Attribute Value. Example: utm_medium: email",
"DAY_OF_THE_WEEK": "Day of the week as a string in format: Monday, Tuesday etc.",
"TIME_OF_THE_DAY": "Time of the day as string: 00,01,02,..,23",
"USER_IP_ADDRESS": "IP address for location based experiences",
"USER_AGENT": "Copy the USER-AGENT http header from the request"
})
});
var data = await result.json()
console.log(data)
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
)
func main() {
client := &http.Client{}
var data = strings.NewReader(`{
"customer_id": "<unique user identifier like email or phone number. Eg: john@example.com>",
"experience_key": ["<experience key>"],
"Custom_attribute":"Attribute Value. Example: utm_medium: email",
"DAY_OF_THE_WEEK": "Day of the week as a string in format: Monday, Tuesday etc.",
"TIME_OF_THE_DAY": "Time of the day as string: 00,01,02,..,23",
"USER_IP_ADDRESS": "IP address for location based experiences",
"USER_AGENT": "Copy the USER-AGENT http header from the request"
}`)
req, err := http.NewRequest("POST", "https://sdk-01.moengage.com/v1/experiences/fetch", data)
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", "Basic RE1RNjFOVk0xQjJKRUs4VVNCUzFIMUNPOlVMWkI1Z3JUTTRRWmJJU0RsOFFEM0c2Vw==")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("MOE-APPKEY", "<Your Workspace ID>")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
bodyText, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s", bodyText)
}
<?PHP
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sdk-0X.moengage.com/v1/experiences/fetch');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization' = 'Basic RE1RNjFOVk0xQjJKRUs4VVNCUzFIMUNPOlVMWkI1Z3JUTTRRWmJJU0RsOFFEM0c2Vw==',
'Content-Type' = 'application/json',
'MOE-APPKEY' = '<Your Workspace ID>',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"customer_id": "<unique user identifier like email or phone number. Eg: john@example.com>","experience_key": ["<experience key>"],"Custom_attribute":"Attribute Value. Example: utm_medium: email", "DAY_OF_THE_WEEK": "Day of the week as a string in format: Monday, Tuesday etc.", "TIME_OF_THE_DAY": "Time of the day as string: 00,01,02,..,23", "USER_IP_ADDRESS": "IP address for location based experiences", "USER_AGENT": "Copy the USER-AGENT http header from the request"}');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
curl_close($ch);
import requests
url = 'https://sdk-0X.moengage.com/v1/experiences/fetch'
headers = {
'Authorization': 'Basic RE1RNjFOVk0xQjJKRUs4VVNCUzFIMUNPOlVMWkI1Z3JUTTRRWmJJU0RsOFFEM0c2Vw==',
'MOE-APPKEY', '<Your Workspace ID>'
}
data = {
"customer_id": "<unique user identifier like email or phone number. Eg: john@example.com>",
"experience_key": ["<experience key>"],
"Custom_attribute":"Attribute Value. Example: utm_medium: email",
"DAY_OF_THE_WEEK": "Day of the week as a string in format: Monday, Tuesday etc.",
"TIME_OF_THE_DAY": "Time of the day as string: 00,01,02,..,23",
"USER_IP_ADDRESS": "IP address for location based experiences",
"USER_AGENT": "Copy the USER-AGENT http header from the request"
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
require 'net/http'
require 'json'
uri = URI('https://sdk-0X.moengage.com/v1/experiences/fetch')
req = Net::HTTP::Post.new(uri)
req.content_type = 'application/json'
req['Authorization'] = 'Basic RE1RNjFOVk0xQjJKRUs4VVNCUzFIMUNPOlVMWkI1Z3JUTTRRWmJJU0RsOFFEM0c2Vw=='
req['MOE-APPKEY'] = '<Your Workspace ID>'
# The object won't be serialized exactly like this
req.body = {
"customer_id": "<unique user identifier like email or phone number. Eg: john@example.com>",
"experience_key": ["<experience key>"],
"Custom_attribute":"Attribute Value. Example: utm_medium: email",
"DAY_OF_THE_WEEK": "Day of the week as a string in format: Monday, Tuesday etc.",
"TIME_OF_THE_DAY": "Time of the day as string: 00,01,02,..,23",
"USER_IP_ADDRESS": "IP address for location based experiences",
"USER_AGENT": "Copy the USER-AGENT http header from the request"
}.to_json
req_options = {
use_ssl: uri.scheme == "https"
}
res = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(req)
end
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class Main {
public static void main(String[] args) throws IOException {
URL url = new URL("https://sdk-0X.moengage.com/v1/experiences/fetch");
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Authorization", "Basic RE1RNjFOVk0xQjJKRUs4VVNCUzFIMUNPOlVMWkI1Z3JUTTRRWmJJU0RsOFFEM0c2Vw==");
httpConn.setRequestProperty("Content-Type", "application/json");
httpConn.setRequestProperty("MOE-APPKEY", "<Your Workspace ID>");
httpConn.setDoOutput(true);
String payload = "{
"customer_id": "<unique user identifier like email or phone number. Eg: john@example.com>",
"experience_key": ["<experience key>"],
"Custom_attribute":"Attribute Value. Example: utm_medium: email",
"DAY_OF_THE_WEEK": "Day of the week as a string in format: Monday, Tuesday etc.",
"TIME_OF_THE_DAY": "Time of the day as string: 00,01,02,..,23",
"USER_IP_ADDRESS": "IP address for location based experiences",
"USER_AGENT": "Copy the USER-AGENT http header from the request"
}";
httpConn.setDoOutput(true);
OutputStream os = httpConn.getOutputStream();
os.write(payload.getBytes());
os.flush();
InputStream responseStream = httpConn.getResponseCode() == HttpURLConnection.HTTP_OK
? httpConn.getInputStream()
: httpConn.getErrorStream();
BufferedReader br = new BufferedReader(new InputStreamReader(
(responseStream)));
String output;
while ((output = br.readLine()) != null) {
System.out.println(output);
}
httpConn.disconnect();
}
}
Response Body
Key |
Description |
---|---|
payload |
This field contains a list of all the key-value pairs defined as part of the experience |
value |
This field contains the value of the keys defined in the payload |
data_type |
This field contains the value of the keys defined in the payload |
experience_context |
This field returns a JSON object that is to be used for reporting pageviews/impressions and/or tracking clicks within the personalized experience. Refer here for more details |
Sample response
{
"experiences": {
"new-serverside-experience": {
"payload": {
"Title": {
"value": "Presenting MoEngage Server side personalization! ",
"data_type": "string"
},
"Image": {
"value": "https://cdn.pixabay.com/photo/2021/02/24/20/53/abstract-6047465_960_720.jpg",
"data_type": "string"
},
},
"experience_context": {
"cid": "65eae5738ea5032b0ef60138_F_T_WP_AB_2_P_0_AU_42D",
"experience": "Server Side Experience",
"moe_locale_id": "<id>",
"moe_variation_id": "<id>",
"audience_name": "<audience name>",
"audience_id": "<id>",
"type": "Web Personalization"
}
}
}
}
Response Codes
Status Code |
Request State |
Description |
---|---|---|
200 |
Success |
This response is returned when the request is submitted to MoEngage. |
400 |
Bad Request |
This response is returned in case the payload is empty or invalid. |
401 |
Authorization Failed |
This response is returned when the authorization fails due to incorrect values for the APP KEY/ HTTP Auth Header. |
500 |
Internal Server error |
This response is returned when the system runs into an unexpected error. You can try for a maximum of 3 times with exponential backoff. |
Reporting Impressions
With Server-side personalization, the experience is personalized on the server. You can use either the Report Impression API or the MoEngage Web SDK to report impressions
Using API (Recommended)
Applicable for all platforms, including website, mobile or TV app & more.
To report an impression for your campaign, use the API endpoint given below:
POST https://sdk-0X.moengage.com/v1/experiences/events
The 'X' in the API Endpoint URL refers to the MoEngage Data Center (DC). MoEngage hosts each customer in a different DC. You can find your DC number (value of X) and replace the value of 'X' in the URL by referring to the DC and API endpoint mapping here.
Authentication
Same method as the one used for the Fetch API endpoint described above.
Request Header
Key |
Sample Values |
Description |
---|---|---|
MOE-APPKEY |
{"MOE-APPKEY": "Workspace ID"} |
This is the Workspace ID of your MoEngage account, and it needs to be passed along with the request. You can find your MoEngage Workspace ID in the MoEngage Dashboard API Settings. For more information, refer to Authentication. |
Request Body
Key |
Mandatory |
Value |
Description |
---|---|---|---|
customer_id |
Yes |
String |
Your brand provides this field, which should be pasted in the request. Generally, this is the phone number, email ID, or any other unique ID used to uniquely identify the user in MoEngage. This is essential for event mapping back to the user. |
user_attributes
|
No |
JSON |
This field is used to update the details of a user identified by customer_id. |
user_timezone_offset |
No |
Numeric |
The difference in time between UTC and the local system time in a particular time zone. All time zones are defined by their offset from UTC. The offset is expressed as either UTC- or UTC+. user_timezone_offset should have a value in seconds, which can be between -54000 to 54000. For example, for IST (UTC+0530), "user_timezone_offset" will be 19800. |
action |
Yes |
String |
This field identifies the action or the event performed by the user. Accepted values MOE_PERSONALIZATION_MESSAGE_SHOWN MOE_PERSONALIZATION_MESSAGE_CLICKED |
actions |
Yes |
Array |
Multiple actions or events performed by a user can be grouped together in a single API call |
moe_event_uuid |
Yes |
String |
Unique identifier to be sent for each event to prevent duplication. |
event_time |
Yes |
Numeric (Epoch time in seconds) OR |
This field represents UTC time at which the event happened. |
platform |
Yes |
String |
This field represents the platform on which the user is shown the personalization event. If the values are missing, Unknown will be used. Accepted values
|
attributes |
Yes |
JSON |
This field is the experience context sent as part of the response to the Experience Fetch API request call. |
b_id |
No |
String |
This field can be used to uniquely identify click tracking events on multiple elements on a page. |
Sample Requests
For a user existing in MoEngage
curl --location --request POST 'https://sdk-0X.moengage.com/v1/experiences/events' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <Authorisation>' \
--header 'MOE-APPKEY: <Your APP Key>' \
--data-raw '{
"elements": [
{
"customer_id": "<unique user identifier like email or phone number. Eg: john@example.com>",
"user_timezone_offset": 19800,
"actions": [
{
"action": "MOE_PERSONALIZATION_MESSAGE_SHOWN",
"moe_event_uuid": "aa886712-4537-47c1-b126-2686efda2e26",
"event_time": 1725258666,
"platform": "web",
"attributes": {
"cid": "66d55ae445921e4d35ae4368_F_T_WP_AB_2_P_0_AU_5A",
"experience": "Test Server side experience",
"moe_locale_id": "0",
"moe_variation_id": "2",
"audience_name": "All Users",
"audience_id": "5A",
"type": "Web Personalization"
}
}
]
}
]
}'
}'
For a user new to MoEngage with a unique identifier
curl --location --request POST 'https://sdk-0X.moengage.com/v1/experiences/events' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <Authorisation>' \
--header 'MOE-APPKEY: <Your APP Key>' \
--data-raw '{
"elements": [
{
"customer_id": "john@example.com",
"user_attributes": {
"name": "John Doe",
"first_name": "John",
"last_name": "Doe"
}
"user_timezone_offset": 19800,
"actions": [
{
"action": "MOE_PERSONALIZATION_MESSAGE_SHOWN",
"moe_event_uuid": "aa886712-4537-47c1-b126-2686efda2e26",
"event_time": 1725258666,
"platform": "web",
"attributes": {
"cid": "66d55ae445921e4d35ae4368_F_T_WP_AB_2_P_0_AU_5A",
"experience": "Test Server side experience",
"moe_locale_id": "0",
"moe_variation_id": "2",
"audience_name": "All Users",
"audience_id": "5A",
"type": "Web Personalization"
}
}
]
}
]
}'
}'
For an anonymous user visiting the platform
curl --location --request POST 'https://sdk-0X.moengage.com/v1/experiences/events' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <Authorisation>' \
--header 'MOE-APPKEY: <Your APP Key>' \
--data-raw '{
"elements": [
{
"customer_id": "<identifier for the user for the session>",
"user_timezone_offset": 19800,
"actions": [
{
"action": "MOE_PERSONALIZATION_MESSAGE_SHOWN",
"moe_event_uuid": "aa886712-4537-47c1-b126-2686efda2e26",
"event_time": 1725258666,
"platform": "web",
"attributes": {
"cid": "66d55ae445921e4d35ae4368_F_T_WP_AB_2_P_0_AU_5A",
"experience": "Test Server side experience",
"moe_locale_id": "0",
"moe_variation_id": "2",
"audience_name": "All Users",
"audience_id": "5A",
"type": "Web Personalization"
}
}
]
}
]
}'
}'
Using MoEngage SDK
Applicable only for websites that have the MoEngage Web SDK integrated/
To report an impression for your campaign, use the below MoEngage SDK function
window.addEventListener("MOE_LIFECYCLE",function(e){
if(e.detail.name === "SDK_INITIALIZED"){
window.Moengage.web_p.trackImpression(experienceContext);}
})
experienceContext is a JSON object that is returned in the response to the Server-side experience Fetch call. Click here for more details.
Reporting Clicks
With Server-side personalization, the experience is personalized on the server. You can use either the Report Impression API or the MoEngage Web SDK to report impressions
Using API (Recommended)
Applicable for all platforms, including website, mobile or TV app & more.
The API Request to report clicks using APIs remains the same as the one to report impressions. The only change is to the value of the action field to MOE_PERSONALIZATION_MESSAGE_CLICKED.
POST https://sdk-0X.moengage.com/v1/experiences/events
Sample Requests
For a user existing in MoEngage
curl --location --request POST 'https://sdk-0X.moengage.com/v1/experiences/events' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <Authorisation>' \
--header 'MOE-APPKEY: <Your APP Key>' \
--data-raw '{
"elements": [
{
"customer_id": "<unique user identifier like email or phone number. Eg: john@example.com>",
"user_timezone_offset": 19800,
"actions": [
{
"action": "MOE_PERSONALIZATION_MESSAGE_CLICKED",
"moe_event_uuid": "aa886712-4537-47c1-b126-2686efda2e26",
"event_time": 1725258666,
"platform": "web",
"attributes": {
"cid": "66d55ae445921e4d35ae4368_F_T_WP_AB_2_P_0_AU_5A",
"experience": "Test Server side experience",
"moe_locale_id": "0",
"moe_variation_id": "2",
"b_id": "Add to Cart",
"audience_name": "All Users",
"audience_id": "5A",
"type": "Web Personalization"
}
}
]
}
]
}'
}'
For a user new to MoEngage with a unique identifier
curl --location --request POST 'https://sdk-0X.moengage.com/v1/experiences/events' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <Authorisation>' \
--header 'MOE-APPKEY: <Your APP Key>' \
--data-raw '{
"elements": [
{
"customer_id": "john@example.com",
"user_attributes": {
"name": "John Doe",
"first_name": "John",
"last_name": "Doe"
}
"user_timezone_offset": 19800,
"actions": [
{
"action": "MOE_PERSONALIZATION_MESSAGE_CLICKED",
"moe_event_uuid": "aa886712-4537-47c1-b126-2686efda2e26",
"event_time": 1725258666,
"platform": "web",
"attributes": {
"cid": "66d55ae445921e4d35ae4368_F_T_WP_AB_2_P_0_AU_5A",
"experience": "Test Server side experience",
"moe_locale_id": "0",
"moe_variation_id": "2",
"b_id": "Add to Cart",
"audience_name": "All Users",
"audience_id": "5A",
"type": "Web Personalization"
}
}
]
}
]
}'
}'
For an anonymous user visiting the platform
curl --location --request POST 'https://sdk-0X.moengage.com/v1/experiences/events' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <Authorisation>' \
--header 'MOE-APPKEY: <Your APP Key>' \
--data-raw '{
"elements": [
{
"customer_id": "<identifier for the user for the session>",
"user_timezone_offset": 19800,
"actions": [
{
"action": "MOE_PERSONALIZATION_MESSAGE_CLICKED",
"moe_event_uuid": "aa886712-4537-47c1-b126-2686efda2e26",
"event_time": 1725258666,
"platform": "web",
"attributes": {
"cid": "66d55ae445921e4d35ae4368_F_T_WP_AB_2_P_0_AU_5A",
"experience": "Test Server side experience",
"moe_locale_id": "0",
"moe_variation_id": "2",
"b_id": "Add to Cart",
"audience_name": "All Users",
"audience_id": "5A",
"type": "Web Personalization"
}
}
]
}
]
}'
}'
Using MoEngage SDK
Users engage with your webpage by clicking on the different links or CTAs present on it. Apart from measuring impressions, reporting clicks is important to gauge the success of your campaign and improve performance.
To report a click for your campaign, use the below MoEngage SDK function
window.Moengage.web_p.trackClick(experienceContext, extraAttributes);
experienceContext is a JSON object that is returned in the Response to the Server-side experience Fetch call. More details here.
experienceAttributes is a JSON object in which you can pass additional information about the link or the CTA which the user has interacted with.
{
"widget_id": "<alphanumeric value>"
}
Key | Description | Sample Values |
widget_id | This key is used to identify either a link or CTA uniquely. If the visitor clicks on the same link or CTA across multiple visits, ensure to send the same value for the link/CTA in each session | AlphaNumeric value. |
Passing deviceID back to the Server
A first-time anonymous visitor to your website is eligible for experiences that are configured for All Users and/or based on In-session Attributes. Such a visitor who visits a site that contains the MoEngage Web SDK is assigned a specific ID called as deviceID. This deviceID is stored in cookies, session storage, and local storage of the browser.
The deviceID is not a unique identifier for the user. The same user could be assigned another deviceID in any of the following cases:
- The user uses a different browser or a different device.
- The user deletes the cookies, cache, and local storage of the browser.
- The user enters the site using incognito mode.
- The user returns to the site after the cookie storing the deviceID expires.
When a first-time anonymous visitor is shown a personalized experience, passing the deviceID generated by MoEngage back to the server is recommended. For future sessions of the same user, this deviceID can be used to fetch personalized experiences from the server. Use the below function to fetch the MoEngage deviceID.
Moengage.device.getUuid()
deviceID needs to be passed as the value for the key visitor_id as part of the request to fetch The server-side experience. deviceID needs to be sent only if the unique identifier for the user is not available
If the user logs into the website using a unique identifier (email, phone number, etc.), then a unique identifier is assigned to the user, and this serves as 1:1 mapping for the user. This identifier can be used for future sessions of the user.
The unique identifier needs to be passed as the value for the key user_id as part of the request to fetch Server side experience.