@sitecore-cloudsdk/personalize
Advanced tools
Comparing version 0.2.3 to 0.2.4
{ | ||
"name": "@sitecore-cloudsdk/personalize", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"license": "Apache-2.0", | ||
@@ -19,4 +19,4 @@ "homepage": "https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html", | ||
"dependencies": { | ||
"@sitecore-cloudsdk/core": "^0.2.3", | ||
"@sitecore-cloudsdk/utils": "^0.2.3" | ||
"@sitecore-cloudsdk/core": "^0.2.4", | ||
"@sitecore-cloudsdk/utils": "^0.2.4" | ||
}, | ||
@@ -23,0 +23,0 @@ "scripts": { |
@@ -15,1 +15,2 @@ /** | ||
export declare const PERSONALIZE_NAMESPACE: "sitecore-cloudsdk:personalize"; | ||
export declare const UTM_PREFIX = "utm_"; |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PERSONALIZE_NAMESPACE = exports.ErrorMessages = exports.LIBRARY_VERSION = void 0; | ||
exports.UTM_PREFIX = exports.PERSONALIZE_NAMESPACE = exports.ErrorMessages = exports.LIBRARY_VERSION = void 0; | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
@@ -26,1 +26,2 @@ const package_json_1 = __importDefault(require("../../package.json")); | ||
exports.PERSONALIZE_NAMESPACE = 'sitecore-cloudsdk:personalize'; | ||
exports.UTM_PREFIX = 'utm_'; |
@@ -19,4 +19,6 @@ "use strict"; | ||
const id = (0, core_1.getBrowserId)(); | ||
return new personalizer_1.Personalizer(id).getInteractiveExperienceData(personalizeData, settings, { timeout }); | ||
return new personalizer_1.Personalizer(id).getInteractiveExperienceData(personalizeData, settings, window.location.search, { | ||
timeout, | ||
}); | ||
} | ||
exports.personalize = personalize; |
@@ -18,3 +18,3 @@ import { Settings } from '@sitecore-cloudsdk/core'; | ||
*/ | ||
getInteractiveExperienceData(personalizeInput: PersonalizerInput, settings: Settings, opts?: { | ||
getInteractiveExperienceData(personalizeInput: PersonalizerInput, settings: Settings, searchParams: string, opts?: { | ||
timeout?: number; | ||
@@ -37,2 +37,9 @@ userAgent?: string | null; | ||
private validate; | ||
/** | ||
* Retrieves UTM parameters from the url query string e.g. `utm_test1=123&utm_test2=456` | ||
* @param urlParams - The url params passed | ||
* @param prefix - The prefix we want to extract from the params | ||
* @returns - an object containing the UTM parameters (if they exist) in the form: `utm: {test1: 123, test2: 456}` | ||
*/ | ||
private extractUrlParamsWithPrefix; | ||
} | ||
@@ -39,0 +46,0 @@ /** |
@@ -23,5 +23,9 @@ "use strict"; | ||
*/ | ||
async getInteractiveExperienceData(personalizeInput, settings, opts) { | ||
async getInteractiveExperienceData(personalizeInput, settings, searchParams, opts) { | ||
this.validate(personalizeInput); | ||
const sanitizedInput = this.sanitizeInput(personalizeInput); | ||
if (searchParams.includes(consts_1.UTM_PREFIX) && !sanitizedInput.params?.utm) { | ||
sanitizedInput.params = sanitizedInput.params || {}; | ||
sanitizedInput.params.utm = this.extractUrlParamsWithPrefix(searchParams, consts_1.UTM_PREFIX); | ||
} | ||
const mappedData = this.mapPersonalizeInputToEPData(sanitizedInput); | ||
@@ -87,3 +91,21 @@ if (!mappedData.email && !mappedData.identifiers) | ||
} | ||
/** | ||
* Retrieves UTM parameters from the url query string e.g. `utm_test1=123&utm_test2=456` | ||
* @param urlParams - The url params passed | ||
* @param prefix - The prefix we want to extract from the params | ||
* @returns - an object containing the UTM parameters (if they exist) in the form: `utm: {test1: 123, test2: 456}` | ||
*/ | ||
extractUrlParamsWithPrefix(urlParams, prefix) { | ||
const urlSearchParams = new URLSearchParams(decodeURI(urlParams)); | ||
const extractedParams = {}; | ||
urlSearchParams.forEach((value, key) => { | ||
const paramKey = key.toLowerCase(); | ||
if (paramKey.indexOf(prefix) === 0) { | ||
const paramName = paramKey.substring(prefix.length); | ||
extractedParams[paramName] = value; | ||
} | ||
}); | ||
return extractedParams; | ||
} | ||
} | ||
exports.Personalizer = Personalizer; |
@@ -20,7 +20,13 @@ "use strict"; | ||
const id = (0, core_1.getBrowserIdFromRequest)(request, settings.cookieSettings.cookieName); | ||
const requestUrl = new URL(request.url, `https://localhost`); | ||
const userAgent = (0, utils_1.isNextJsMiddlewareRequest)(request) | ||
? request.headers.get('user-agent') | ||
: request.headers['user-agent']; | ||
return new personalizer_1.Personalizer(id).getInteractiveExperienceData(personalizeData, settings, { timeout, userAgent }); | ||
if (!personalizeData.geo && (0, utils_1.isNextJsMiddlewareRequest)(request) && request.geo && Object.keys(request.geo).length) | ||
personalizeData.geo = request.geo; | ||
return new personalizer_1.Personalizer(id).getInteractiveExperienceData(personalizeData, settings, requestUrl.search, { | ||
timeout, | ||
userAgent, | ||
}); | ||
} | ||
exports.personalizeServer = personalizeServer; |
{ | ||
"name": "@sitecore-cloudsdk/personalize", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"license": "Apache-2.0", | ||
@@ -19,4 +19,4 @@ "homepage": "https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html", | ||
"dependencies": { | ||
"@sitecore-cloudsdk/core": "^0.2.3", | ||
"@sitecore-cloudsdk/utils": "^0.2.3" | ||
"@sitecore-cloudsdk/core": "^0.2.4", | ||
"@sitecore-cloudsdk/utils": "^0.2.4" | ||
}, | ||
@@ -23,0 +23,0 @@ "scripts": { |
@@ -15,1 +15,2 @@ /** | ||
export declare const PERSONALIZE_NAMESPACE: "sitecore-cloudsdk:personalize"; | ||
export declare const UTM_PREFIX = "utm_"; |
@@ -19,1 +19,2 @@ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
export const PERSONALIZE_NAMESPACE = 'sitecore-cloudsdk:personalize'; | ||
export const UTM_PREFIX = 'utm_'; |
@@ -16,3 +16,5 @@ import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core'; | ||
const id = getBrowserId(); | ||
return new Personalizer(id).getInteractiveExperienceData(personalizeData, settings, { timeout }); | ||
return new Personalizer(id).getInteractiveExperienceData(personalizeData, settings, window.location.search, { | ||
timeout, | ||
}); | ||
} |
@@ -18,3 +18,3 @@ import { Settings } from '@sitecore-cloudsdk/core'; | ||
*/ | ||
getInteractiveExperienceData(personalizeInput: PersonalizerInput, settings: Settings, opts?: { | ||
getInteractiveExperienceData(personalizeInput: PersonalizerInput, settings: Settings, searchParams: string, opts?: { | ||
timeout?: number; | ||
@@ -37,2 +37,9 @@ userAgent?: string | null; | ||
private validate; | ||
/** | ||
* Retrieves UTM parameters from the url query string e.g. `utm_test1=123&utm_test2=456` | ||
* @param urlParams - The url params passed | ||
* @param prefix - The prefix we want to extract from the params | ||
* @returns - an object containing the UTM parameters (if they exist) in the form: `utm: {test1: 123, test2: 456}` | ||
*/ | ||
private extractUrlParamsWithPrefix; | ||
} | ||
@@ -39,0 +46,0 @@ /** |
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
import { language, debug } from '@sitecore-cloudsdk/core'; | ||
import { sendCallFlowsRequest } from './send-call-flows-request'; | ||
import { ErrorMessages, PERSONALIZE_NAMESPACE } from '../consts'; | ||
import { ErrorMessages, PERSONALIZE_NAMESPACE, UTM_PREFIX } from '../consts'; | ||
export class Personalizer { | ||
@@ -20,5 +20,9 @@ /** | ||
*/ | ||
async getInteractiveExperienceData(personalizeInput, settings, opts) { | ||
async getInteractiveExperienceData(personalizeInput, settings, searchParams, opts) { | ||
this.validate(personalizeInput); | ||
const sanitizedInput = this.sanitizeInput(personalizeInput); | ||
if (searchParams.includes(UTM_PREFIX) && !sanitizedInput.params?.utm) { | ||
sanitizedInput.params = sanitizedInput.params || {}; | ||
sanitizedInput.params.utm = this.extractUrlParamsWithPrefix(searchParams, UTM_PREFIX); | ||
} | ||
const mappedData = this.mapPersonalizeInputToEPData(sanitizedInput); | ||
@@ -84,2 +88,20 @@ if (!mappedData.email && !mappedData.identifiers) | ||
} | ||
/** | ||
* Retrieves UTM parameters from the url query string e.g. `utm_test1=123&utm_test2=456` | ||
* @param urlParams - The url params passed | ||
* @param prefix - The prefix we want to extract from the params | ||
* @returns - an object containing the UTM parameters (if they exist) in the form: `utm: {test1: 123, test2: 456}` | ||
*/ | ||
extractUrlParamsWithPrefix(urlParams, prefix) { | ||
const urlSearchParams = new URLSearchParams(decodeURI(urlParams)); | ||
const extractedParams = {}; | ||
urlSearchParams.forEach((value, key) => { | ||
const paramKey = key.toLowerCase(); | ||
if (paramKey.indexOf(prefix) === 0) { | ||
const paramName = paramKey.substring(prefix.length); | ||
extractedParams[paramName] = value; | ||
} | ||
}); | ||
return extractedParams; | ||
} | ||
} |
@@ -17,6 +17,12 @@ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName); | ||
const requestUrl = new URL(request.url, `https://localhost`); | ||
const userAgent = isNextJsMiddlewareRequest(request) | ||
? request.headers.get('user-agent') | ||
: request.headers['user-agent']; | ||
return new Personalizer(id).getInteractiveExperienceData(personalizeData, settings, { timeout, userAgent }); | ||
if (!personalizeData.geo && isNextJsMiddlewareRequest(request) && request.geo && Object.keys(request.geo).length) | ||
personalizeData.geo = request.geo; | ||
return new Personalizer(id).getInteractiveExperienceData(personalizeData, settings, requestUrl.search, { | ||
timeout, | ||
userAgent, | ||
}); | ||
} |
{ | ||
"name": "@sitecore-cloudsdk/personalize", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"license": "Apache-2.0", | ||
@@ -19,4 +19,4 @@ "homepage": "https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html", | ||
"dependencies": { | ||
"@sitecore-cloudsdk/core": "^0.2.3", | ||
"@sitecore-cloudsdk/utils": "^0.2.3" | ||
"@sitecore-cloudsdk/core": "^0.2.4", | ||
"@sitecore-cloudsdk/utils": "^0.2.4" | ||
}, | ||
@@ -23,0 +23,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
111482
1023