PageSourceSearch

https://airtel.mg/assets/js/eventTrackerScript.js

js airtel.mg collected 2026-10-02 09:55:16 UTC 3,412 bytes, 129 lines download raw bytes

1class EventTracker {
2  endpointV1 = "/event/v1/add" // For authorized event save
3  endpointV2 = "/event/v2/add" // For non authorized event save
4  initialData = {
5    eventBaseURL: "",
6    channel: "",
7    msisdn: "",
8    xCountry: "",
9    header: {}
10  }
11
12  // Private constructor to prevent direct instantiation
13  constructor() {}
14
15  // Static method to get an instance, if needed
16  static getInstance() {
17    if (!this.instance) {
18      this.instance = new EventTracker()
19    }
20    return this.instance
21  }
22
23  /**
24   *
25   * @param token If user is authorised this argument will consist authorization token otherwise will be empty
26   * @returns the header option values to passed in request header
27   */
28  getHeaderOptions = token => {
29    const headers = {
30      "Content-Type": "application/json",
31      deviceName: "web",
32      msisdn: this.initialData.msisdn || "",
33      channel: this.initialData.channel,
34      "x-country": this.initialData.xCountry,
35      buildNo: 1,
36      ...this.initialData.header
37    }
38
39    if (token) {
40      headers["Authorization"] = `Bearer ${token}`
41    }
42    return headers
43  }
44
45  /**
46   *
47   * @param token If user is authorised this argument will consist authorization token otherwise will be empty
48   * @returns string of endpoint to be called with event data
49   */
50  getEndPoint(token = "") {
51    return token ? this.endpointV1 : this.endpointV2
52  }
53
54  /**
55   * Saves event data to the server.
56   * @param eventData - The data to be saved.
57   */
58  saveEventData(eventData, token="") {
59    try {
60      fetch(
61        `${this.initialData.eventBaseURL}${this.getEndPoint(token)}`,
62        {
63          method: "POST",
64          headers: {
65            ...this.getHeaderOptions(token)
66          },
67          body: JSON.stringify({ events: [eventData] })
68        }
69      )
70        .then(response => response.json())
71        .then(data => {})
72        .catch(error => console.error("Error saving event:", error))
73    } catch (error) {
74      console.error("Synchronous error while saving event data:", error)
75    }
76  }
77
78  /**
79   * Sends the event data to be saved.
80   * @param eventProps - Event data properties to be saved.
81   */
82  send(eventProps) {
83    try {
84      const { eventType, timeStamp, token, msisdn = "", ...rest } = eventProps
85        let eventObj = {
86          eventType: eventType,
87          channel: this.initialData.channel,
88          timeStamp: timeStamp,
89          loggedIn: Boolean(token),
90          msisdn: msisdn,
91          meta: { ...rest }
92        }
93
94        if (msisdn) {
95          eventObj = { ...eventObj, meta: { ...eventObj.meta, msisdn }}
96          if(!this.initialData.msisdn) {
97            this.initialData.msisdn = msisdn
98          }
99        }
100        // Save the event data
101        this.saveEventData(eventObj, token)
102    } catch (error) {
103      console.error("Error sending event:", error)
104    }
105  }
106
107  /**
108   * Initializes the tracker with configuration.
109   * @param initProps - Initialization properties for the tracker.
110   */
111  initialize(initProps) {
112    try {
113      this.initialData = { ...initProps }
114    } catch (error) {
115      console.error("Error initializing event tracker:", error)
116    }
117  }
118}
119
120const init = () => {
121  try {
122    return EventTracker.getInstance();
123  } catch (error) {
124    console.error("Error creating event tracker instance:", error)
125  }
126}
127
128// Created single instance at the module level
129window.eventTrackerInit = init;

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.