PageSourceSearch

https://www.aia.com.hk/etc.clientlibs/hk-aiaplus/clientlibs/client…/aiaplus-aa-tracking-common-function.js

js aia.com.hk collected 2026-10-02 02:56:04 UTC 14,030 bytes, 424 lines download raw bytes

1/**
2   * 
3    aaTrackingCommonFunction({
4      eventName: "buttonClicks",
5      event1to100:{
6        event6:{
7          value:1
8        },
9        event54:{
10          value:1
11        }
12      },
13      evars:{
14            eVar32: "xxx",
15            eVar53: "yyy"
16      }
17    })
18  */
19function aaTrackingCommonFunction ({eventName, event1to100, evars}) {
20  if (window && window.adobeDataLayer) {
21    window.adobeDataLayer.push({
22      event: eventName,
23      eventInfo: {
24        _experience: {
25          analytics: {
26            event1to100,
27            customDimensions: {
28              eVars: evars
29            }
30          }
31        }
32      }
33    });
34  }
35};
36
37var AATrackingPageNameSetupApp = {
38  data() {
39    return {
40      pathname: "",
41      pageName: "",
42      selector: {
43        meta: "meta[name='pathname']"
44      },
45      RoutePageNames: window.aiaPlusRoutePageNames,
46      reAuthOtp: "/aia-plus/re-authentication/otp-template.html",
47      reAuthOtpTitle: {
48        en: {
49          switchLoginID: "Switch to mobile number login",
50          switchMobileID: "Update login mobile",
51          switchFaceID: "login with face ID",
52          switchFingerprint: "Log in with fingerprint recognition",
53          updateContact: "Update OTP contact details",
54          combine: "Combine user accounts",
55          changepwd: "Change password"
56        },
57        "zh-cn": {
58          switchLoginID: "改用手机号码登录",
59          switchMobileID: "更新登录手机号码",
60          switchFaceID: "以面容ID登录",
61          switchFingerprint: "以指纹识别登陆",
62          updateContact: "更新一次性验证码联系信息",
63          combine: "合并用户账户",
64          changepwd: "更改密码"
65        },
66        "zh-hk": {
67          switchLoginID: "轉用手機號碼登入",
68          switchMobileID: "更新登入手機號碼",
69          switchFaceID: "以Face ID登入",
70          switchFingerprint: "以指紋識別登入",
71          updateContact: "更新一次性驗證碼聯絡資料",
72          combine: "合併用戶賬戶",
73          changepwd: "更改密碼"
74        }
75      },
76      adb2cSelector: {
77        inputIdPassport: "#attributeVerification #passportNumber",
78      },
79      forgotIDAndMobilePii: "/aia-plus/forgot/identity/validate-info-template.html",
80      forgotPasswordPii: "/aia-plus/forgot/credential/validate-info-template.html",
81      RouteSubPageNames: {
82        "/aia-plus/forgot/identity/validate-info-template.html": {
83          noMatch: "NoMatchingAccountFound",
84          stillNoMatch: "StillNoMatchingAccountFound"
85        },
86        "/aia-plus/forgot/credential/validate-info-template.html": {
87          DOB_ID_NO_CHALLENGE: "DateOfBirthAndID",
88          DOB_MEMBERID_CHALLENGE: "GroupInsuranceDetail",
89          EMAIL_CHALLENGE: "EmailAddress",
90          MOBILE_CHALLENGE: "MobileNumber",
91          CUSTOMER_SUPPORT: "ContactUs"
92        }
93      },
94    };
95  },
96  mounted() {
97    let _this = this;
98    var data = this.data();
99    for (var i in data) {
100      this[i] = data[i];
101    }
102    for (var i in this.methods) {
103      this[i] = this.methods[i];
104    }
105    this.init();
106  },
107  methods: {
108    init() {
109      this.getEnv();
110      this.getPageName();
111      this.setPageName();
112      this.pageView();
113    },
114    getEnv() {
115      const { meta } = this.selector;
116      const path = location.hostname;
117      const domainPath = ["b2clogin.com", "plus-sit.aia.com.hk", "plus-uat.aia.com.hk", "plus.aia.com.hk"];
118      if (domainPath.some(domain => path.includes(domain))) {
119        const el = document.querySelector(meta);
120        if (el) {
121          this.pathname = el.getAttribute("content");
122        }
123      } else {
124        this.pathname = window.location.pathname;
125      }
126    },
127    getLang() {
128      var htmlLanguage = $("html").attr("lang");
129      var lang = "";
130      if (htmlLanguage === "zh-Hant" || htmlLanguage === "zh-Hant-HK") {
131        lang = "zh-hk";
132      } else if (htmlLanguage === "zh-Hans" || htmlLanguage === "zh-Hans-CN") {
133        lang = "zh-cn";
134      } else {
135        lang = "en";
136      }
137      return lang
138    },
139    getReAuthOtpIdx() {
140      const urlParams = new URLSearchParams(window.location.search)
141      const pageTitle = urlParams.get("entryTitle").replace(/%20/g, " ")
142      const lang = this.getLang()
143      let idx = 0
144      let keys = Object.keys(this.reAuthOtpTitle[lang])
145      for (let i = 0; i < keys.length; i++) {
146        if (this.reAuthOtpTitle[lang][keys[i]] === pageTitle) {
147          idx = i
148        }
149      }
150      return idx
151    },
152    getPageName() {
153      const { inputIdPassport } = this.adb2cSelector
154      let key = this.getCurrentPathname();
155      if (location.hostname.includes("localhost")) {
156        key = key.replace(".html", "");
157      }
158      if (this.RoutePageNames[key]) {
159        // SwitchToMobileNumberLoginOTP|UpdateLoginMobileOTP|UpdateOTPContactDetailsOTP|CombineUserAccountOTP|ChangePasswordOTP
160        if (key === this.reAuthOtp) {
161          const arr = this.RoutePageNames[key].split("|")
162          const idx = this.getReAuthOtpIdx()
163          this.pageName = `hk:aiaplus:${arr[idx]}`;
164        } else if (key === this.forgotIDAndMobilePii) {
165          if ($(inputIdPassport).length > 0) {
166            this.pageName = `hk:aiaplus:${this.RoutePageNames[key]}:${this.RouteSubPageNames[key].noMatch}`;
167          } else {
168            this.pageName = `hk:aiaplus:${this.RoutePageNames[key]}:${this.RouteSubPageNames[key].stillNoMatch}`;
169          }
170        } else if (key === this.forgotPasswordPii) {
171          /** 
172         * DOB_ID_NO_CHALLENGE     case1
173         * DOB_MEMBERID_CHALLENGE  case2
174         * EMAIL_CHALLENGE         case3
175         * MOBILE_CHALLENGE        case4
176         * CUSTOMER_SUPPORT         case5
177         * */
178          var parser = new URL(SETTINGS.remoteResource);
179          if (parser.searchParams.size > 0) {
180            const challengeType = parser.searchParams.get("challengeType");
181            this.pageName = `hk:aiaplus:${this.RoutePageNames[key]}:${this.RouteSubPageNames[key][challengeType]}`;
182          }
183        } else {
184          this.pageName = `hk:aiaplus:${this.RoutePageNames[key]}`;
185        }
186      } else if (window.SETTINGS) {
187        // 单独针对forgot id forgotType带参数
188        var parser = new URL(SETTINGS.remoteResource);
189        if (parser.searchParams.size > 0) {
190          var forgotType = parser.searchParams.get("forgotType")
191          var mixKey = `${key}?forgotType=${forgotType}`
192          this.pageName = `hk:aiaplus:${this.RoutePageNames[mixKey]}`;
193        }
194      } else if (this.RoutePageNames[key + location.search]){
195        // 单独针对forgot id 入口forgotType带参数
196        this.pageName = `hk:aiaplus:${this.RoutePageNames[key + location.search]}`;
197      }
198
199    },
200    setPageName() {
201      if (!this.pageName) {
202        return;
203      }
204      window.aiaDatalayer = window.aiaDatalayer || {};
205      window.aiaDatalayer.pageInfo = window.aiaDatalayer.pageInfo || {};
206      window.aiaDatalayer.pageInfo.pageName = this.pageName;
207      setTimeout(function () {
208        if (sessionStorage.getItem("appMode") === "true") {
209          let time = 0;
210          let timer = setInterval(() => {
211            if (time > 5000) {
212              clearInterval(timer);
213              return;
214            }
215            time += 200;
216            if (window.postMessage.toString().includes("waitForAcknowledgement")) {
217              clearInterval(timer);
218              window.postMessage(
219                JSON.stringify({
220                  eventName: "SET_PAGE_NAME",
221                  value: window.aiaDatalayer.pageInfo.pageName.replace("hk:aiaplus:", "")
222                })
223              );
224            }
225          }, 200)
226        }
227      }, 500)
228    },
229    getCurrentLanguage(type) {
230      const url = this.pathname;
231      if (url.includes("/zh-cn/")) {
232        return type === "upper" ? "zh_CN" : "zh-cn";
233      }
234      if (url.includes("/zh-hk/")) {
235        return type === "upper" ? "zh_HK" : "zh-hk";
236      }
237
238      return type === "upper" ? "en_HK" : "en";
239    },
240    getCurrentPathname() {
241      const lang = this.getCurrentLanguage();
242      if (lang === "zh-cn" || lang === "zh-hk") {
243        const index = this.pathname.indexOf(`/${lang}/`);
244        return this.pathname.slice(index + 6);
245      } else {
246        const index = this.pathname.indexOf(`/en/`);
247        return this.pathname.slice(index + 3);
248      }
249    },
250    pageView() {
251      if (!this.pageName) {
252        return;
253      }
254      var sessionHashID = sessionStorage.getItem("login_hash");
255      var hasValidHashID = typeof sessionHashID === "string" ? sessionHashID.trim() : sessionHashID;
256      var flag_ReauthPage = this.getCurrentPathname() === this.reAuthOtp && Boolean(hasValidHashID);
257      var flag_noReauthPage = this.getCurrentPathname() !== this.reAuthOtp;
258      if (window.adobeDataLayer && (flag_ReauthPage || flag_noReauthPage)) {
259        window.adobeDataLayer.push({
260          event: "pageView"
261        });
262      } else {
263        window.requestAnimationFrame(AATrackingPageNameSetupApp.pageView.bind(AATrackingPageNameSetupApp));
264      }
265    }
266  }
267};
268
269(function () {
270  var pageNameIntervalId = null;
271
272  function checkPageName() {
273    if (window.aiaPlusRoutePageNames) {
274      clearInterval(pageNameIntervalId);
275      pageNameIntervalId = null;
276      AATrackingPageNameSetupApp.mounted();
277    }
278  }
279
280  pageNameIntervalId = setInterval(checkPageName, 100);
281})();
282
283
284
285var NavAATracking = {
286  data() {
287    return {
288      selector: {
289        meta: "#aiaplus-nav-close-attr",
290        back_icon: "#nav-back",
291        help_icon: "#nav-help",
292        close_icon: "#nav-close",
293        langEN_icon: "#nav-lang-en",
294        langSC_icon: "#nav-lang-sc",
295        langTC_icon: "#nav-lang-tc",
296        help_dialog_title: ".modalTitle",
297        close_dialog_title: ".confirm-modal-title",
298        close_dialog_confirm: ".confirm-modal-wrap .confirm",
299        close_dialog_cancel: ".confirm-modal-wrap .cancel"
300      }
301    };
302  },
303  mounted() {
304    var data = this.data();
305    for (var i in data) {
306      this[i] = data[i];
307    }
308    for (var i in this.methods) {
309      this[i] = this.methods[i];
310    }
311    this.init();
312  },
313  methods: {
314    init() {
315      this.setNavTagEvent();
316    },
317    setNavTagEvent() {
318      var navCloseValue = $(this.selector.meta) ? $(this.selector.meta).attr("content") : "false";
319      // back_icon
320      $(document).on("click", this.selector.back_icon, () => { 
321        console.log("nav-back_icon");
322        var clickAAParams = {
323          eventName: "buttonClicks",
324          event1to100: { event6: { value: 1 } },
325          evars: { eVar32: "back" }
326        };
327        aaTrackingCommonFunction(clickAAParams);
328      });
329      // close_icon
330      $(document).on("click", this.selector.close_icon, () => { 
331        console.log("nav-close_icon");
332        var clickAAParams = {
333          eventName: "buttonClicks",
334          event1to100: { event6: { value: 1 } },
335          evars: { eVar32: "close" }
336        };
337        aaTrackingCommonFunction(clickAAParams);
338        if (navCloseValue !== "true") {
339          var popupAAParams = {
340            eventName: "Popups",
341            event1to100: { event79: { value: 1 } },
342            evars: { eVar83: $(this.selector.close_dialog_title).text() }
343          };
344          aaTrackingCommonFunction(popupAAParams);
345        }
346      });
347      // close dialog confirm_icon
348      $(document).on("click", this.selector.close_dialog_confirm, () => { 
349        console.log("nav-close_dialog_confirm");
350        var clickAAParams = {
351          eventName: "buttonClicks",
352          event1to100: { event6: { value: 1 } },
353          evars: {
354            eVar32: $(this.selector.close_dialog_confirm).text(),
355            eVar83: $(this.selector.close_dialog_title).text()
356          }
357        };
358        aaTrackingCommonFunction(clickAAParams);
359      })
360      // close dialog confirm_icon
361      $(document).on("click", this.selector.close_dialog_cancel, () => { 
362        console.log("nav-close_dialog_cancel");
363        var clickAAParams = {
364          eventName:"buttonClicks",
365          event1to100:{ event6: { value: 1 } },
366          evars:{
367            eVar32: $(this.selector.close_dialog_cancel).text(),
368            eVar83: $(this.selector.close_dialog_title).text()
369          }
370        }
371        aaTrackingCommonFunction(clickAAParams);
372      })
373      // help_icon: Executed in global function 'aiaplus-getHelp'
374      $(document).on("click", this.selector.help_icon, () => { 
375        console.log("nav-help_icon");
376        var clickAAParams = {
377          eventName: "buttonClicks",
378          event1to100: { event6: { value: 1 } },
379          evars: { eVar32: "Help and Support" }
380        };
381        aaTrackingCommonFunction(clickAAParams);
382      });
383      // langEN_icon
384      $(document).on("click", this.selector.langEN_icon, () => { 
385          console.log("nav-langEN_icon");
386          var clickAAParams = {
387            eventName:"buttonClicks",
388            event1to100:{ event6: { value: 1 } },
389            evars:{ eVar32: "ENG" }
390          }
391          aaTrackingCommonFunction(clickAAParams);
392      });
393      // langSC_icon
394      $(document).on("click", this.selector.langSC_icon, () => { 
395          console.log("nav-langSC_icon");
396          var clickAAParams = {
397            eventName:"buttonClicks",
398            event1to100:{ event6: { value: 1 } },
399            evars:{ eVar32: "简" }
400          }
401          aaTrackingCommonFunction(clickAAParams);
402      });
403      // langTC_icon
404      $(document).on("click", this.selector.langTC_icon, () => { 
405          console.log("nav-langTC_icon");
406          var clickAAParams = {
407            eventName:"buttonClicks",
408            event1to100:{ event6: { value: 1 } },
409            evars:{ eVar32: "繁" }
410          }
411          aaTrackingCommonFunction(clickAAParams);
412      });
413    }
414  }
415};
416
417var pageNavAAInitTimer = setInterval(function () {
418  if (window.jQuery) {
419    $(function(){
420      NavAATracking.mounted();
421    })
422    clearInterval(pageNavAAInitTimer);
423  }
424}, 500);

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.