-
Notifications
You must be signed in to change notification settings - Fork 4
/
engage-sdk-base-script.js
77 lines (63 loc) · 2.77 KB
/
engage-sdk-base-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// ==UserScript==
// @name Sitecore CDP/P base script - {{SiteName}}
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Generic Load Sitecore CDP Tampermonkey script
// @author Sitecore Presales
// @match https://*.yoursite.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// edit the {{cookieDomain}}, {{clientKey}}, {{pointOfSale}} and {{SiteName}} with your CDP/P enviorment values and website name
// see https://doc.sitecore.com/cdp/en/developers/api/collect-required-details.html for where and how to get these values
//Choose the API_TARGET that matches your API region (Europe,USA,or Asia)
const EU_API_TARGET = "https://api-engage-eu.sitecorecloud.io";
const US_API_TARGET = "https://api-engage-us.sitecorecloud.io";
const AP_API_TARGET = "https://api-engage-ap.sitecorecloud.io";
//Engage SDK settings
const ENGAGE_COOKIE_DOMAIN = "{{cookieDomain}}"; // e.g. ".myretailsite.com"
const ENGAGE_API_TARGET = AP_API_TARGET;
const ENGAGE_CLIENT_KEY = "{{clientKey}}";
const ENGAGE_POINT_OF_SALE = "{{pointOfSale}}";
const CURRENCY = "USD";
const CHANNEL = "WEB"
const LANG = "EN";
main();
var engage = undefined;
function main(engage) {
console.log("Loading Sitecore Engage SDK...")
// Create and inject the <script> tag into the HTML
var s = document.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src = "https://d1mj578wat5n4o.cloudfront.net/sitecore-engage-v.1.3.0.min.js";
var x = document.querySelector("script");
x.parentNode.insertBefore(s, x);
// Initialize the Engage SDK & send a VIEW event on each page load
s.addEventListener("load", async () => {
var settings = {
clientKey: ENGAGE_CLIENT_KEY,
targetURL: ENGAGE_API_TARGET,
pointOfSale: ENGAGE_POINT_OF_SALE,
cookieDomain: ENGAGE_COOKIE_DOMAIN,
cookieExpiryDays: 365,
forceServerCookieMode: false,
includeUTMParameters: true,
webPersonalization: "true"
};
window.engage = await window.Engage.init(settings);
var event = {
channel: CHANNEL,
language: LANG,
currency: CURRENCY,
page: window.location.pathname + window.location.search
};
// Send VIEW event
window.engage.pageView(event);
console.log("Sitecore Engage SDK Sent VIEW event")
//temp solution for demobars as the Engage.settings object does not expose the cookieDomain
localStorage.setItem("scDemoBar_cookieDomain", settings.cookieDomain);
});
}
})();