PageSourceSearch

https://www.luna.com/Scripts/src/luna-cad.js?b=019b8cce-56c2-4ac5-8b8d-2abd702968cc

js luna.com collected 2026-09-26 12:44:40 UTC 11,517 bytes, 380 lines download raw bytes

1// helper functions -------
2function getQueryParameters(str) {
3    return (str || document.location.search).replace(/(^\?)/, '').split("&").map(function (n) { return n = n.split("="), this[n[0].toLowerCase()] = n[1] == undefined ? n[1] : decodeURIComponent(n[1]), this }.bind({}))[0];
4};
5
6
7function getAdobeId(cookieName) {
8    var wholeCookie = document.cookie;
9    var partOfCookie = wholeCookie.split(cookieName + "=");
10    var cookieFound = partOfCookie.pop().split(';').shift();
11    var decodedCookie = decodeURI(cookieFound);
12    var adobeID = decodedCookie.split('|')[4];
13
14    return adobeID;
15};
16
17// cookie function helpers ---------------------------------
18function setCookie(cname, cvalue, exdays) {
19    // console.log('set cookie is call')
20    var d = new Date();
21    d.setTime(d.getTime() + (exdays*24*60*60*1000));
22    var expires = "expires="+ d.toUTCString();
23    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
24};
25
26// return cookie by its name
27function getCookieByName(cookieName) {
28    var wholeCookie = document.cookie;
29    var partOfCookie = wholeCookie.split(cookieName + "=");
30    if (partOfCookie.length >= 2) {
31        var cookieFound = partOfCookie.pop().split(';').shift();
32    }
33
34    return cookieFound;
35};
36
37function resetCookie() {
38    // console.log('remove ETS')
39    setCookie('ETS', '', 0);
40};
41
42
43// =============================================================
44//-------- End of Helpers
45
46
47
48// variable set up -----
49var httpRequest;
50var paramsQueryObject = getQueryParameters();
51var adobeId = getAdobeId('AMCV_1519401053DAE9740A490D4C%40AdobeOrg') || '';
52
53
54var cookieETS = getCookieByName('ETS');
55// console.log('TC - CookieETS')
56// console.log(cookieETS)
57var etsObject = cookieETS ? JSON.parse(cookieETS) : { "data": {} };
58
59var oldId = etsObject.data.adobeId;
60var dataId = etsObject.id || null;
61var newValues = false;
62var ipAddress = serverVars.ipAdd || '';
63
64
65// assign newest adobe id to etsObject
66etsObject.data.adobeId = adobeId;
67
68
69
70var userData = {
71    data: {
72        adobeId: etsObject.data.adobeId,
73        event_data: [],
74        content_ids: [],
75        fbp: getCookieByName('_fbp') || '',
76        client_ip_address: ipAddress,
77        client_user_agent: window.navigator.userAgent || ''
78    }
79};
80
81var webLeadBindings = { // to be use if biding Personal Data
82    // first_name: 'firstName',
83    // last_name: 'lastName',
84    // phone: 'primaryPhone',
85    // email: 'emailAddress',
86    // address: 'addressLine1'
87};
88
89var paramBindings = {};
90
91
92function inputChangeValueTracking(e) {   
93    var currentValue = e.target.value;
94    var inputDataName = e.target.dataset.name;
95
96    if ( userData.data[inputDataName] == undefined || userData.data[inputDataName] != currentValue && currentValue != "" ) {
97        if (inputDataName == 'suggested_time') {
98            userData.data['schedule_time'] = currentValue;
99            userData.data['schedule_date'] = e.target.dataset.date;
100        } else {
101            userData.data[inputDataName] = currentValue;
102        }
103        // console.log('TC - Post on ChangeValue')
104        postRequest(userData.id);
105    } else {
106        // console.log('no new values')
107        newValues = false;
108    }
109};
110
111
112function mapIncomingDataToUserData(obj, bool) {
113    var objAPI = bool ? JSON.parse(obj.data) : obj;
114    // console.log(objAPI)
115    for (key in objAPI) {
116
117        if ( objAPI[key] != '' && key != '' && objAPI[key] != undefined ) {
118
119            if (objAPI[key] != userData.data[key] && objAPI[key] != null) {
120 
121                userData.data[key] = objAPI[key];
122
123                if (bool == false) {
124                    newValues = true;
125                }
126            } else {
127                newValues = false;
128            }
129
130            validateChannel(key, objAPI);
131
132
133        } else if (objAPI[key] == '' && userData.data[key] == undefined) {
134
135            userData.data[key] = objAPI[key];
136        }
137    }
138};
139
140
141// validate and remove wrong values for channel
142function validateChannel(param, obj) {
143    if (param == "channel") {
144
145        var channelLowerCase = obj[param] ? obj[param].toLowerCase() : '';
146
147        if (channelLowerCase != "callcenter" && channelLowerCase != "web") {
148            // console.log(param)
149            userData.data[param] = '';
150            newValues = true;
151        }
152    }
153};
154
155
156function bindToCorrectModelKeys(defaultObject, bindingObject) {
157    var updatedBindedObject = {};
158 
159    for (var [key, value] of Object.entries(defaultObject)) {
160
161        if (bindingObject[key] != undefined && value != '') {
162            updatedBindedObject[bindingObject[key].toLowerCase()] = value;
163        } else {
164            updatedBindedObject[key.toLowerCase()] = value;
165        }
166
167    };
168
169    return updatedBindedObject;
170 };
171
172
173 function FBEventView(eName, id, arg) {
174    var eventData = userData.data.event_data;
175    var date = new Date();
176    var UTCTime = date.toISOString();
177    var lastIndex = userData.data.event_data.length - 1;
178    var eventCount = eventData.length == 0 ? 0 : eventData[lastIndex].event_no + 1;
179    var eventGuid = id +'-'+ eventCount;
180
181    eventData.push(
182        {
183            event_source_company: 'Luna',
184            event_id: eventGuid,
185            event_no: eventCount,
186            event_name: eName,
187            event_url: window.location.href,
188            event_date_time: UTCTime
189        }
190    );
191
192    faceBookTrackCall(eName, arg, eventGuid) 
193};
194
195
196function faceBookTrackCall(eName, favs, id) {
197    if ( eName == 'PageView') {
198        fbq('track', eName, {}, {eventID: id});
199    }
200
201    if ( eName == 'CompleteRegistration' ) {
202        fbq('track', eName, { value: 1.00, currency: 'USD'}, {eventID: id});
203    }
204};
205
206// end -----
207
208
209// API Calls and Helper Methods -----
210function postRequest(id) {
211    httpRequest = new XMLHttpRequest();
212
213    var res;
214
215    if (!httpRequest) {
216      console.log('Giving up :( Cannot create an XMLHTTP instance');
217      return false;
218    }
219
220    httpRequest.onreadystatechange = function() {
221        if (httpRequest.readyState === XMLHttpRequest.DONE) {
222            if (httpRequest.status === 200) {
223                res = JSON.parse(httpRequest.responseText);
224                console.log('TC - post response')
225                if (id == undefined) {
226                    // console.log('data id undefined post call');
227                    postInitalCookieSet(res); 
228                } else {
229                    // console.log('data id found post call');
230                }
231                     
232            } else {
233                console.log('There was a problem with the request.');
234            }
235        }
236    };
237
238
239    httpRequest.open('POST', serverVars.CADAPIEndpoint);
240    httpRequest.setRequestHeader('Content-Type', 'application/json');
241    httpRequest.send(JSON.stringify(userData));
242};
243// post to api and set cookie if none
244function postInitalCookieSet(res) {
245    userData.id = res.id
246    etsObject.id = res.id;
247    var data = JSON.stringify(etsObject);
248
249    // console.log('TC - set cookie when ID is undefined')
250    setCookie('ETS', data, 7);
251    // grad id and post to set init event with id
252    FBEventView('PageView', res.id);
253    postRequest(res.id);
254};
255
256
257function getRequest(dataId) {
258    httpRequest = new XMLHttpRequest();
259    var res; 
260
261    if (!httpRequest) {
262        console.log('Giving up :( Cannot create an XMLHTTP instance');
263        return false;
264    }
265
266    httpRequest.onreadystatechange = function() {
267        if (httpRequest.readyState === XMLHttpRequest.DONE) {
268            if (httpRequest.status === 200) {
269                res = JSON.parse(httpRequest.responseText);
270                getAndMapUserData(res)                    
271            } else {
272                console.log('There was a problem with the request.');
273            }
274        }
275    };
276
277    httpRequest.open('GET', serverVars.CADAPIEndpoint + dataId );
278    httpRequest.send();
279};
280
281
282function getAndMapUserData(res) {
283
284    mapIncomingDataToUserData(res, true); // map with previous data
285    userData.id = res.id;
286    mapIncomingDataToUserData(paramsQueryObject, false); // map with param data
287
288    validateCallSystems();
289
290    var wLocal = window.location.href;
291    var urlArrLenght = userData.data.event_data.length;
292    var lasViewLocation = '';
293    if (urlArrLenght > 0) {
294        lasViewLocation = userData.data.event_data[urlArrLenght-1].event_url;
295    }
296
297    wLocal != lasViewLocation ? newValues = true : newValues = false;
298    // console.log('ln: ' + newValues)
299
300    if (userData.id != etsObject.id) {
301        // console.log('id did not match');
302        etsObject.id = userData.id;
303    }
304    var data = JSON.stringify(etsObject);
305
306    // reset cookie every time to seven days ahead
307    setCookie('ETS', data, 7);
308    if (newValues && window.location.href.indexOf('appointment-thanks') < 0) {
309        // console.log('TC - New Values found')
310        FBEventView('PageView', res.id);
311        postRequest(res.id);
312    }
313
314    if (newValues && window.location.href.indexOf('appointment-thanks') >= 0) {
315        setTimeout(function() {
316            // userData.data.content_ids = fbcids;
317            userData.data.opportunity_number = opptyNumber;
318            FBEventView('PageView', res.id);
319            // FBEventView('Purchase', res.id, fbcids);
320            FBEventView('CompleteRegistration', res.id);
321            postRequest(res.id);
322        }, 400);
323    }
324
325    if ( window.location.href.indexOf('appointment-thanks') >= 0 ) {
326        console.log('TC - cookie reset')
327        setTimeout(function() {
328            resetCookie();
329        }, 500);                 
330    }
331};
332
333// Validates call tracking systems params
334function validateCallSystems() {
335    var data = userData.data;
336    if (data.calltrackingsystem && data.calltrackingsystemid) {
337        // console.log('both are here')
338    } else {
339
340        if (data.calltrackingsystem || data.calltrackingsystemid) {
341            newValues = true;
342        }
343        data.calltrackingsystem ? data['calltrackingsystem'] = '' : null;
344        data.calltrackingsystemid ? data['calltrackingsystemid'] = '' : null;
345        // console.log('has new value = ' + newValues)
346    }
347};
348
349
350function resetForm() {
351    localStorage.removeItem('roomCount');
352    localStorage.removeItem('appt_session');
353    localStorage.removeItem('gbp');
354    localStorage.removeItem('promotion');
355};
356
357// Init Tracking Code -----
358function initETSTracking() {
359
360    if (paramsQueryObject.session === 'new') {
361        // resets ETS COOKIE
362        setCookie('ETS', '', 0);
363        cookieETS = undefined;
364        resetForm();
365        // remove session new param
366        window.history.replaceState({ path: window.location.href }, '', window.location.href.replace(/.session=new/, ''));
367    }
368
369    if (cookieETS == undefined && window.location.href.indexOf('appointment-thanks') < 0 || adobeId != oldId && window.location.href.indexOf('appointment-thanks') < 0) {
370        console.log('init by setting cookie');
371        mapIncomingDataToUserData(paramsQueryObject, false);
372        validateCallSystems();
373        postRequest();
374    } else if (adobeId == oldId) {
375        console.log('new id matches old id');
376        getRequest(dataId)           
377    }
378}; initETSTracking();
379
380

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.