PageSourceSearch

https://www.ybs.co.uk/o/ybs-theme/js/NPS-Survey.js

js ybs.co.uk collected 2026-09-24 10:07:34 UTC 10,196 bytes, 273 lines download raw bytes

1/**
2 *  @name Surveys
3 *  
4 *  @return Return_Description
5 *  
6 *  @details These surveys will trigger automagically over time when rules are met.
7 */
8//Whilst a const is preferred, this file gets loaded multiple times in a journey, so const cannot be used.
9var surveys = [{
10	active: true,
11	site: "ybs",
12	name: "general_ybs_secure",
13	device: "all",
14	frequency: 1,
15	trigger: "/logout/logout1",
16	pathLength: 1,
17	allowMultiple: true,
18	expiry: 30,
19	popupDelay: 2000,
20	url: "https://survey2.medallia.eu/?online-transaction-tes&S=1",
21	content: '<div class="survey" id="survey-popup"> \
22				<div class="survey-inner"> \
23					<h3>Please take part in our survey.  </h3> \
24					<p> \
25						We value your feedback so why not help us improve our online service by telling us about your experience today?  \
26					</p> \
27						<a href="https://survey2.medallia.eu/?online-transaction-tes&S=1" target="_blank" title="Start Survey" class="btn btn-nm btn-solid-primary-color ybs-secure-btn">Start survey</a> \
28						<a href="#" title="Close survey" class="btn btn-solid-white js-close-popup">No thank you</a> \
29						<br/> \
30						<p style="font-size:0.9em">This survey is hosted by KPMG Nunwood, a customer experience specialist based in the UK. The information you give us will be treated with the strictest confidence and in accordance with the Market Research Society Code of Conduct. It will not be passed on to any other party and any personal details you provide will not be used in any sales or marketing activity.</p> \
31				</div> \
32		</div>',
33
34}, {
35	active: true,
36	site: "ybs",
37	name: "general_ybs",
38	device: "desktop",
39	frequency: 1,
40	trigger: "/",
41	exclusions: ["/logout/logout1"],
42	pathLength: 3,
43	allowMultiple: false,
44	expiry: 30,
45	popupDelay: 2000,
46	url: "https://survey2.medallia.eu/?online-transaction-tes&S=2",
47	content: '<div class="survey" id="survey-popup"> \
48			<div class="survey-inner"> \
49				<h3 title="We would love to hear your thoughts">We would love to hear your thoughts</h3> \
50				<p>We value your experience, so why not help us improve our online experience\?<br>It only takes a few minutes.</p> \
51				<a href="https://survey2.medallia.eu/?online-transaction-tes&S=2" target="_blank" title="Give feedback" class="btn btn-nm btn-solid-primary-color ">Give feedback</a> \
52				<a href="#" title="Close survey" class="btn btn-solid-white js-close-popup">No thank you</a> \
53			</div> \
54		</div>'
55}, {
56	active: true,
57	site: "ybs",
58	name: "general_ybs",
59	device: "tablet",
60	frequency: 1,
61	trigger: "/",
62	pathLength: 3,
63	allowMultiple: false,
64	expiry: 30,
65	popupDelay: 2000,
66	url: "https://survey2.medallia.eu/?online-transaction-tes&S=2",
67	content: '<div class="survey" id="survey-popup"> \
68			<div class="survey-inner"> \
69				<h3 title="We would love to hear your thoughts">We would love to hear your thoughts</h3> \
70				<p>We value your experience, so why not help us improve our online experience\?<br>It only takes a few minutes.</p> \
71				<a href="https://survey2.medallia.eu/?online-transaction-tes&S=2" target="_blank" title="Give feedback" class="btn btn-nm btn-solid-primary-color">Give feedback</a> \
72				<a href="#" title="Close survey" class="btn btn-solid-white js-close-popup">No thank you</a> \
73			</div> \
74		</div>'
75}, {
76	active: true,
77	site: "ybs",
78	name: "general_ybs",
79	device: "mobile",
80	frequency: 1,
81	trigger: "/",
82	pathLength: 3,
83	allowMultiple: false,
84	expiry: 30,
85	popupDelay: 2000,
86	url: "https://survey2.medallia.eu/?online-transaction-tes&S=2",
87	content: '<div class="survey" id="survey-popup"> \
88			<div class="survey-inner"> \
89				<h3 title="We would love to hear your thoughts">We would love to hear your thoughts</h3> \
90				<p>We value your experience, so why not help us improve our online experience\?<br>It only takes a few minutes.</p> \
91				<a href="https://survey2.medallia.eu/?online-transaction-tes&S=2" target="_blank" title="Give feedback" class="btn btn-nm btn-solid-primary-color">Give feedback</a> \
92				<a href="#" title="Close survey" class="btn btn-solid-white js-close-popup">No thank you</a> \
93			</div> \
94		</div>'
95}];
96
97// global survey settings
98var cookiesEnabled = navigator.cookieEnabled && readCookie("OptanonConsent") && decodeURIComponent(readCookie("OptanonConsent")).indexOf("C0002:1") > -1;
99var surveyInactiveTimeout = 60000; // hide survey popup after X seconds of inactivity eg. 
100
101
102function getSurveyStatus(){
103	var activeSurvey = readCookie("activeSurvey");
104	var surveysCount = readCookie("surveyCount");
105	var surveysExpired = (surveysCount === "expired");
106	var surveysReserve = (activeSurvey === "reServe");
107	return {
108		cookie: activeSurvey,
109		count: surveysCount,
110		expired: surveysExpired,
111		reserve: surveysReserve
112	}
113}
114
115function isSurveyExcluded(surveyId){
116	var thisSurvey = surveys[surveyId];
117	if(!thisSurvey || !thisSurvey.exclusions){
118		return false;
119	}
120
121	let isExcluded = false;
122	thisSurvey.exclusions.forEach(function(item){
123		if(window.location.pathname.indexOf(item) > -1){
124			isExcluded =  true;
125		}
126	});
127
128	return isExcluded;
129}
130
131function showSurveyPopup(surveyName, surveyContent) {
132	//If this has been re-triggered somehow, dont render it again.
133	if(document.querySelector("#survey_"+surveyName)){
134		return;
135	}
136
137	//Create the popup in DOM form, then add it to the page.
138	var surveyPopup = document.createElement('div');
139		surveyPopup.setAttribute("id", "survey_"+surveyName);
140		
141		surveyPopup.addEventListener("click", function(ev){
142			if(ev.target.classList.contains("js-close-popup")){
143				ev.preventDefault();
144				this.remove();
145				clearTimeout(surveyTimer);
146			}
147		}, true);
148		
149		// static survey popoup
150		surveyPopup.classList.add('notification-container');
151		surveyPopup.innerHTML = surveyContent;
152		
153	document.querySelector('.ybs').appendChild(surveyPopup);
154		
155	var surveyTimer = setTimeout(closeSurveyPopup, surveyInactiveTimeout); // hide survey popup after inactivity
156
157	// Dispatch the event on the element
158	document.documentElement.dispatchEvent(new CustomEvent('FeedbackSurveyActive', {
159		detail: {
160		   display: true
161		}
162	}))
163}
164
165//Thisn should run everytime a page is loaded.
166window.addEventListener("load", checkForSurveys);
167//This should load everytime the SPA loads a new view.
168Liferay.on("screenActivate", checkForSurveys);
169
170function checkForSurveys() {
171	//Get the initial state
172	let surveyStatus = getSurveyStatus();
173	let isExcluded = surveyStatus.cookie !== null ? isSurveyExcluded(parseInt(surveyStatus.cookie)) : false;
174	// If cookies are allowed, and no survey has been set/survey is set to reServe, and its not expired
175	if (cookiesEnabled && (surveyStatus.cookie === null || surveyStatus.reserve || isExcluded) && !surveyStatus.expired) {
176
177		for (var i=0; i<surveys.length; i++) {
178			var thisSurvey = surveys[i];
179			if(!thisSurvey.active){
180				continue;
181			}
182			
183			if(thisSurvey.site !== NPS_SURVEY_MODE){
184				continue;
185			}
186
187			if ((thisSurvey.device == "mobile" && ybs?.isMobile) ||
188				(thisSurvey.device == "tablet" && ybs?.isMobile) ||
189				(thisSurvey.device == "desktop" && !ybs?.isMobile) ||
190				(thisSurvey.device == "all")) {
191				
192				var surveyCookie = readCookie(thisSurvey.name);
193
194				//Is this page an appropriate trigger for the survey
195				var isTriggered = window.location.pathname.indexOf(thisSurvey.trigger) > -1;
196				if(!isTriggered){
197					continue;
198				}
199
200				//Is Page excluded from running on this page?
201				isExcluded = isSurveyExcluded(i);
202				if(isExcluded){
203					continue;
204				}
205
206
207				//Frequency = true
208				//Cookie not set
209				//Cookie !== defered
210				if (thisSurvey.frequency && !surveyCookie && surveyCookie != "defered") {
211					createCookie("activeSurvey", i); // declare active survey as number in surveys
212					createCookie(thisSurvey.name, 0); // init active survey name cookie path length checker
213					break;
214
215				//Frequency = false
216				//Cookie not set
217				//Cookie !== defered
218				} else if (!thisSurvey.frequency && !surveyCookie && surveyCookie != "defered") {
219					// user has not been selected (frequency) to receive this survey at this time
220					createCookie(thisSurvey.name, "defered"); // defer active survey name cookie until next visit
221				}
222			}
223		}
224	}
225
226	//Reload the state so the rest of the code knows whats going on.
227	surveyStatus = getSurveyStatus();
228
229	//Survey code - continues
230	if (cookiesEnabled && (surveyStatus.cookie && parseInt(surveyStatus.cookie) <= surveys.length) && !surveyStatus.expired) {
231		
232		var thisSurvey = surveys[surveyStatus.cookie];
233		var surveyCookieVal = readCookie(thisSurvey.name);
234			surveyCookieVal = parseInt(surveyCookieVal);
235		
236		surveyCookieVal++; // increment cookie value to match the number of pages visited
237
238		if (surveyCookieVal < thisSurvey.pathLength) {
239			createCookie(thisSurvey.name, surveyCookieVal);
240		}
241
242		if (surveyCookieVal === thisSurvey.pathLength) {
243			// user has now visited the required number of pages to display survey popup for survey
244			// expire the cookie for this survey
245			createCookie(thisSurvey.name, "served", thisSurvey.expiry);
246			if (thisSurvey.allowMultiple == true && !surveyStatus.count) {
247
248				// this survey allows another survey to run in conjunction. Should the user visit a new trigger page for another survey, they will start the survey initialization process again
249				createCookie("activeSurvey", "reServe", thisSurvey.expiry);
250				createCookie("surveyCount", "1", thisSurvey.expiry);
251				// show the survey popup
252				window.surveyTimer = setTimeout(function () {
253					showSurveyPopup(thisSurvey.name, thisSurvey.content)
254				}, thisSurvey.popupDelay);
255
256
257			} else if (surveyStatus.count == 1 || !surveyStatus.count) {
258				// this is the last survey the user will be shown on this visit or for the next X days
259				createCookie("activeSurvey", "served", thisSurvey.expiry);
260				createCookie("surveyCount", "expired", thisSurvey.expiry);
261				window.surveyTimer = setTimeout(function () {
262					showSurveyPopup(thisSurvey.name, thisSurvey.content)
263				}, thisSurvey.popupDelay);
264			} else {
265				// multiple surveys are not allowed with this survey - do not show anymore surveys on this visit or for X days
266				createCookie("activeSurvey", "served", thisSurvey.expiry);
267				createCookie("surveyCount", "expired", suthisSurvey.expiryrveyExpiry);
268			}
269
270		}
271
272	}	
273};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.