1var etCommerceDebugTools = { 2 objectDefinitions: { 3 product: { 4 'id': { 5 required: true, 6 type: 'string', 7 allowEmpty: false 8 }, 9 'name': { 10 required: true, 11 type: 'string', 12 allowEmpty: false 13 }, 14 'category': { 15 required: false, 16 type: 'array', 17 allowEmpty: true, 18 checkFunc: function (value) { 19 var checkArray = etCommerceDebugTools.checkArrayForLengthAndAllowedType(value, 'string', 0, 4, true); 20 if (!checkArray) { 21 etCommerce.debug('etracker et_commerce error: invalid category at product object. only strings allowed in the array and max 4 entries'); 22 } 23 return checkArray; 24 } 25 }, 26 'price': { 27 required: true, 28 type: 'string|number|integer', 29 allowEmpty: false, 30 checkFunc: function (value) { 31 var numberPattern = /^[+-]?((\d+\.\d*)|(\.\d+)|(\d+))([eE][+-]?\d+)?$/; 32 33 if (typeof value === 'number' || (typeof value === 'string' && numberPattern.test(value))) { 34 return true; 35 } 36 37 etCommerce.debug('etracker et_commerce error: invalid NumberString: ' + value + ' for price'); 38 return false; 39 } 40 }, 41 'currency': { 42 required: true, 43 type: 'string', 44 allowEmpty: false 45 }, 46 'coupon': { 47 required: false, 48 type: 'string', 49 allowEmpty: true, 50 checkFunc: function (value) { 51 if (!value.match(/^[\s\S]{0,50}$/)) { 52 etCommerce.debug('etracker et_commerce error: invalid String: ' + value + ' for coupon'); 53 return false; 54 } 55 return true; 56 } 57 }, 58 'discount': { 59 required: false, 60 type: 'string|number|integer', 61 allowEmpty: true, 62 checkFunc: function (value) { 63 var numberPattern = /^[+-]?[((\d+\.\d*)|(\.\d+)|(\d+))]{0,20}$/; 64 65 if (typeof value === 'number' || (typeof value === 'string' && numberPattern.test(value))) { 66 return true; 67 } 68 69 etCommerce.debug('etracker et_commerce error: invalid or too long NumberString: ' + value + ' for discount'); 70 return false; 71 } 72 }, 73 'variants': { 74 required: false, 75 type: 'object', 76 allowEmpty: true, 77 checkFunc: function (value) { 78 var validVariants = etCommerceDebugTools.validateVariantsObject(value); 79 if (!validVariants) { 80 etCommerce.debug('etracker et_commerce error: invalid variants Object. Maximum 5 Variants allowed, no empty keys or values, wrong keys, Strings only.'); 81 } 82 return validVariants; 83 } 84 }, 85 'pro_name': { 86 required: false, 87 type: 'string', 88 allowEmpty: true 89 }, 90 'ean': { 91 required: false, 92 type: 'string', 93 allowEmpty: true 94 }, 95 'score': { 96 required: false, 97 type: 'integer', 98 allowEmpty: true, 99 checkFunc: function (value) { 100 if (value < 0) { 101 etCommerce.debug('etracker et_commerce error: invalid score: ' + value); 102 return false; 103 } 104 return true; 105 } 106 } 107 }, 108 basket: { 109 'id': { 110 required: true, 111 type: 'string', 112 allowEmpty: false 113 }, 114 'products': { 115 required: true, 116 type: 'array', 117 allowEmpty: false, 118 checkFunc: function (value) {
119 var validProductsArray = etCommerceDebugTools.checkArrayOfProductObjects(value); 120 if (!validProductsArray) { 121 etCommerce.debug('etracker et_commerce error: invalid products Array. at least one Product required and Products must be Valid.'); 122 } 123 return validProductsArray; 124 } 125 } 126 }, 127 order: { 128 'orderNumber': { 129 required: true, 130 type: 'string', 131 allowEmpty: false 132 }, 133 'status': { 134 required: true, 135 type: 'string', 136 allowEmpty: false, 137 checkFunc: function (value) { 138 var validEnum = etCommerceDebugTools.checkEnum(value, ['lead', 'sale', 'storno', 'partial_storno']); 139 if (!validEnum) { 140 etCommerce.debug('etracker et_commerce error: invalid status Enum. only "lead", "sale", "storno" and "partial_storno" are valid, ' + value + ' given'); 141 } 142 return validEnum; 143 } 144 }, 145 'orderPrice': { 146 required: true, 147 type: 'string|number|integer', 148 allowEmpty: false, 149 checkFunc: function (value) { 150 var numberPattern = /^[+-]?((\d+\.\d*)|(\.\d+)|(\d+))([eE][+-]?\d+)?$/; 151 152 if (typeof value === 'number' || (typeof value === 'string' && numberPattern.test(value))) { 153 return true; 154 } 155 156 etCommerce.debug('etracker et_commerce error: invalid NumberString: ' + value + ' for orderPrice'); 157 return false; 158 } 159 }, 160 'currency': { 161 required: true, 162 type: 'string', 163 allowEmpty: false 164 }, 165 'coupon': { 166 required: false, 167 type: 'string', 168 allowEmpty: true, 169 checkFunc: function (value) { 170 if (!value.match(/^[\s\S]{0,50}$/)) { 171 etCommerce.debug('etracker et_commerce error: String length exceeded: ' + value + ' for coupon'); 172 return false; 173 } 174 return true; 175 } 176 }, 177 'basket': { 178 required: true, 179 type: 'object', 180 allowEmpty: false, 181 checkFunc: function (value) { 182 var checkObject = etCommerceDebugTools.validateObject('basket', value); 183 if (!checkObject) { 184 etCommerce.debug('etracker et_commerce error: invalid basket Object'); 185 } 186 return checkObject; 187 } 188 }, 189 'em': { 190 required: false, 191 type: 'string', 192 allowEmpty: true 193 }, 194 'customerId': { 195 required: false, 196 type: 'string', 197 allowEmpty: true 198 }, 199 'customerGroup': { 200 required: false, 201 type: 'string', 202 allowEmpty: true 203 }, 204 'customerAddress': { 205 required: false, 206 type: 'string', 207 allowEmpty: true 208 }, 209 'invoiceAddress': { 210 required: false, 211 type: 'string', 212 allowEmpty: true 213 }, 214 'paymentMethod': { 215 required: false, 216 type: 'string', 217 allowEmpty: true 218 }, 219 'deliveryConditions': { 220 required: false, 221 type: 'string', 222 allowEmpty: true 223 }, 224 'paymentConditions': { 225 required: false, 226 type: 'string', 227 allowEmpty: true 228 }, 229 'shipType': { 230 required: false, 231 type: 'string', 232 allowEmpty: true 233 }, 234 'shipCosts': { 235 required: false, 236 type: 'string|number|integer', 237 allowEmpty: true, 238 checkFunc: function (value) { 239 var numberPattern = /^[+-]?((\d+\.\d*)|(\.\d+)|(\d+))([eE][+-]?\d+)?$/; 240 241 if (typeof value === 'number' || (typeof value === 'string' && numberPattern.test(value))) { 242 return true; 243 } 244 245 etCommerce.debug('etracker et_commerce error: invalid NumberString: ' + value + ' for shipCosts'); 246 return false;
247 } 248 }, 249 'couponCodes': { 250 required: false, 251 type: 'string', 252 allowEmpty: true 253 }, 254 'giftPackage': { 255 required: false, 256 type: 'array', 257 allowEmpty: true, 258 checkFunc: function (value) { 259 var checkArray = etCommerceDebugTools.checkArrayForLengthAndAllowedType(value, 'string', 0, 1000, false); 260 if (!checkArray) { 261 etCommerce.debug('etracker et_commerce error: invalid giftPackage at product object. only strings allowed in the array and max 1000 entries'); 262 } 263 return checkArray; 264 } 265 }, 266 'differenceData': { 267 required: false, 268 type: 'integer', 269 allowEmpty: true 270 }, 271 'waParameter': { // waParameter is special, autogenerated to flag converted wa events. it makes no sense to leave this empty. 272 required: false, 273 type: 'string', 274 allowEmpty: false 275 } 276 }, 277 productList: { 278 'listType': { 279 required: false, 280 type: 'string', 281 allowEmpty: true 282 }, 283 'products': { 284 required: true, 285 type: 'array', 286 allowEmpty: true, 287 checkFunc: function (value) { 288 var validProductsList = false; 289 290 if (etCommerce.typeOf(value) !== 'array' || value.length < 0) { 291 etCommerce.debug('etracker et_commerce error: invalid array of products'); 292 } else { 293 for (var key in value) { 294 if (value.hasOwnProperty(key)) { 295 if (!etCommerceDebugTools.validateObject('product', value[key])) { 296 return false; 297 } 298 } 299 } 300 validProductsList = true; 301 } 302 303 304 if (!validProductsList) { 305 etCommerce.debug('etracker et_commerce error: invalid product list. Products must be Valid.'); 306 } 307 return validProductsList; 308 } 309 } 310 } 311 }, 312 validateEvent: function (jsonData, eventName, usedArguments) { 313 if (jsonData.length > (16 * window.et_maxUrlLength)) { 314 etCommerce.debug('etracker et_commerce: the event is too large, it will not be counted.'); 315 } 316 317 if (this.validateEventCall(eventName, usedArguments)) { 318 etCommerce.debug('etracker et_commerce: valid "' + eventName + '" event'); 319 etCommerce.debug(jsonData); 320 return true; 321 } else { 322 etCommerce.debug('etracker et_commerce error: invalid "' + eventName + '" event'); 323 return false; 324 } 325 }, 326 validateEventCall: function (eventName, validateArguments) { 327 var ret = true, eventDefinition = etCommerce.eventDefintions[eventName], 328 tmpArguments = validateArguments.slice(1); 329 330 if (eventDefinition === undefined) { 331 etCommerce.debug('etracker et_commerce error: unknown event type "' + eventName + '", no event definition found'); 332 ret = false;
333 } 334 335 // check for valid argument count 336 var requiredParamsCnt = 0, storeParamInfos = []; 337 for (var key in eventDefinition) { 338 if (eventDefinition.hasOwnProperty(key)) { 339 if (!eventDefinition[key].optional) { 340 requiredParamsCnt++; 341 } 342 343 storeParamInfos.push(eventDefinition[key]); 344 } 345 } 346 347 if (requiredParamsCnt > tmpArguments.length) { 348 etCommerce.debug('etracker et_commerce error: required params missing in event call "' + eventName + '"'); 349 ret = false; 350 } 351 352 // check param types 353 var paramCount = 0; 354 355 for (key in tmpArguments) { 356 if (tmpArguments.hasOwnProperty(key)) { 357 if (storeParamInfos[paramCount] === undefined) { 358 etCommerce.debug('etracker et_commerce error: event name "' + eventName + '" is invalid'); 359 return false; 360 } 361 362 var value = tmpArguments[key]; 363 var paramType = storeParamInfos[paramCount].type; 364 var paramIsOptional = storeParamInfos[paramCount].optional; 365 var paramAllowEmpty = storeParamInfos[paramCount].allowEmpty; 366 var paramCheckFunc = storeParamInfos[paramCount].checkFunc ? storeParamInfos[paramCount].checkFunc : false; 367 368 if (paramIsOptional && value !== undefined && value !== null && !isNaN(value)) { 369 if (!etCommerceDebugTools.isValidType(paramType, value)) { 370 etCommerce.debug('etracker et_commerce error: wrong param type at position "' + key + '". expected: "' + paramType + '" is: "' + etCommerce.typeOf(value) + '"'); 371 ret = false;
372 } 373 374 if (!etCommerceDebugTools.isNotEmptyValue(paramAllowEmpty, value)) { 375 etCommerce.debug('etracker et_commerce error: empty ' + paramType + ' parameter at position ' + key + ' is not allowed'); 376 ret = false; 377 } 378 379 if (value.length > 512) { 380 etCommerce.debug('etracker et_commerce error: too long ' + paramType + ' parameter at position ' + key + ' (max 512 chars)'); 381 ret = false; 382 } 383 } 384 385 // run callback function 386 if (paramCheckFunc) { 387 ret = ret && paramCheckFunc(value); 388 } 389 390 paramCount++; 391 } 392 } 393 394 return ret; 395 }, 396 checkEnum: function (value, allowedStrings) { 397 for (var key in allowedStrings) { 398 if (allowedStrings.hasOwnProperty(key)) { 399 if (allowedStrings[key] == value) { 400 return true; 401 } 402 } 403 } 404 return false; 405 }, 406 checkArrayForLengthAndAllowedType: function (value, allowedType, min, max, allowEmpty) { 407 if (value.length < min || value.length > max) { 408 return false; 409 } 410 for (var key in value) { 411 if (value.hasOwnProperty(key)) { 412 if (etCommerce.typeOf(value[key]) != allowedType || (value[key] == '' && !allowEmpty)) { 413 return false; 414 } 415 } 416 } 417 return true; 418 }, 419 validateVariantsObject: function (variants) { 420 if (variants.length > 5) { 421 return false; 422 } 423 var validKeys = ["var1", "var2", "var3", "var4", "var5"]; 424 for (var key in variants) { 425 if (variants.hasOwnProperty(key)) { 426 if ((key.length < 1) || etCommerce.typeOf(variants[key]) !== 'string' || variants[key] === '' || !validKeys.includes(key)) { 427 return false; 428 } 429 } 430 } 431 return true; 432 }, 433 checkArrayOfProductObjects: function (dataValue) { 434 var ret = false;
435 436 if (etCommerce.typeOf(dataValue) == 'array' && dataValue.length > 0) { 437 for (var key in dataValue) { 438 if (dataValue.hasOwnProperty(key)) { 439 var quantity = dataValue[key].quantity; 440 if (!quantity) { 441 etCommerce.debug('etracker et_commerce error: missing quantity property at product basket object'); 442 return false; 443 } 444 445 if (!etCommerceDebugTools.isValidType("integer", quantity)) { 446 etCommerce.debug('etracker et_commerce error: quantity property is not a valid integer at product basket object'); 447 return false; 448 } 449 450 if (!etCommerceDebugTools.isNotEmptyValue(false, quantity) || quantity < 1) { 451 etCommerce.debug('etracker et_commerce error: empty quantity property at product basket object'); 452 return false; 453 } 454 if (!etCommerceDebugTools.validateObject('product', dataValue[key].product)) { 455 return false; 456 } 457 if (!etCommerceDebugTools.checkObjectLength(dataValue[key], 2, 2)) { 458 etCommerce.debug('etracker et_commerce error: only quantity and product allowed in a product array'); 459 return false; 460 } 461 } 462 } 463 ret = true; 464 } else { 465 etCommerce.debug('etracker et_commerce error: invalid array of products'); 466 } 467 return ret; 468 }, 469 checkObjectLength: function (obj, min, max) { 470 var length = 0; 471 for (var i in obj) length++; 472 return max >= length && length >= min; 473 }, 474 validateObject: function (objectName, dataValue) { 475 var definition = etCommerceDebugTools.objectDefinitions[objectName], ret = false;
476 for (var key in definition) { 477 if (definition.hasOwnProperty(key)) { 478 if (definition[key].required && !dataValue[key]) { 479 etCommerce.debug('etracker et_commerce error: missing or empty "' + key + '" property at object "' + objectName + '"'); 480 return false; 481 } 482 483 if (etCommerce.typeOf(dataValue[key]) === 'undefined') { 484 continue; 485 } 486 487 if (!etCommerceDebugTools.isNotEmptyValue(definition[key].allowEmpty, dataValue[key])) { 488 etCommerce.debug('etracker et_commerce error: empty "' + key + '" property at object "' + objectName + '" is not allowed'); 489 return false; 490 } 491 492 if (!etCommerceDebugTools.isValidType(definition[key].type, dataValue[key])) { 493 etCommerce.debug('etracker et_commerce error: wrong param type at object "' + objectName + '". property: "' + key + '" expected: "' + definition[key].type + '" is: "' + etCommerce.typeOf(dataValue[key]) + '"'); 494 return false; 495 } 496 497 if (definition[key].checkFunc && etCommerce.typeOf(definition[key].checkFunc) === 'function') { 498 if (!definition[key].checkFunc(dataValue[key])) { 499 return false; 500 } 501 } 502 } 503 } 504 505 for (key in dataValue) { 506 if (dataValue.hasOwnProperty(key)) { 507 if (!definition[key]) { 508 etCommerce.debug('etracker et_commerce error: unknown object property "' + key + '" (object: ' + objectName + ')'); 509 return false; 510 } 511 } 512 } 513 return true; 514 }, 515 isNotEmptyValue: function (paramAllowEmpty, value) { 516 var isNotEmpty = true; 517 switch (etCommerce.typeOf(value)) { 518 case 'string | number': 519 isNotEmpty = (paramAllowEmpty || value != 0) && value !== '' && Math.abs(value) < 65535; 520 break; 521 case 'string': 522 isNotEmpty = paramAllowEmpty || value != ''; 523 break; 524 case 'integer': 525 isNotEmpty = (paramAllowEmpty || value != 0) && Math.abs(value) < 65535; 526 break; 527 case 'number': 528 isNotEmpty = (paramAllowEmpty || value != 0) && Math.abs(value) < 65535; 529 break; 530 case 'array': 531 isNotEmpty = paramAllowEmpty || value.length > 0; 532 break; 533 case 'object': 534 for (var prop in value) { 535 if (value.hasOwnProperty(prop)) { 536 isNotEmpty = true; 537 } 538 } 539 isNotEmpty = isNotEmpty || paramAllowEmpty; 540 break; 541 } 542 return isNotEmpty; 543 }, 544 isValidType: function(exceptedType, value) { 545 var actualType = etCommerce.typeOf(value); 546 547 if (actualType === 'function') { 548 return false; 549 } 550 551 var allowedTypes = exceptedType.split('|'); 552 553 for (var j = 0; j < allowedTypes.length; j++) { 554 if (allowedTypes[j] === actualType) { 555 return true; 556 } 557 } 558 559 return false; 560 } 561};
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.