PageSourceSearch

https://www.allvest.de/_next_assets/utils/atl/consumers/ca-consumer.js

js allvest.de collected 2026-10-07 14:09:43 UTC 8,814 bytes, 250 lines download raw bytes

1/**
2 * Extension of the ATL in order to support CommandersAct as a consumer type.
3 *
4 * Related Jira Tickets
5 * https://allvest.atlassian.net/browse/OTA-109
6 */
7'use strict';
8
9(function () {
10  /* CA Consumer */
11  var CommandersActConsumer = (function () {
12    function CommandersActConsumerInternal() {
13      this.logger = console; // TODO: Other Logger!
14      this.initState = 'none'; // [none, running, finished, failed]
15      this.consumerConfig = null;
16    }
17
18    // === Helpers === //
19    function isNonEmptyString(v) {
20      return typeof v === 'string' && v !== '';
21    }
22    function eachRecursive(strCurrStem, arTranslate, oCurrentNode) {
23      var arSubNodeFlat = {};
24      var arChildFlat = {};
25      for (var strKey in oCurrentNode) {
26        if (!oCurrentNode.hasOwnProperty(strKey)) {
27          continue;
28        }
29        var numKey = Number(strKey);
30        // DS-START: If next key is numbered array-element with filled "name" & contains "value" property
31        // if (strCurrStem == "q_attr") debugger;
32        if (
33          !isNaN(numKey) &&
34          Object.keys(oCurrentNode[numKey]).length === 2 &&
35          oCurrentNode[numKey].hasOwnProperty('name') &&
36          'name' in oCurrentNode[numKey] &&
37          oCurrentNode[numKey].hasOwnProperty('value')
38        ) {
39          // Append name/value leaf
40          arSubNodeFlat[strCurrStem + '_' + oCurrentNode[numKey].name] = oCurrentNode[numKey].value;
41          continue;
42        } // DS-END ...else process as usually
43        var strCurrShortKey = void 0;
44        if (typeof arTranslate[strKey] !== 'undefined') {
45          strCurrShortKey = arTranslate[strKey];
46        } else {
47          strCurrShortKey = strKey;
48        } // end else (typeof arTranslate[strKey] !== "undefined")
49        // var strNewStem = strCurrShortKey; //DS: Moved to else to save double assignments
50        var strNewStem = void 0;
51        if (strCurrStem !== '') {
52          strNewStem = strCurrStem + '_' + strCurrShortKey;
53        } else {
54          strNewStem = strCurrShortKey;
55        }
56        if (typeof oCurrentNode[strKey] === 'object' && oCurrentNode[strKey] !== null) {
57          arChildFlat = eachRecursive(strNewStem, arTranslate, oCurrentNode[strKey]);
58          for (var strFlatChildKey in arChildFlat) {
59            if (!arChildFlat.hasOwnProperty(strFlatChildKey)) {
60              continue;
61            }
62            arSubNodeFlat[strFlatChildKey] = arChildFlat[strFlatChildKey];
63          } // Maybe referencing would be better than loopcopy considering memoryusage?
64        } else {
65          if (oCurrentNode[strKey] !== null) {
66            arSubNodeFlat[strNewStem] = oCurrentNode[strKey];
67          }
68        } // end else (... subnode ...)
69      } // end for (var strKey in oCurrentNode)
70      return arSubNodeFlat;
71    }
72    var arShortKeyTranslation = {
73      page: 'pg',
74      pageInfo: 'pInfo',
75      component: 'cmp',
76      attributes: 'attr',
77      attribute: 'attr',
78      quoteDetails: 'qDetail',
79      quote: 'q',
80      product: 'prd',
81      coverage: 'cov',
82      objects: 'obj',
83      vehicle: 'car',
84      building: 'bld',
85      content: 'cnt',
86      enterprise: 'ent',
87      persons: 'pers',
88      policyHolder: 'pHldr',
89      purchasedProducts: 'purchPrd',
90      customerPortal: 'custPort',
91      modifiedProduct: 'modPrd',
92      transaction: 'trans',
93      application: 'app',
94      marketingCampaign: 'mCmp',
95      process: 'pr',
96      processName: 'prName',
97      previousProcessName: 'prevPrName',
98      stepName: 'stName',
99      stepNumber: 'stNr',
100      engagement: 'eng',
101      service: 'selfSrv',
102      error: 'err',
103      organisationalEntity: 'oe',
104      environment: 'env',
105    };
106
107    CommandersActConsumerInternal.prototype.init = function (consumerConfig, envStage, callbackInitializationFinished) {
108      try {
109        var self = this;
110        // self.logger.debug('initConsumer', arguments);
111        self.consumerConfig = consumerConfig;
112
113        // === dont run again === //
114        if (self.initState !== 'none') {
115          return;
116        } // dont run again!
117        self.initState = 'running';
118
119        // === check if script of that type was loaded already === //
120        // window.tC.event.MIXready is loaded by footer snippet!
121        if (
122          window.tC &&
123          window.tC.event &&
124          typeof window.tC.event.MIXready === 'function' &&
125          window.ca_global_footer_atl
126        ) {
127          self.initState = 'finished';
128          callbackInitializationFinished();
129          return;
130        }
131
132        /* === todo define tc_vars ? === //
133            window.tc_vars = window.tc_vars || {};
134            window.tc_vars = Object.assign({}, window.tc_vars, {
135                env_template: "test environment",
136                env_work: "dev"
137            });
138            // ===
139        */
140
141        // === Grab URL and load script === //
142        var envMapping = consumerConfig && consumerConfig.config && consumerConfig.config.envToUrlMapping;
143        var scriptURL = undefined;
144        if (envMapping) {
145          var defaultKey = envMapping.default;
146          scriptURL = envMapping[envStage] || envMapping[defaultKey];
147        }
148        if (!scriptURL) {
149          self.initState = 'failed';
150          throw `no script url provided`;
151        }
152
153        // === States === //
154        var onError = function () {
155          self.initState = 'failed';
156        };
157        var onSuccess = function () {
158          self.initState = 'finished';
159          callbackInitializationFinished();
160        };
161        // === addScript === //
162        var script = document.createElement('script');
163        script.async = true;
164        script.src = scriptURL;
165        script.addEventListener('load', onSuccess);
166        script.addEventListener('error', onError);
167        script.addEventListener('abort', onError);
168        document.head.appendChild(script);
169      } catch (e) {
170        self.logger.error('CAConsumerInit', e);
171      }
172    };
173
174    CommandersActConsumerInternal.prototype.isInitialized = function () {
175      var bool = this.initState === 'finished';
176      // this.logger.debug('isInitialized:', bool);
177      return bool;
178    };
179
180    CommandersActConsumerInternal.prototype.getName = function () {
181      // this.logger.debug('getName');
182      return this.consumerConfig && this.consumerConfig.name;
183    };
184
185    CommandersActConsumerInternal.prototype.track = function (event, datalayer, done) {
186      var self = this;
187      // self.logger.debug('track', event, datalayer);
188      done();
189
190      // if (!self.isInitialized()) {
191      //   self.logger.debug('not initialized, can not track event');
192      // }
193
194      datalayer = datalayer || { data: {}, state: 'submitted', id: 999 }; // AllianzTrackingLibrary_model_1.DataLayerState.SUBMITTED => "submitted"
195      datalayer.data = datalayer.data || {};
196
197      // === format data === //
198      var oLocalData = {};
199      var arFlatResult = eachRecursive('', arShortKeyTranslation, datalayer.data);
200      for (var strFlatKey in arFlatResult) {
201        if (
202          !arFlatResult.hasOwnProperty(strFlatKey) ||
203          arFlatResult[strFlatKey] === undefined ||
204          arFlatResult[strFlatKey] === null
205        ) {
206          continue;
207        }
208        oLocalData[strFlatKey] = arFlatResult[strFlatKey].toString();
209      }
210      oLocalData.type = 'CommandersActConsumerType';
211
212      // > CommandersAct Special: join ProcessName, StepNumber and StepName
213      if (
214        isNonEmptyString(oLocalData.pr_prName) &&
215        isNonEmptyString(oLocalData.pr_stNr) &&
216        isNonEmptyString(oLocalData.pr_stName)
217      ) {
218        oLocalData.pr_pos = [oLocalData.pr_prName, oLocalData.pr_stNr, oLocalData.pr_stName].join('_');
219      }
220
221      // === send data === //
222      var eventLabel = 'atl_' + event.name;
223      if (window.tC.event && typeof window.tC.event[eventLabel] === 'function') {
224        // self.logger.debug(`[TagCommander] Tracking event ${eventLabel}`, {}, oLocalData);
225        window.tC.container.reload({ exclusions: ['deduplication'] });
226        window.tC.event[eventLabel]({}, oLocalData);
227      } else {
228        self.logger.warn(`[TagCommander] The event with the label ${eventLabel} does not exist`);
229      }
230      done();
231    };
232    CommandersActConsumerInternal.type = 'CommandersActConsumerType';
233    return CommandersActConsumerInternal;
234  })();
235
236  var ExtCreator = (function () {
237    function Creator(ctor) {
238      this.ctor = ctor;
239    }
240
241    Creator.prototype.getNew = function (config, envStage, callbackInitializationFinished) {
242      var consumer = new this.ctor();
243      consumer.init(config, envStage, callbackInitializationFinished);
244      return consumer;
245    };
246    return Creator;
247  })();
248
249  AllianzTrackingLibrary.registerConsumerType(CommandersActConsumer.type, new ExtCreator(CommandersActConsumer));
250})();

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.