admin.js
3 years ago
bootstrap.min.js
5 years ago
jquery.bind-first-0.2.3.min.js
5 years ago
js.cookie-2.1.3.min.js
5 years ago
popper.min.js
5 years ago
public.bundle.js
2 years ago
public.js
2 years ago
select2.min.js
3 years ago
public.js
2856 lines
| 1 | /* global pysOptions */ |
| 2 | |
| 3 | // https://bitbucket.org/pixelyoursite/pys_pro_7/issues/7/possible-ie-11-error |
| 4 | // https://tc39.github.io/ecma262/#sec-array.prototype.includes |
| 5 | if (!Array.prototype.includes) { |
| 6 | Object.defineProperty(Array.prototype, 'includes', { |
| 7 | value: function (searchElement, fromIndex) { |
| 8 | |
| 9 | if (this == null) { |
| 10 | throw new TypeError('"this" is null or not defined'); |
| 11 | } |
| 12 | |
| 13 | // 1. Let O be ? ToObject(this value). |
| 14 | var o = Object(this); |
| 15 | |
| 16 | // 2. Let len be ? ToLength(? Get(O, "length")). |
| 17 | var len = o.length >>> 0; |
| 18 | |
| 19 | // 3. If len is 0, return false. |
| 20 | if (len === 0) { |
| 21 | return false; |
| 22 | } |
| 23 | |
| 24 | // 4. Let n be ? ToInteger(fromIndex). |
| 25 | // (If fromIndex is undefined, this step produces the value 0.) |
| 26 | var n = fromIndex | 0; |
| 27 | |
| 28 | // 5. If n ≥ 0, then |
| 29 | // a. Let k be n. |
| 30 | // 6. Else n < 0, |
| 31 | // a. Let k be len + n. |
| 32 | // b. If k < 0, let k be 0. |
| 33 | var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); |
| 34 | |
| 35 | function sameValueZero(x, y) { |
| 36 | return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); |
| 37 | } |
| 38 | |
| 39 | // 7. Repeat, while k < len |
| 40 | while (k < len) { |
| 41 | // a. Let elementK be the result of ? Get(O, ! ToString(k)). |
| 42 | // b. If SameValueZero(searchElement, elementK) is true, return true. |
| 43 | if (sameValueZero(o[k], searchElement)) { |
| 44 | return true; |
| 45 | } |
| 46 | // c. Increase k by 1. |
| 47 | k++; |
| 48 | } |
| 49 | |
| 50 | // 8. Return false |
| 51 | return false; |
| 52 | } |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | !function ($, options) { |
| 57 | |
| 58 | if (options.debug) { |
| 59 | console.log('PYS:', options); |
| 60 | } |
| 61 | |
| 62 | var dummyPinterest = function () { |
| 63 | |
| 64 | /** |
| 65 | * Public API |
| 66 | */ |
| 67 | return { |
| 68 | |
| 69 | isEnabled: function () { |
| 70 | }, |
| 71 | |
| 72 | disable: function () { |
| 73 | }, |
| 74 | |
| 75 | loadPixel: function () { |
| 76 | }, |
| 77 | |
| 78 | fireEvent: function (name, data) { |
| 79 | return false; |
| 80 | }, |
| 81 | |
| 82 | onCommentEvent: function () { |
| 83 | }, |
| 84 | |
| 85 | onDownloadEvent: function (params) { |
| 86 | }, |
| 87 | |
| 88 | onFormEvent: function (params) { |
| 89 | }, |
| 90 | |
| 91 | onWooAddToCartOnButtonEvent: function (product_id) { |
| 92 | }, |
| 93 | |
| 94 | onWooAddToCartOnSingleEvent: function (product_id, qty, is_variable, is_external, $form) { |
| 95 | }, |
| 96 | |
| 97 | onWooRemoveFromCartEvent: function (cart_item_hash) { |
| 98 | }, |
| 99 | |
| 100 | onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { |
| 101 | }, |
| 102 | |
| 103 | onEddRemoveFromCartEvent: function (item) { |
| 104 | }, |
| 105 | onPageScroll: function (event) {}, |
| 106 | onTime: function (event) { |
| 107 | |
| 108 | }, |
| 109 | |
| 110 | } |
| 111 | |
| 112 | }(); |
| 113 | |
| 114 | var dummyBing = function () { |
| 115 | |
| 116 | /** |
| 117 | * Public API |
| 118 | */ |
| 119 | return { |
| 120 | |
| 121 | isEnabled: function () { |
| 122 | }, |
| 123 | |
| 124 | disable: function () { |
| 125 | }, |
| 126 | |
| 127 | loadPixel: function () { |
| 128 | }, |
| 129 | |
| 130 | fireEvent: function (name, data) { |
| 131 | return false; |
| 132 | }, |
| 133 | |
| 134 | onAdSenseEvent: function () { |
| 135 | }, |
| 136 | |
| 137 | onClickEvent: function (params) { |
| 138 | }, |
| 139 | |
| 140 | onWatchVideo: function (params) { |
| 141 | }, |
| 142 | |
| 143 | onCommentEvent: function () { |
| 144 | }, |
| 145 | |
| 146 | onFormEvent: function (params) { |
| 147 | }, |
| 148 | |
| 149 | onDownloadEvent: function (params) { |
| 150 | }, |
| 151 | |
| 152 | onWooAddToCartOnButtonEvent: function (product_id) { |
| 153 | }, |
| 154 | |
| 155 | onWooAddToCartOnSingleEvent: function (product_id, qty, is_variable, is_external, $form) { |
| 156 | }, |
| 157 | |
| 158 | onWooRemoveFromCartEvent: function (cart_item_hash) { |
| 159 | }, |
| 160 | |
| 161 | onWooAffiliateEvent: function (product_id) { |
| 162 | }, |
| 163 | |
| 164 | onWooPayPalEvent: function () { |
| 165 | }, |
| 166 | |
| 167 | onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { |
| 168 | }, |
| 169 | |
| 170 | onEddRemoveFromCartEvent: function (item) { |
| 171 | }, |
| 172 | |
| 173 | onPageScroll: function (event) { |
| 174 | }, |
| 175 | |
| 176 | onTime: function (event) { |
| 177 | }, |
| 178 | |
| 179 | } |
| 180 | |
| 181 | }(); |
| 182 | |
| 183 | var Utils = function (options) { |
| 184 | |
| 185 | var Pinterest = dummyPinterest; |
| 186 | |
| 187 | var Bing = dummyBing; |
| 188 | |
| 189 | var gtag_loaded = false; |
| 190 | |
| 191 | let isNewSession = checkSession(); |
| 192 | |
| 193 | var utmTerms = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']; |
| 194 | |
| 195 | var utmId = ['fbadid', 'gadid', 'padid', 'bingid']; |
| 196 | |
| 197 | function validateEmail(email) { |
| 198 | var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; |
| 199 | return re.test(email); |
| 200 | } |
| 201 | function getDomain(url) { |
| 202 | |
| 203 | url = url.replace(/(https?:\/\/)?(www.)?/i, ''); |
| 204 | |
| 205 | if (url.indexOf('/') !== -1) { |
| 206 | return url.split('/')[0]; |
| 207 | } |
| 208 | |
| 209 | return url; |
| 210 | } |
| 211 | function loadPixels() { |
| 212 | |
| 213 | if (!options.gdpr.all_disabled_by_api) { |
| 214 | |
| 215 | if (!options.gdpr.facebook_disabled_by_api) { |
| 216 | Facebook.loadPixel(); |
| 217 | } |
| 218 | |
| 219 | if (!options.gdpr.analytics_disabled_by_api) { |
| 220 | Analytics.loadPixel(); |
| 221 | } |
| 222 | |
| 223 | if (!options.gdpr.pinterest_disabled_by_api) { |
| 224 | Pinterest.loadPixel(); |
| 225 | } |
| 226 | |
| 227 | if (!options.gdpr.bing_disabled_by_api) { |
| 228 | Bing.loadPixel(); |
| 229 | } |
| 230 | } |
| 231 | if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined") { |
| 232 | if (typeof CS_Data.cs_google_analytics_consent_mode !== "undefined" && CS_Data.cs_google_analytics_consent_mode == 1) { |
| 233 | Analytics.loadPixel(); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | } |
| 238 | |
| 239 | function checkSession() { |
| 240 | let duration = options.last_visit_duration * 60000 |
| 241 | if( Cookies.get('pys_start_session') === undefined || |
| 242 | Cookies.get('pys_session_limit') === undefined) { |
| 243 | var now = new Date(); |
| 244 | now.setTime(now.getTime() + duration); |
| 245 | Cookies.set('pys_session_limit', true,{ expires: now }) |
| 246 | Cookies.set('pys_start_session', true) |
| 247 | return true |
| 248 | } |
| 249 | return false |
| 250 | |
| 251 | } |
| 252 | |
| 253 | function getTrafficSource() { |
| 254 | |
| 255 | try { |
| 256 | |
| 257 | let referrer = document.referrer.toString(), |
| 258 | source; |
| 259 | |
| 260 | let direct = referrer.length === 0; |
| 261 | let internal = direct ? false : referrer.indexOf(options.siteUrl) === 0; |
| 262 | let external = !direct && !internal; |
| 263 | |
| 264 | if (external === false) { |
| 265 | source = 'direct'; |
| 266 | } else { |
| 267 | source = referrer; |
| 268 | } |
| 269 | |
| 270 | if (source !== 'direct') { |
| 271 | // leave only domain (Issue #70) |
| 272 | return getDomain(source); |
| 273 | } else { |
| 274 | return source; |
| 275 | } |
| 276 | |
| 277 | } catch (e) { |
| 278 | console.error(e); |
| 279 | return 'direct'; |
| 280 | } |
| 281 | |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Return query variables object with where property name is query variable |
| 286 | * and property value is query variable value. |
| 287 | */ |
| 288 | function getQueryVars() { |
| 289 | |
| 290 | try { |
| 291 | |
| 292 | var result = {}, |
| 293 | tmp = []; |
| 294 | |
| 295 | window.location.search |
| 296 | .substr(1) |
| 297 | .split("&") |
| 298 | .forEach(function (item) { |
| 299 | |
| 300 | tmp = item.split('='); |
| 301 | |
| 302 | if (tmp.length > 1) { |
| 303 | result[tmp[0]] = tmp[1]; |
| 304 | } |
| 305 | |
| 306 | }); |
| 307 | |
| 308 | return result; |
| 309 | |
| 310 | } catch (e) { |
| 311 | console.error(e); |
| 312 | return {}; |
| 313 | } |
| 314 | |
| 315 | } |
| 316 | |
| 317 | |
| 318 | function getUTMId(useLast = false) { |
| 319 | try { |
| 320 | let cookiePrefix = 'pys_' |
| 321 | let terms = []; |
| 322 | if (useLast) { |
| 323 | cookiePrefix = 'last_pys_' |
| 324 | } |
| 325 | $.each(utmId, function (index, name) { |
| 326 | if (Cookies.get(cookiePrefix + name)) { |
| 327 | terms[name] = Cookies.get(cookiePrefix + name) |
| 328 | } |
| 329 | }); |
| 330 | return terms; |
| 331 | } catch (e) { |
| 332 | console.error(e); |
| 333 | return []; |
| 334 | } |
| 335 | } |
| 336 | /** |
| 337 | * Return UTM terms from request query variables or from cookies. |
| 338 | */ |
| 339 | function getUTMs(useLast = false) { |
| 340 | |
| 341 | try { |
| 342 | let cookiePrefix = 'pys_' |
| 343 | if(useLast) { |
| 344 | cookiePrefix = 'last_pys_' |
| 345 | } |
| 346 | let terms = []; |
| 347 | $.each(utmTerms, function (index, name) { |
| 348 | if (Cookies.get(cookiePrefix + name)) { |
| 349 | let value = Cookies.get(cookiePrefix + name); |
| 350 | terms[name] = filterEmails(value); // do not allow email in request params (Issue #70) |
| 351 | } |
| 352 | }); |
| 353 | |
| 354 | return terms; |
| 355 | |
| 356 | } catch (e) { |
| 357 | console.error(e); |
| 358 | return []; |
| 359 | } |
| 360 | |
| 361 | } |
| 362 | |
| 363 | function getDateTime() { |
| 364 | var dateTime = new Array(); |
| 365 | var date = new Date(), |
| 366 | days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], |
| 367 | months = ['January', 'February', 'March', 'April', 'May', 'June', |
| 368 | 'July', 'August', 'September', 'October', 'November', 'December' |
| 369 | ], |
| 370 | hours = ['00-01', '01-02', '02-03', '03-04', '04-05', '05-06', '06-07', '07-08', |
| 371 | '08-09', '09-10', '10-11', '11-12', '12-13', '13-14', '14-15', '15-16', '16-17', |
| 372 | '17-18', '18-19', '19-20', '20-21', '21-22', '22-23', '23-24' |
| 373 | ]; |
| 374 | dateTime.push(hours[date.getHours()]); |
| 375 | dateTime.push(days[date.getDay()]); |
| 376 | dateTime.push(months[date.getMonth()]); |
| 377 | return dateTime; |
| 378 | } |
| 379 | |
| 380 | function filterEmails(value) { |
| 381 | return validateEmail(value) ? undefined : value; |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * PUBLIC API |
| 386 | */ |
| 387 | return { |
| 388 | PRODUCT_SIMPLE : 0, |
| 389 | PRODUCT_VARIABLE : 1, |
| 390 | PRODUCT_BUNDLE : 2, |
| 391 | PRODUCT_GROUPED : 3, |
| 392 | utmTerms : utmTerms, |
| 393 | utmId : utmId, |
| 394 | fireEventForAllPixel:function(functionName,events){ |
| 395 | if (events.hasOwnProperty(Facebook.tag())) |
| 396 | Facebook[functionName](events[Facebook.tag()]); |
| 397 | if (events.hasOwnProperty(Analytics.tag())) |
| 398 | Analytics[functionName](events[Analytics.tag()]); |
| 399 | if (events.hasOwnProperty(Pinterest.tag())) |
| 400 | Pinterest[functionName](events[Pinterest.tag()]); |
| 401 | if (events.hasOwnProperty(Bing.tag())) |
| 402 | Bing[functionName](events[Bing.tag()]); |
| 403 | }, |
| 404 | |
| 405 | setupPinterestObject: function () { |
| 406 | Pinterest = window.pys.Pinterest || Pinterest; |
| 407 | return Pinterest; |
| 408 | }, |
| 409 | |
| 410 | setupBingObject: function () { |
| 411 | Bing = window.pys.Bing || Bing; |
| 412 | return Bing; |
| 413 | }, |
| 414 | |
| 415 | // Clone all object members to another and return it |
| 416 | copyProperties: function (from, to) { |
| 417 | for (var key in from) { |
| 418 | if("function" == typeof from[key]) { |
| 419 | continue; |
| 420 | } |
| 421 | to[key] = from[key]; |
| 422 | } |
| 423 | return to; |
| 424 | }, |
| 425 | |
| 426 | manageCookies: function () { |
| 427 | let expires = parseInt(options.cookie_duration); // days |
| 428 | let queryVars = getQueryVars(); |
| 429 | let landing = window.location.href.split('?')[0]; |
| 430 | try { |
| 431 | // save data for first visit |
| 432 | if(Cookies.get('pys_first_visit') === undefined && (!options.cookie.disabled_all_cookie)) { |
| 433 | |
| 434 | if(!options.cookie.disabled_first_visit_cookie) |
| 435 | { |
| 436 | Cookies.set('pys_first_visit', true, { expires: expires }); |
| 437 | } |
| 438 | else { |
| 439 | Cookies.remove('pys_first_visit') |
| 440 | } |
| 441 | |
| 442 | if(!options.cookie.disabled_trafficsource_cookie) |
| 443 | { |
| 444 | Cookies.set('pysTrafficSource', getTrafficSource(), { expires: expires }); |
| 445 | } |
| 446 | else { |
| 447 | Cookies.remove('pysTrafficSource') |
| 448 | } |
| 449 | |
| 450 | if(!options.cookie.disabled_landing_page_cookie) |
| 451 | { |
| 452 | Cookies.set('pys_landing_page',landing,{ expires: expires }); |
| 453 | } |
| 454 | else { |
| 455 | Cookies.remove('pys_landing_page') |
| 456 | } |
| 457 | |
| 458 | if(!options.cookie.disabled_utmTerms_cookie) |
| 459 | { |
| 460 | $.each(utmTerms, function (index, name) { |
| 461 | if (queryVars.hasOwnProperty(name)) { |
| 462 | Cookies.set('pys_' + name, queryVars[name], { expires: expires }); |
| 463 | } else { |
| 464 | Cookies.remove('pys_' + name) |
| 465 | } |
| 466 | }); |
| 467 | } |
| 468 | else { |
| 469 | $.each(utmTerms, function (index, name) { |
| 470 | Cookies.remove('pys_' + name) |
| 471 | }); |
| 472 | } |
| 473 | |
| 474 | if(!options.cookie.disabled_utmId_cookie) |
| 475 | { |
| 476 | $.each(utmId,function(index,name) { |
| 477 | if (queryVars.hasOwnProperty(name)) { |
| 478 | Cookies.set('pys_' + name, queryVars[name], { expires: expires }); |
| 479 | } else { |
| 480 | Cookies.remove('pys_' + name) |
| 481 | } |
| 482 | }) |
| 483 | } |
| 484 | else { |
| 485 | $.each(utmId, function (index, name) { |
| 486 | Cookies.remove('pys_' + name) |
| 487 | }); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | // save data for last visit if it new session |
| 492 | if(isNewSession && (!options.cookie.disabled_all_cookie)) { |
| 493 | if(!options.cookie.disabled_trafficsource_cookie) |
| 494 | { |
| 495 | Cookies.set('last_pysTrafficSource', getTrafficSource(), { expires: expires }); |
| 496 | } |
| 497 | else { |
| 498 | Cookies.remove('last_pysTrafficSource') |
| 499 | } |
| 500 | |
| 501 | if(!options.cookie.disabled_landing_page_cookie) |
| 502 | { |
| 503 | Cookies.set('last_pys_landing_page',landing,{ expires: expires }); |
| 504 | } |
| 505 | else { |
| 506 | Cookies.remove('last_pys_landing_page') |
| 507 | } |
| 508 | |
| 509 | if(!options.cookie.disabled_utmTerms_cookie) |
| 510 | { |
| 511 | $.each(utmTerms, function (index, name) { |
| 512 | if (queryVars.hasOwnProperty(name)) { |
| 513 | Cookies.set('last_pys_' + name, queryVars[name], { expires: expires }); |
| 514 | } else { |
| 515 | Cookies.remove('last_pys_' + name) |
| 516 | } |
| 517 | }); |
| 518 | } |
| 519 | else { |
| 520 | $.each(utmTerms, function (index, name) { |
| 521 | Cookies.remove('last_pys_' + name) |
| 522 | }); |
| 523 | } |
| 524 | |
| 525 | if(!options.cookie.disabled_utmId_cookie) |
| 526 | { |
| 527 | $.each(utmId,function(index,name) { |
| 528 | if (queryVars.hasOwnProperty(name)) { |
| 529 | Cookies.set('last_pys_' + name, queryVars[name], { expires: expires }); |
| 530 | } else { |
| 531 | Cookies.remove('last_pys_' + name) |
| 532 | } |
| 533 | }) |
| 534 | } |
| 535 | else { |
| 536 | $.each(utmId, function (index, name) { |
| 537 | Cookies.remove('last_pys_' + name) |
| 538 | }); |
| 539 | } |
| 540 | |
| 541 | } |
| 542 | if(options.cookie.disabled_all_cookie) |
| 543 | { |
| 544 | Cookies.remove('pys_first_visit') |
| 545 | Cookies.remove('pysTrafficSource') |
| 546 | Cookies.remove('pys_landing_page') |
| 547 | Cookies.remove('last_pys_landing_page') |
| 548 | Cookies.remove('last_pysTrafficSource') |
| 549 | Cookies.remove('pys_start_session') |
| 550 | Cookies.remove('pys_session_limit') |
| 551 | $.each(Utils.utmTerms, function (index, name) { |
| 552 | Cookies.remove('pys_' + name) |
| 553 | }); |
| 554 | $.each(Utils.utmId,function(index,name) { |
| 555 | Cookies.remove('pys_' + name) |
| 556 | }) |
| 557 | $.each(Utils.utmTerms, function (index, name) { |
| 558 | Cookies.remove('last_pys_' + name) |
| 559 | }); |
| 560 | $.each(Utils.utmId,function(index,name) { |
| 561 | Cookies.remove('last_pys_' + name) |
| 562 | }); |
| 563 | } |
| 564 | } catch (e) { |
| 565 | console.error(e); |
| 566 | } |
| 567 | }, |
| 568 | // clone object |
| 569 | clone: function(obj) { |
| 570 | var copy; |
| 571 | |
| 572 | // Handle the 3 simple types, and null or undefined |
| 573 | if (null == obj || "object" != typeof obj) return obj; |
| 574 | |
| 575 | // Handle Date |
| 576 | if (obj instanceof Date) { |
| 577 | copy = new Date(); |
| 578 | copy.setTime(obj.getTime()); |
| 579 | return copy; |
| 580 | } |
| 581 | |
| 582 | // Handle Array |
| 583 | if (obj instanceof Array) { |
| 584 | copy = []; |
| 585 | for (var i = 0, len = obj.length; i < len; i++) { |
| 586 | if("function" == typeof obj[i]) { |
| 587 | continue; |
| 588 | } |
| 589 | copy[i] = Utils.clone(obj[i]); |
| 590 | } |
| 591 | return copy; |
| 592 | } |
| 593 | |
| 594 | // Handle Object |
| 595 | if (obj instanceof Object) { |
| 596 | copy = {}; |
| 597 | for (var attr in obj) { |
| 598 | if (obj.hasOwnProperty(attr)) { |
| 599 | if("function" == typeof obj[attr]) { |
| 600 | continue; |
| 601 | } |
| 602 | copy[attr] = Utils.clone(obj[attr]); |
| 603 | } |
| 604 | } |
| 605 | return copy; |
| 606 | } |
| 607 | |
| 608 | return obj; |
| 609 | }, |
| 610 | |
| 611 | // Returns array of elements with given tag name |
| 612 | getTagsAsArray: function (tag) { |
| 613 | return [].slice.call(document.getElementsByTagName(tag)); |
| 614 | }, |
| 615 | |
| 616 | getRequestParams: function () { |
| 617 | return []; |
| 618 | }, |
| 619 | |
| 620 | /** |
| 621 | * CUSTOM EVENTS |
| 622 | */ |
| 623 | |
| 624 | setupMouseOverClickEvents: function (eventId, triggers) { |
| 625 | |
| 626 | // Non-default binding used to avoid situations when some code in external js |
| 627 | // stopping events propagation, eg. returns false, and our handler will never called |
| 628 | document.addEventListener('mouseover', function(event) { |
| 629 | var matchedElements = Array.from(document.querySelectorAll(triggers)); |
| 630 | if (matchedElements.includes(event.target)) { |
| 631 | if (event.target.classList.contains('pys-mouse-over-' + eventId)) { |
| 632 | return true; |
| 633 | } else { |
| 634 | event.target.classList.add('pys-mouse-over-' + eventId); |
| 635 | } |
| 636 | |
| 637 | Utils.fireTriggerEvent(eventId); |
| 638 | } |
| 639 | }); |
| 640 | |
| 641 | }, |
| 642 | |
| 643 | setupCSSClickEvents: function (eventId, triggers) { |
| 644 | // Non-default binding used to avoid situations when some code in external js |
| 645 | // stopping events propagation, eg. returns false, and our handler will never called |
| 646 | document.addEventListener('click', function(event) { |
| 647 | var matchedElements = Array.from(document.querySelectorAll(triggers)); |
| 648 | if (matchedElements.includes(event.target)) { |
| 649 | console.log(event.target) |
| 650 | Utils.fireTriggerEvent(eventId); |
| 651 | } |
| 652 | }, true); |
| 653 | }, |
| 654 | |
| 655 | setupURLClickEvents: function () { |
| 656 | |
| 657 | // Non-default binding used to avoid situations when some code in external js |
| 658 | // stopping events propagation, eg. returns false, and our handler will never called |
| 659 | $('a[data-pys-event-id]').onFirst('click', function (evt) { |
| 660 | |
| 661 | $(this).attr('data-pys-event-id').split(',').forEach(function (eventId) { |
| 662 | |
| 663 | eventId = parseInt(eventId); |
| 664 | |
| 665 | if (isNaN(eventId) === false) { |
| 666 | Utils.fireTriggerEvent(eventId); |
| 667 | } |
| 668 | |
| 669 | }); |
| 670 | |
| 671 | }); |
| 672 | |
| 673 | |
| 674 | }, |
| 675 | |
| 676 | setupScrollPosEvents: function (eventId, triggers) { |
| 677 | |
| 678 | var scrollPosThresholds = {}, |
| 679 | docHeight = $(document).height() - $(window).height(); |
| 680 | |
| 681 | // convert % to absolute positions |
| 682 | $.each(triggers, function (index, scrollPos) { |
| 683 | |
| 684 | // convert % to pixels |
| 685 | scrollPos = docHeight * scrollPos / 100; |
| 686 | scrollPos = Math.round(scrollPos); |
| 687 | |
| 688 | scrollPosThresholds[scrollPos] = eventId; |
| 689 | |
| 690 | }); |
| 691 | |
| 692 | $(document).on("scroll",function () { |
| 693 | |
| 694 | var scrollPos = $(window).scrollTop(); |
| 695 | |
| 696 | $.each(scrollPosThresholds, function (threshold, eventId) { |
| 697 | |
| 698 | // position has not reached yes |
| 699 | if (scrollPos <= threshold) { |
| 700 | return true; |
| 701 | } |
| 702 | |
| 703 | // fire event only once |
| 704 | if (eventId === null) { |
| 705 | return true; |
| 706 | } else { |
| 707 | scrollPosThresholds[threshold] = null; |
| 708 | } |
| 709 | |
| 710 | Utils.fireTriggerEvent(eventId); |
| 711 | |
| 712 | }); |
| 713 | |
| 714 | }); |
| 715 | |
| 716 | |
| 717 | }, |
| 718 | setupCommentEvents : function (eventId,triggers) { |
| 719 | $('form.comment-form').on("submit",function () { |
| 720 | Utils.fireTriggerEvent(eventId); |
| 721 | }); |
| 722 | }, |
| 723 | |
| 724 | /** |
| 725 | * Events |
| 726 | */ |
| 727 | |
| 728 | fireTriggerEvent: function (eventId) { |
| 729 | |
| 730 | if (!options.triggerEvents.hasOwnProperty(eventId)) { |
| 731 | return; |
| 732 | } |
| 733 | |
| 734 | var event = {}; |
| 735 | var events = options.triggerEvents[eventId]; |
| 736 | |
| 737 | if (events.hasOwnProperty('facebook')) { |
| 738 | event = events.facebook; |
| 739 | Facebook.fireEvent(event.name, event); |
| 740 | } |
| 741 | |
| 742 | if (events.hasOwnProperty('ga')) { |
| 743 | event = events.ga; |
| 744 | Analytics.fireEvent(event.name, event); |
| 745 | } |
| 746 | |
| 747 | if (events.hasOwnProperty('pinterest')) { |
| 748 | event = events.pinterest; |
| 749 | Pinterest.fireEvent(event.name, event); |
| 750 | } |
| 751 | |
| 752 | if (events.hasOwnProperty('bing')) { |
| 753 | event = events.bing; |
| 754 | Bing.fireEvent(event.name, event); |
| 755 | } |
| 756 | }, |
| 757 | |
| 758 | fireStaticEvents: function (pixel) { |
| 759 | |
| 760 | if (options.staticEvents.hasOwnProperty(pixel)) { |
| 761 | |
| 762 | $.each(options.staticEvents[pixel], function (eventName, events) { |
| 763 | $.each(events, function (index, eventData) { |
| 764 | |
| 765 | eventData.fired = eventData.fired || false; |
| 766 | |
| 767 | if (!eventData.fired) { |
| 768 | |
| 769 | var fired = false; |
| 770 | |
| 771 | // fire event |
| 772 | if ('facebook' === pixel) { |
| 773 | fired = Facebook.fireEvent(eventData.name, eventData); |
| 774 | } else if ('ga' === pixel) { |
| 775 | fired = Analytics.fireEvent(eventData.name, eventData); |
| 776 | } else if ('pinterest' === pixel) { |
| 777 | fired = Pinterest.fireEvent(eventData.name, eventData); |
| 778 | } else if ('bing' === pixel) { |
| 779 | fired = Bing.fireEvent(eventData.name, eventData); |
| 780 | } |
| 781 | |
| 782 | // prevent event double event firing |
| 783 | eventData.fired = fired; |
| 784 | |
| 785 | } |
| 786 | |
| 787 | }); |
| 788 | }); |
| 789 | |
| 790 | } |
| 791 | |
| 792 | }, |
| 793 | |
| 794 | /** |
| 795 | * Load tag's JS |
| 796 | * |
| 797 | * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/ |
| 798 | * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets |
| 799 | */ |
| 800 | loadGoogleTag: function (id) { |
| 801 | |
| 802 | if (!gtag_loaded) { |
| 803 | |
| 804 | (function (window, document, src) { |
| 805 | var a = document.createElement('script'), |
| 806 | m = document.getElementsByTagName('script')[0]; |
| 807 | a.async = 1; |
| 808 | a.src = src; |
| 809 | m.parentNode.insertBefore(a, m); |
| 810 | })(window, document, '//www.googletagmanager.com/gtag/js?id=' + id); |
| 811 | |
| 812 | window.dataLayer = window.dataLayer || []; |
| 813 | window.gtag = window.gtag || function gtag() { |
| 814 | dataLayer.push(arguments); |
| 815 | }; |
| 816 | |
| 817 | gtag('js', new Date()); |
| 818 | |
| 819 | gtag_loaded = true; |
| 820 | |
| 821 | } |
| 822 | |
| 823 | }, |
| 824 | |
| 825 | /** |
| 826 | * GDPR |
| 827 | */ |
| 828 | |
| 829 | loadPixels: function () { |
| 830 | |
| 831 | if (options.gdpr.ajax_enabled && !options.gdpr.consent_magic_integration_enabled) { |
| 832 | |
| 833 | // retrieves actual PYS GDPR filters values which allow to avoid cache issues |
| 834 | $.get({ |
| 835 | url: options.ajaxUrl, |
| 836 | dataType: 'json', |
| 837 | data: { |
| 838 | action: 'pys_get_gdpr_filters_values' |
| 839 | }, |
| 840 | success: function (res) { |
| 841 | |
| 842 | if (res.success) { |
| 843 | |
| 844 | options.gdpr.all_disabled_by_api = res.data.all_disabled_by_api; |
| 845 | options.gdpr.facebook_disabled_by_api = res.data.facebook_disabled_by_api; |
| 846 | options.gdpr.analytics_disabled_by_api = res.data.analytics_disabled_by_api; |
| 847 | options.gdpr.google_ads_disabled_by_api = res.data.google_ads_disabled_by_api; |
| 848 | options.gdpr.pinterest_disabled_by_api = res.data.pinterest_disabled_by_api; |
| 849 | options.gdpr.bing_disabled_by_api = res.data.bing_disabled_by_api; |
| 850 | |
| 851 | options.cookie.externalID_disabled_by_api = res.data.externalID_disabled_by_api; |
| 852 | options.cookie.disabled_all_cookie = res.data.disabled_all_cookie; |
| 853 | options.cookie.disabled_advanced_form_data_cookie = res.data.disabled_advanced_form_data_cookie; |
| 854 | options.cookie.disabled_landing_page_cookie = res.data.disabled_landing_page_cookie; |
| 855 | options.cookie.disabled_first_visit_cookie = res.data.disabled_first_visit_cookie; |
| 856 | options.cookie.disabled_trafficsource_cookie = res.data.disabled_trafficsource_cookie; |
| 857 | options.cookie.disabled_utmTerms_cookie = res.data.disabled_utmTerms_cookie; |
| 858 | options.cookie.disabled_utmId_cookie = res.data.disabled_utmId_cookie; |
| 859 | } |
| 860 | |
| 861 | loadPixels(); |
| 862 | |
| 863 | } |
| 864 | }); |
| 865 | |
| 866 | } else { |
| 867 | loadPixels(); |
| 868 | } |
| 869 | |
| 870 | }, |
| 871 | |
| 872 | consentGiven: function (pixel) { |
| 873 | |
| 874 | /** |
| 875 | * ConsentMagic |
| 876 | */ |
| 877 | if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined" ) { |
| 878 | |
| 879 | var test_prefix = CS_Data.test_prefix; |
| 880 | if ((typeof CS_Data.cs_google_analytics_consent_mode !== "undefined" && CS_Data.cs_google_analytics_consent_mode == 1) && pixel == 'analytics') { |
| 881 | return true; |
| 882 | } |
| 883 | if ((typeof CS_Data.cs_google_ads_consent_mode !== "undefined" && CS_Data.cs_google_ads_consent_mode == 1) && pixel == 'google_ads') { |
| 884 | return true; |
| 885 | } |
| 886 | |
| 887 | if ( CS_Data.cs_cache_enabled == 1 ) { |
| 888 | var substring = "cs_enabled_cookie_term"; |
| 889 | var theCookies = document.cookie.split(';'); |
| 890 | |
| 891 | for (var i = 1 ; i <= theCookies.length; i++) { |
| 892 | if ( theCookies[ i - 1 ].indexOf( substring ) !== -1 ) { |
| 893 | var categoryCookie = theCookies[ i - 1 ].replace( 'cs_enabled_cookie_term' + test_prefix + '_', '' ); |
| 894 | categoryCookie = Number( categoryCookie.replace( /\D+/g, "" ) ); |
| 895 | var cs_cookie_val = Cookies.get( 'cs_enabled_cookie_term' + test_prefix + '_' + categoryCookie ); |
| 896 | |
| 897 | if ( categoryCookie === CS_Data.cs_script_cat.facebook && pixel == 'facebook' ) { |
| 898 | if ( cs_cookie_val == 'yes' ) { |
| 899 | return true; |
| 900 | } else { |
| 901 | return false; |
| 902 | } |
| 903 | } else if ( categoryCookie === CS_Data.cs_script_cat.bing && pixel == 'bing' ) { |
| 904 | if ( cs_cookie_val == 'yes' ) { |
| 905 | return true; |
| 906 | } else { |
| 907 | return false; |
| 908 | } |
| 909 | } else if ( categoryCookie === CS_Data.cs_script_cat.analytics && pixel == 'analytics' ) { |
| 910 | if ( cs_cookie_val == 'yes' ) { |
| 911 | return true; |
| 912 | } else { |
| 913 | return false; |
| 914 | } |
| 915 | } else if ( categoryCookie === CS_Data.cs_script_cat.gads && pixel == 'google_ads' ) { |
| 916 | if ( cs_cookie_val == 'yes' ) { |
| 917 | return true; |
| 918 | } else { |
| 919 | return false; |
| 920 | } |
| 921 | } else if ( categoryCookie === CS_Data.cs_script_cat.pinterest && pixel == 'pinterest' ) { |
| 922 | if ( cs_cookie_val == 'yes' ) { |
| 923 | return true; |
| 924 | } else { |
| 925 | return false; |
| 926 | } |
| 927 | } else if ( categoryCookie === CS_Data.cs_script_cat.tiktok && pixel == 'tiktok' ) { |
| 928 | if ( cs_cookie_val == 'yes' ) { |
| 929 | return true; |
| 930 | } else { |
| 931 | return false; |
| 932 | } |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | } else { |
| 937 | var cs_cookie = Cookies.get('cs_viewed_cookie_policy'+test_prefix); |
| 938 | if (typeof cs_cookie === 'undefined' || cs_cookie === 'yes') { |
| 939 | return true; |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | return false; |
| 944 | |
| 945 | } |
| 946 | |
| 947 | /** |
| 948 | * Real Cookie Banner |
| 949 | */ |
| 950 | if(options.gdpr.real_cookie_banner_integration_enabled) { |
| 951 | var consentApi = window.consentApi; |
| 952 | if (consentApi) { |
| 953 | switch (pixel) { |
| 954 | case "analytics": |
| 955 | return consentApi.consentSync("http", "_ga", "*").cookieOptIn; |
| 956 | case "facebook": |
| 957 | return consentApi.consentSync("http", "_fbp", "*").cookieOptIn; |
| 958 | case "pinterest": |
| 959 | return consentApi.consentSync("http", "_pinterest_sess", ".pinterest.com").cookieOptIn; |
| 960 | default: |
| 961 | return true; |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * Cookiebot |
| 968 | */ |
| 969 | if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { |
| 970 | |
| 971 | var cookiebot_consent_category = options.gdpr['cookiebot_' + pixel + '_consent_category']; |
| 972 | |
| 973 | if (options.gdpr[pixel + '_prior_consent_enabled']) { |
| 974 | if (Cookiebot.consented === false || Cookiebot.consent[cookiebot_consent_category]) { |
| 975 | return true; |
| 976 | } |
| 977 | } else { |
| 978 | if (Cookiebot.consent[cookiebot_consent_category]) { |
| 979 | return true; |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | return false; |
| 984 | |
| 985 | } |
| 986 | |
| 987 | /** |
| 988 | * Cookie Notice |
| 989 | */ |
| 990 | if (options.gdpr.cookie_notice_integration_enabled && typeof cnArgs !== 'undefined') { |
| 991 | |
| 992 | var cn_cookie = Cookies.get(cnArgs.cookieName); |
| 993 | |
| 994 | if (options.gdpr[pixel + '_prior_consent_enabled']) { |
| 995 | if (typeof cn_cookie === 'undefined' || cn_cookie === 'true') { |
| 996 | return true; |
| 997 | } |
| 998 | } else { |
| 999 | if (cn_cookie === 'true') { |
| 1000 | return true; |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | return false; |
| 1005 | |
| 1006 | } |
| 1007 | |
| 1008 | /** |
| 1009 | * Cookie Law Info |
| 1010 | */ |
| 1011 | if (options.gdpr.cookie_law_info_integration_enabled) { |
| 1012 | |
| 1013 | var cli_cookie = Cookies.get('viewed_cookie_policy'); |
| 1014 | |
| 1015 | if (options.gdpr[pixel + '_prior_consent_enabled']) { |
| 1016 | if (typeof cli_cookie === 'undefined' || cli_cookie === 'yes') { |
| 1017 | return true; |
| 1018 | } |
| 1019 | } else { |
| 1020 | if (cli_cookie === 'yes') { |
| 1021 | return true; |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | return false; |
| 1026 | |
| 1027 | } |
| 1028 | |
| 1029 | return true; |
| 1030 | |
| 1031 | }, |
| 1032 | |
| 1033 | setupGdprCallbacks: function () { |
| 1034 | /** |
| 1035 | * ConsentMagic |
| 1036 | */ |
| 1037 | if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined") { |
| 1038 | var test_prefix = CS_Data.test_prefix, |
| 1039 | cs_refresh_after_consent = false, |
| 1040 | substring = "cs_enabled_cookie_term"; |
| 1041 | |
| 1042 | if (CS_Data.cs_refresh_after_consent == 1) { |
| 1043 | cs_refresh_after_consent = CS_Data.cs_refresh_after_consent; |
| 1044 | } |
| 1045 | |
| 1046 | if (!cs_refresh_after_consent) { |
| 1047 | var theCookies = document.cookie.split(';'); |
| 1048 | for (var i = 1 ; i <= theCookies.length; i++) { |
| 1049 | if (theCookies[i-1].indexOf(substring) !== -1) { |
| 1050 | var categoryCookie = theCookies[i-1].replace('cs_enabled_cookie_term'+test_prefix+'_',''); |
| 1051 | categoryCookie = Number(categoryCookie.replace(/\D+/g,"")); |
| 1052 | var cs_cookie_val = Cookies.get('cs_enabled_cookie_term'+test_prefix+'_'+categoryCookie); |
| 1053 | if(cs_cookie_val == 'yes') { |
| 1054 | if (categoryCookie === CS_Data.cs_script_cat.facebook) { |
| 1055 | Facebook.loadPixel(); |
| 1056 | } |
| 1057 | |
| 1058 | if (categoryCookie === CS_Data.cs_script_cat.bing) { |
| 1059 | Bing.loadPixel(); |
| 1060 | } |
| 1061 | |
| 1062 | if (categoryCookie === CS_Data.cs_script_cat.analytics || (typeof CS_Data.cs_google_analytics_consent_mode !== "undefined" && CS_Data.cs_google_analytics_consent_mode == 1)) { |
| 1063 | |
| 1064 | Analytics.loadPixel(); |
| 1065 | } |
| 1066 | |
| 1067 | if (categoryCookie === CS_Data.cs_script_cat.pinterest) { |
| 1068 | Pinterest.loadPixel(); |
| 1069 | } |
| 1070 | } else { |
| 1071 | if (categoryCookie === CS_Data.cs_script_cat.facebook) { |
| 1072 | Facebook.disable(); |
| 1073 | } |
| 1074 | |
| 1075 | if (categoryCookie === CS_Data.cs_script_cat.bing) { |
| 1076 | Bing.disable(); |
| 1077 | } |
| 1078 | if (categoryCookie === CS_Data.cs_script_cat.analytics && (typeof CS_Data.cs_google_analytics_consent_mode == "undefined" || CS_Data.cs_google_analytics_consent_mode == 0)) { |
| 1079 | Analytics.disable(); |
| 1080 | } |
| 1081 | |
| 1082 | if (categoryCookie === CS_Data.cs_script_cat.pinterest) { |
| 1083 | Pinterest.disable(); |
| 1084 | } |
| 1085 | } |
| 1086 | if (Cookies.get('cs_enabled_advanced_matching') == 'yes') { |
| 1087 | Facebook.loadPixel(); |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | $(document).on('click','.cs_action_btn',function(e) { |
| 1093 | e.preventDefault(); |
| 1094 | var elm = $(this), |
| 1095 | button_action = elm.attr('data-cs_action'); |
| 1096 | |
| 1097 | if(button_action === 'allow_all') { |
| 1098 | Facebook.loadPixel(); |
| 1099 | Bing.loadPixel(); |
| 1100 | Analytics.loadPixel(); |
| 1101 | Pinterest.loadPixel(); |
| 1102 | } else if(button_action === 'disable_all') { |
| 1103 | Facebook.disable(); |
| 1104 | Bing.disable(); |
| 1105 | if(CS_Data.cs_google_analytics_consent_mode == 0 || typeof CS_Data.cs_google_analytics_consent_mode == "undefined") |
| 1106 | { |
| 1107 | Analytics.disable(); |
| 1108 | } |
| 1109 | Pinterest.disable(); |
| 1110 | } |
| 1111 | }); |
| 1112 | } |
| 1113 | } |
| 1114 | /** |
| 1115 | * Real Cookie Banner |
| 1116 | */ |
| 1117 | if(options.gdpr.real_cookie_banner_integration_enabled) { |
| 1118 | var consentApi = window.consentApi; |
| 1119 | if (consentApi) { |
| 1120 | consentApi.consent("http", "_ga", "*") |
| 1121 | .then(Analytics.loadPixel.bind(Analytics), Analytics.disable.bind(Analytics)); |
| 1122 | consentApi.consent("http", "_fbp", "*") |
| 1123 | .then(Facebook.loadPixel.bind(Facebook), Facebook.disable.bind(Facebook)); |
| 1124 | consentApi.consent("http", "_pinterest_sess", ".pinterest.com") |
| 1125 | .then(Pinterest.loadPixel.bind(Pinterest), Pinterest.disable.bind(Pinterest)); |
| 1126 | consentApi.consent("http", "_uetsid", "*") |
| 1127 | .then(Bing.loadPixel.bind(Bing), Bing.disable.bind(Bing)); |
| 1128 | } |
| 1129 | } |
| 1130 | /** |
| 1131 | * Cookiebot |
| 1132 | */ |
| 1133 | if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { |
| 1134 | |
| 1135 | window.addEventListener("CookiebotOnConsentReady", function() { |
| 1136 | if (Cookiebot.consent.marketing) { |
| 1137 | Facebook.loadPixel(); |
| 1138 | Bing.loadPixel(); |
| 1139 | Pinterest.loadPixel(); |
| 1140 | |
| 1141 | } |
| 1142 | if (Cookiebot.consent.statistics) { |
| 1143 | Analytics.loadPixel(); |
| 1144 | } |
| 1145 | if (!Cookiebot.consent.marketing) { |
| 1146 | Facebook.disable(); |
| 1147 | Pinterest.disable(); |
| 1148 | Bing.disable() |
| 1149 | } |
| 1150 | if (!Cookiebot.consent.statistics) { |
| 1151 | Analytics.disable(); |
| 1152 | } |
| 1153 | }); |
| 1154 | |
| 1155 | } |
| 1156 | |
| 1157 | /** |
| 1158 | * Cookie Notice |
| 1159 | */ |
| 1160 | if (options.gdpr.cookie_notice_integration_enabled) { |
| 1161 | |
| 1162 | $(document).onFirst('click', '.cn-set-cookie', function () { |
| 1163 | |
| 1164 | if ($(this).data('cookie-set') === 'accept') { |
| 1165 | Facebook.loadPixel(); |
| 1166 | Analytics.loadPixel(); |
| 1167 | Pinterest.loadPixel(); |
| 1168 | Bing.loadPixel(); |
| 1169 | } else { |
| 1170 | Facebook.disable(); |
| 1171 | Analytics.disable(); |
| 1172 | Pinterest.disable(); |
| 1173 | Bing.disable(); |
| 1174 | } |
| 1175 | |
| 1176 | }); |
| 1177 | |
| 1178 | $(document).onFirst('click', '.cn-revoke-cookie', function () { |
| 1179 | Facebook.disable(); |
| 1180 | Analytics.disable(); |
| 1181 | Pinterest.disable(); |
| 1182 | Bing.disable(); |
| 1183 | }); |
| 1184 | |
| 1185 | } |
| 1186 | |
| 1187 | /** |
| 1188 | * Cookie Law Info |
| 1189 | */ |
| 1190 | if (options.gdpr.cookie_law_info_integration_enabled) { |
| 1191 | |
| 1192 | $(document).onFirst('click', '#cookie_action_close_header', function () { |
| 1193 | Facebook.loadPixel(); |
| 1194 | Analytics.loadPixel(); |
| 1195 | Pinterest.loadPixel(); |
| 1196 | Bing.loadPixel(); |
| 1197 | }); |
| 1198 | |
| 1199 | $(document).onFirst('click', '#cookie_action_close_header_reject', function () { |
| 1200 | Facebook.disable(); |
| 1201 | Analytics.disable(); |
| 1202 | Pinterest.disable(); |
| 1203 | Bing.disable(); |
| 1204 | }); |
| 1205 | |
| 1206 | } |
| 1207 | |
| 1208 | }, |
| 1209 | |
| 1210 | /** |
| 1211 | * DOWNLOAD DOCS |
| 1212 | */ |
| 1213 | |
| 1214 | getLinkExtension: function (link) { |
| 1215 | |
| 1216 | // Remove anchor, query string and everything before last slash |
| 1217 | link = link.substring(0, (link.indexOf("#") === -1) ? link.length : link.indexOf("#")); |
| 1218 | link = link.substring(0, (link.indexOf("?") === -1) ? link.length : link.indexOf("?")); |
| 1219 | link = link.substring(link.lastIndexOf("/") + 1, link.length); |
| 1220 | |
| 1221 | // If there's a period left in the URL, then there's a extension |
| 1222 | if (link.length > 0 && link.indexOf('.') !== -1) { |
| 1223 | link = link.substring(link.indexOf(".") + 1); // Remove everything but what's after the first period |
| 1224 | return link; |
| 1225 | } else { |
| 1226 | return ""; |
| 1227 | } |
| 1228 | }, |
| 1229 | |
| 1230 | getLinkFilename: function (link) { |
| 1231 | |
| 1232 | // Remove anchor, query string and everything before last slash |
| 1233 | link = link.substring(0, (link.indexOf("#") === -1) ? link.length : link.indexOf("#")); |
| 1234 | link = link.substring(0, (link.indexOf("?") === -1) ? link.length : link.indexOf("?")); |
| 1235 | link = link.substring(link.lastIndexOf("/") + 1, link.length); |
| 1236 | |
| 1237 | // If there's a period left in the URL, then there's a extension |
| 1238 | if (link.length > 0 && link.indexOf('.') !== -1) { |
| 1239 | return link; |
| 1240 | } else { |
| 1241 | return ""; |
| 1242 | } |
| 1243 | }, |
| 1244 | /** |
| 1245 | * Enrich |
| 1246 | */ |
| 1247 | isCheckoutPage: function () { |
| 1248 | return $('body').hasClass('woocommerce-checkout') || document.querySelector('.woocommerce-checkout') || |
| 1249 | $('body').hasClass('edd-checkout'); |
| 1250 | }, |
| 1251 | addCheckoutFields : function() { |
| 1252 | var utm = ""; |
| 1253 | var utms = getUTMs() |
| 1254 | |
| 1255 | $.each(utmTerms, function (index, name) { |
| 1256 | if(index > 0) { |
| 1257 | utm+="|"; |
| 1258 | } |
| 1259 | utm+=name+":"+utms[name]; |
| 1260 | }); |
| 1261 | var utmIdList = ""; |
| 1262 | var utmsIds = getUTMId() |
| 1263 | $.each(utmId, function (index, name) { |
| 1264 | if(index > 0) { |
| 1265 | utmIdList+="|"; |
| 1266 | } |
| 1267 | utmIdList+=name+":"+utmsIds[name]; |
| 1268 | }); |
| 1269 | var utmIdListLast = ""; |
| 1270 | var utmsIdsLast = getUTMId(true) |
| 1271 | $.each(utmId, function (index, name) { |
| 1272 | if(index > 0) { |
| 1273 | utmIdListLast+="|"; |
| 1274 | } |
| 1275 | utmIdListLast+=name+":"+utmsIdsLast[name]; |
| 1276 | }); |
| 1277 | |
| 1278 | |
| 1279 | var utmLast = ""; |
| 1280 | var utmsLast = getUTMs(true) |
| 1281 | $.each(utmTerms, function (index, name) { |
| 1282 | if(index > 0) { |
| 1283 | utmLast+="|"; |
| 1284 | } |
| 1285 | utmLast+=name+":"+utmsLast[name]; |
| 1286 | }); |
| 1287 | |
| 1288 | var dateTime = getDateTime(); |
| 1289 | var landing = Cookies.get('pys_landing_page'); |
| 1290 | var lastLanding = Cookies.get('last_pys_landing_page'); |
| 1291 | var trafic = Cookies.get('pysTrafficSource'); |
| 1292 | var lastTrafic = Cookies.get('last_pysTrafficSource'); |
| 1293 | |
| 1294 | var $form = null; |
| 1295 | if($('body').hasClass('woocommerce-checkout')) { |
| 1296 | $form = $("form.woocommerce-checkout"); |
| 1297 | } else { |
| 1298 | $form = $("#edd_purchase_form"); |
| 1299 | } |
| 1300 | var inputs = {'pys_utm':utm, |
| 1301 | 'pys_utm_id':utmIdList, |
| 1302 | 'pys_browser_time':dateTime.join("|"), |
| 1303 | 'pys_landing':landing, |
| 1304 | 'pys_source':trafic, |
| 1305 | 'pys_order_type': $(".wcf-optin-form").length > 0 ? "wcf-optin" : "normal", |
| 1306 | |
| 1307 | 'last_pys_landing':lastLanding, |
| 1308 | 'last_pys_source':lastTrafic, |
| 1309 | 'last_pys_utm':utmLast, |
| 1310 | 'last_pys_utm_id':utmIdListLast, |
| 1311 | } |
| 1312 | |
| 1313 | Object.keys(inputs).forEach(function(key,index) { |
| 1314 | $form.append("<input type='hidden' name='"+key+"' value='"+inputs[key]+"' /> "); |
| 1315 | }); |
| 1316 | |
| 1317 | |
| 1318 | }, |
| 1319 | getAdvancedFormData: function () { |
| 1320 | let dataStr = Cookies.get("pys_advanced_form_data"); |
| 1321 | if(dataStr === undefined) { |
| 1322 | return {'first_name':"",'last_name':"",'email':"",'phone':""}; |
| 1323 | } else { |
| 1324 | return JSON.parse(dataStr); |
| 1325 | } |
| 1326 | } |
| 1327 | }; |
| 1328 | |
| 1329 | }(options); |
| 1330 | |
| 1331 | var Facebook = function (options) { |
| 1332 | |
| 1333 | |
| 1334 | var defaultEventTypes = [ |
| 1335 | 'PageView', |
| 1336 | 'ViewContent', |
| 1337 | 'Search', |
| 1338 | 'AddToCart', |
| 1339 | 'AddToWishlist', |
| 1340 | 'InitiateCheckout', |
| 1341 | 'AddPaymentInfo', |
| 1342 | 'Purchase', |
| 1343 | 'Lead', |
| 1344 | |
| 1345 | 'Subscribe', |
| 1346 | 'CustomizeProduct', |
| 1347 | 'FindLocation', |
| 1348 | 'StartTrial', |
| 1349 | 'SubmitApplication', |
| 1350 | 'Schedule', |
| 1351 | 'Contact', |
| 1352 | 'Donate' |
| 1353 | ]; |
| 1354 | |
| 1355 | var initialized = false; |
| 1356 | |
| 1357 | // fire server side event gdpr plugin installed |
| 1358 | var isApiDisabled = options.gdpr.all_disabled_by_api || |
| 1359 | options.gdpr.facebook_disabled_by_api || |
| 1360 | options.gdpr.cookiebot_integration_enabled || |
| 1361 | options.gdpr.consent_magic_integration_enabled || |
| 1362 | options.gdpr.cookie_notice_integration_enabled || |
| 1363 | options.gdpr.cookie_law_info_integration_enabled; |
| 1364 | |
| 1365 | /** |
| 1366 | * |
| 1367 | * @param allData |
| 1368 | * @param params |
| 1369 | * @returns {string | null} |
| 1370 | */ |
| 1371 | function sendFbServerEvent(allData,name,params) { |
| 1372 | let eventId = null; |
| 1373 | if(options.facebook.serverApiEnabled) { |
| 1374 | |
| 1375 | if(allData.e_id === "woo_remove_from_cart" || allData.e_id === "woo_add_to_cart_on_button_click") {// server event will sended from hook |
| 1376 | let isAddToCartFromJs = options.woo.hasOwnProperty("addToCartCatchMethod") |
| 1377 | && options.woo.addToCartCatchMethod === "add_cart_js"; |
| 1378 | |
| 1379 | if(isAddToCartFromJs || allData.e_id !== "woo_add_to_cart_on_button_click") { |
| 1380 | Facebook.updateEventId(allData.name); |
| 1381 | allData.eventID = Facebook.getEventId(allData.name); |
| 1382 | } else { |
| 1383 | // not update eventID for woo_add_to_cart_on_button_click, |
| 1384 | // web event created by ajax from server |
| 1385 | } |
| 1386 | } else { |
| 1387 | if( options.ajaxForServerEvent |
| 1388 | || isApiDisabled |
| 1389 | || allData.delay > 0 |
| 1390 | || allData.type !== "static") |
| 1391 | { // send event from server if they was bloc by gdpr or need send with delay |
| 1392 | allData.eventID = pys_generate_token(36); |
| 1393 | var json = { |
| 1394 | action: 'pys_api_event', |
| 1395 | pixel: 'facebook', |
| 1396 | event: name, |
| 1397 | data:params, |
| 1398 | ids:options.facebook.pixelIds, |
| 1399 | eventID:allData.eventID, |
| 1400 | url:window.location.href, |
| 1401 | ajax_event:options.ajax_event |
| 1402 | }; |
| 1403 | if(allData.hasOwnProperty('woo_order')) { |
| 1404 | json['woo_order'] = allData.woo_order; |
| 1405 | } |
| 1406 | if(allData.hasOwnProperty('edd_order')) { |
| 1407 | json['edd_order'] = allData.edd_order; |
| 1408 | } |
| 1409 | |
| 1410 | if(name == 'PageView') { |
| 1411 | let expires = parseInt(options.cookie_duration); |
| 1412 | var currentTimeInSeconds=Date.now(); |
| 1413 | var randomNum = Math.floor(1000000000 + Math.random() * 9000000000); |
| 1414 | timeoutDelay = 0; |
| 1415 | if(allData.delay > 0) |
| 1416 | { |
| 1417 | timeoutDelay = allData.delay; |
| 1418 | } |
| 1419 | if(!Cookies.get('_fbp')) |
| 1420 | { |
| 1421 | timeoutDelay = 100; |
| 1422 | } |
| 1423 | if(getUrlParameter('fbclid') && !Cookies.get('_fbc')) |
| 1424 | { |
| 1425 | timeoutDelay = 100; |
| 1426 | } |
| 1427 | setTimeout(function(){ |
| 1428 | if(!Cookies.get('_fbp')) |
| 1429 | { |
| 1430 | Cookies.set('_fbp','fb.1.'+currentTimeInSeconds+'.'+randomNum, { expires: expires }) |
| 1431 | } |
| 1432 | if(getUrlParameter('fbclid') && !Cookies.get('_fbc')) |
| 1433 | { |
| 1434 | Cookies.set('_fbc', 'fb.1.'+currentTimeInSeconds+'.'+getUrlParameter('fbclid'), { expires: expires }) |
| 1435 | } |
| 1436 | jQuery.ajax( { |
| 1437 | type: 'POST', |
| 1438 | url: options.ajaxUrl, |
| 1439 | data: json, |
| 1440 | headers: { |
| 1441 | 'Cache-Control': 'no-cache' |
| 1442 | }, |
| 1443 | success: function(){}, |
| 1444 | }); |
| 1445 | },timeoutDelay) |
| 1446 | } |
| 1447 | else |
| 1448 | { |
| 1449 | jQuery.ajax( { |
| 1450 | type: 'POST', |
| 1451 | url: options.ajaxUrl, |
| 1452 | data: json, |
| 1453 | headers: { |
| 1454 | 'Cache-Control': 'no-cache' |
| 1455 | }, |
| 1456 | success: function(){}, |
| 1457 | }); |
| 1458 | } |
| 1459 | } |
| 1460 | } |
| 1461 | eventId = allData.eventID |
| 1462 | } |
| 1463 | |
| 1464 | return eventId; |
| 1465 | } |
| 1466 | |
| 1467 | function fireEvent(name, allData) { |
| 1468 | |
| 1469 | if(typeof window.pys_event_data_filter === "function" && window.pys_disable_event_filter(name,'facebook')) { |
| 1470 | return; |
| 1471 | } |
| 1472 | |
| 1473 | var actionType = defaultEventTypes.includes(name) ? 'track' : 'trackCustom'; |
| 1474 | var data = allData.params; |
| 1475 | var params = {}; |
| 1476 | var arg = {}; |
| 1477 | Utils.copyProperties(data, params); |
| 1478 | |
| 1479 | let eventId = sendFbServerEvent(allData,name,params) |
| 1480 | |
| 1481 | |
| 1482 | if("hCR" === name) { |
| 1483 | return; |
| 1484 | } |
| 1485 | |
| 1486 | if (options.debug) { |
| 1487 | console.log('[Facebook] ' + name, params,"eventID",eventId); |
| 1488 | } |
| 1489 | |
| 1490 | if(eventId != null) { |
| 1491 | arg.eventID = eventId; |
| 1492 | } |
| 1493 | |
| 1494 | fbq(actionType, name, params,arg); |
| 1495 | } |
| 1496 | |
| 1497 | /** |
| 1498 | * Public API |
| 1499 | */ |
| 1500 | return { |
| 1501 | tag: function() { |
| 1502 | return "facebook"; |
| 1503 | }, |
| 1504 | isEnabled: function () { |
| 1505 | return options.hasOwnProperty('facebook'); |
| 1506 | }, |
| 1507 | |
| 1508 | disable: function () { |
| 1509 | initialized = false; |
| 1510 | }, |
| 1511 | advancedMatching: function () { |
| 1512 | if(options.facebook.advancedMatchingEnabled) { |
| 1513 | let advancedMatchingForm = Utils.getAdvancedFormData(); |
| 1514 | let advancedMatching = {}; |
| 1515 | if(Object.keys(options.facebook.advancedMatching).length > 0) { |
| 1516 | advancedMatching = options.facebook.advancedMatching; |
| 1517 | } |
| 1518 | |
| 1519 | if(!advancedMatching.hasOwnProperty("em") |
| 1520 | && advancedMatchingForm.hasOwnProperty("email") && advancedMatchingForm["email"].length > 0) { |
| 1521 | advancedMatching["em"] = advancedMatchingForm["email"]; |
| 1522 | } |
| 1523 | if(!advancedMatching.hasOwnProperty("ph") |
| 1524 | && advancedMatchingForm.hasOwnProperty("phone") && advancedMatchingForm["phone"].length > 0) { |
| 1525 | advancedMatching["ph"] = advancedMatchingForm["phone"]; |
| 1526 | } |
| 1527 | if(!advancedMatching.hasOwnProperty("fn") |
| 1528 | && advancedMatchingForm.hasOwnProperty("first_name") && advancedMatchingForm["first_name"].length > 0) { |
| 1529 | advancedMatching["fn"] = advancedMatchingForm["first_name"]; |
| 1530 | } |
| 1531 | if(!advancedMatching.hasOwnProperty("ln") |
| 1532 | && advancedMatchingForm.hasOwnProperty("last_name") && advancedMatchingForm["last_name"].length > 0) { |
| 1533 | advancedMatching["ln"] = advancedMatchingForm["last_name"]; |
| 1534 | } |
| 1535 | if(!advancedMatching.hasOwnProperty("external_id")){ |
| 1536 | if (Cookies.get('pbid')) { |
| 1537 | advancedMatching["external_id"] = Cookies.get('pbid'); |
| 1538 | } |
| 1539 | } |
| 1540 | if(Object.keys(advancedMatching).length > 0) { |
| 1541 | return advancedMatching; |
| 1542 | } |
| 1543 | } |
| 1544 | return false |
| 1545 | }, |
| 1546 | /** |
| 1547 | * Load pixel's JS |
| 1548 | */ |
| 1549 | loadPixel: function () { |
| 1550 | |
| 1551 | if (initialized || !this.isEnabled() || !Utils.consentGiven('facebook')) { |
| 1552 | return; |
| 1553 | } |
| 1554 | |
| 1555 | !function (f, b, e, v, n, t, s) { |
| 1556 | if (f.fbq) return; |
| 1557 | n = f.fbq = function () { |
| 1558 | n.callMethod ? |
| 1559 | n.callMethod.apply(n, arguments) : n.queue.push(arguments) |
| 1560 | }; |
| 1561 | if (!f._fbq) f._fbq = n; |
| 1562 | n.push = n; |
| 1563 | n.loaded = !0; |
| 1564 | n.version = '2.0'; |
| 1565 | n.agent = 'dvpixelyoursite'; |
| 1566 | n.queue = []; |
| 1567 | t = b.createElement(e); |
| 1568 | t.async = !0; |
| 1569 | t.src = v; |
| 1570 | s = b.getElementsByTagName(e)[0]; |
| 1571 | s.parentNode.insertBefore(t, s) |
| 1572 | }(window, |
| 1573 | document, 'script', 'https://connect.facebook.net/en_US/fbevents.js'); |
| 1574 | |
| 1575 | // initialize pixel |
| 1576 | options.facebook.pixelIds.forEach(function (pixelId) { |
| 1577 | if (options.facebook.removeMetadata) { |
| 1578 | fbq('set', 'autoConfig', false, pixelId); |
| 1579 | } |
| 1580 | let advancedMatching = Facebook.advancedMatching(); |
| 1581 | if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined") { |
| 1582 | if(!advancedMatching) { |
| 1583 | fbq('init', pixelId); |
| 1584 | } else { |
| 1585 | var cs_advanced_matching = Cookies.get('cs_enabled_advanced_matching'+test_prefix); |
| 1586 | if (jQuery('#cs_enabled_advanced_matching'+test_prefix).length > 0) { |
| 1587 | if (cs_advanced_matching == 'yes') { |
| 1588 | fbq('init', pixelId, advancedMatching); |
| 1589 | } else { |
| 1590 | fbq('init', pixelId); |
| 1591 | } |
| 1592 | } else { |
| 1593 | fbq('init', pixelId, advancedMatching); |
| 1594 | } |
| 1595 | } |
| 1596 | } else { |
| 1597 | if(!advancedMatching) { |
| 1598 | fbq('init', pixelId); |
| 1599 | } else { |
| 1600 | fbq('init', pixelId, advancedMatching); |
| 1601 | } |
| 1602 | } |
| 1603 | }); |
| 1604 | |
| 1605 | initialized = true; |
| 1606 | |
| 1607 | Utils.fireStaticEvents('facebook'); |
| 1608 | |
| 1609 | }, |
| 1610 | |
| 1611 | fireEvent: function (name, data) { |
| 1612 | |
| 1613 | if (!initialized || !this.isEnabled()) { |
| 1614 | return false; |
| 1615 | } |
| 1616 | |
| 1617 | data.delay = data.delay || 0; |
| 1618 | data.params = data.params || {}; |
| 1619 | |
| 1620 | if (data.delay === 0) { |
| 1621 | |
| 1622 | fireEvent(name, data); |
| 1623 | |
| 1624 | } else { |
| 1625 | |
| 1626 | setTimeout(function (name, params) { |
| 1627 | fireEvent(name, params); |
| 1628 | }, data.delay * 1000, name, data); |
| 1629 | |
| 1630 | } |
| 1631 | |
| 1632 | return true; |
| 1633 | |
| 1634 | }, |
| 1635 | |
| 1636 | onCommentEvent: function (event) { |
| 1637 | this.fireEvent(event.name, event); |
| 1638 | }, |
| 1639 | |
| 1640 | onDownloadEvent: function (event) { |
| 1641 | this.fireEvent(event.name, event); |
| 1642 | }, |
| 1643 | |
| 1644 | onFormEvent: function (event) { |
| 1645 | |
| 1646 | this.fireEvent(event.name, event); |
| 1647 | |
| 1648 | }, |
| 1649 | |
| 1650 | onWooAddToCartOnButtonEvent: function (product_id) { |
| 1651 | |
| 1652 | if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) |
| 1653 | return; |
| 1654 | var event = options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]; |
| 1655 | |
| 1656 | if (window.pysWooProductData.hasOwnProperty(product_id)) { |
| 1657 | if (window.pysWooProductData[product_id].hasOwnProperty('facebook')) { |
| 1658 | event = Utils.copyProperties(event, {}) |
| 1659 | Utils.copyProperties(window.pysWooProductData[product_id]['facebook'].params, event.params) |
| 1660 | this.fireEvent(event.name, event); |
| 1661 | } |
| 1662 | } |
| 1663 | }, |
| 1664 | |
| 1665 | onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, $form) { |
| 1666 | |
| 1667 | window.pysWooProductData = window.pysWooProductData || []; |
| 1668 | if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) |
| 1669 | return; |
| 1670 | var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); |
| 1671 | |
| 1672 | if (product_type === Utils.PRODUCT_VARIABLE && !options.facebook.wooVariableAsSimple) { |
| 1673 | product_id = parseInt($form.find('input[name="variation_id"]').val()); |
| 1674 | } |
| 1675 | |
| 1676 | if (window.pysWooProductData.hasOwnProperty(product_id)) { |
| 1677 | if (window.pysWooProductData[product_id].hasOwnProperty('facebook')) { |
| 1678 | |
| 1679 | |
| 1680 | Utils.copyProperties(window.pysWooProductData[product_id]['facebook'].params, event.params); |
| 1681 | |
| 1682 | var groupValue = 0; |
| 1683 | if(product_type === Utils.PRODUCT_GROUPED ) { |
| 1684 | $form.find(".woocommerce-grouped-product-list .qty").each(function(index){ |
| 1685 | var childId = $(this).attr('name').replaceAll("quantity[","").replaceAll("]",""); |
| 1686 | var quantity = parseInt($(this).val()); |
| 1687 | if(isNaN(quantity)) { |
| 1688 | quantity = 0; |
| 1689 | } |
| 1690 | var childItem = window.pysWooProductData[product_id]['facebook'].grouped[childId]; |
| 1691 | |
| 1692 | if(quantity == 0) { |
| 1693 | event.params.content_ids.forEach(function(el,index,array) { |
| 1694 | if(el == childItem.content_id) { |
| 1695 | array.splice(index, 1); |
| 1696 | } |
| 1697 | }); |
| 1698 | } |
| 1699 | |
| 1700 | if(event.params.hasOwnProperty('contents')) { |
| 1701 | event.params.contents.forEach(function(el,index,array) { |
| 1702 | if(el.id == childItem.content_id) { |
| 1703 | if(quantity > 0){ |
| 1704 | el.quantity = quantity; |
| 1705 | } else { |
| 1706 | array.splice(index, 1); |
| 1707 | } |
| 1708 | } |
| 1709 | }); |
| 1710 | } |
| 1711 | |
| 1712 | |
| 1713 | groupValue += childItem.price * quantity; |
| 1714 | }); |
| 1715 | if(groupValue == 0) return; // skip if no items selected |
| 1716 | } |
| 1717 | |
| 1718 | // maybe customize value option |
| 1719 | if (options.woo.addToCartOnButtonValueEnabled && options.woo.addToCartOnButtonValueOption !== 'global') { |
| 1720 | |
| 1721 | if(product_type === Utils.PRODUCT_GROUPED) { |
| 1722 | event.params.value = groupValue; |
| 1723 | } else if(product_type === Utils.PRODUCT_BUNDLE) { |
| 1724 | var data = $(".bundle_form .bundle_data").data("bundle_form_data"); |
| 1725 | var items_sum = getBundlePriceOnSingleProduct(data); |
| 1726 | event.params.value = (parseInt(data.base_price) + items_sum )* qty; |
| 1727 | } else { |
| 1728 | event.params.value = event.params.value * qty; |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | // only when non Facebook for WooCommerce logic used |
| 1733 | if (event.params.hasOwnProperty('contents') && product_type !== Utils.PRODUCT_GROUPED) { |
| 1734 | event.params.contents[0].quantity = qty; |
| 1735 | } |
| 1736 | |
| 1737 | this.fireEvent(event.name, event); |
| 1738 | |
| 1739 | } |
| 1740 | } |
| 1741 | }, |
| 1742 | |
| 1743 | onWooRemoveFromCartEvent: function (event) { |
| 1744 | this.fireEvent(event.name, event); |
| 1745 | }, |
| 1746 | |
| 1747 | onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { |
| 1748 | |
| 1749 | if(!options.dynamicEvents.edd_add_to_cart_on_button_click.hasOwnProperty(this.tag())) |
| 1750 | return; |
| 1751 | var event = Utils.clone(options.dynamicEvents.edd_add_to_cart_on_button_click[this.tag()]); |
| 1752 | |
| 1753 | if (window.pysEddProductData.hasOwnProperty(download_id)) { |
| 1754 | |
| 1755 | var index; |
| 1756 | |
| 1757 | if (price_index) { |
| 1758 | index = download_id + '_' + price_index; |
| 1759 | } else { |
| 1760 | index = download_id; |
| 1761 | } |
| 1762 | |
| 1763 | if (window.pysEddProductData[download_id].hasOwnProperty(index)) { |
| 1764 | if (window.pysEddProductData[download_id][index].hasOwnProperty('facebook')) { |
| 1765 | |
| 1766 | |
| 1767 | Utils.copyProperties(window.pysEddProductData[download_id][index]['facebook']["params"], event.params) |
| 1768 | |
| 1769 | // maybe customize value option |
| 1770 | if (options.edd.addToCartOnButtonValueEnabled && options.edd.addToCartOnButtonValueOption !== 'global') { |
| 1771 | event.params.value = event.params.value * qty; |
| 1772 | } |
| 1773 | |
| 1774 | // update contents qty param |
| 1775 | var contents = event.params.contents; |
| 1776 | contents[0].quantity = qty; |
| 1777 | event.params.contents = contents; |
| 1778 | |
| 1779 | this.fireEvent(event.name,event); |
| 1780 | |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | } |
| 1785 | |
| 1786 | }, |
| 1787 | |
| 1788 | onEddRemoveFromCartEvent: function (event) { |
| 1789 | this.fireEvent(event.name, event); |
| 1790 | }, |
| 1791 | onPageScroll: function (event) { |
| 1792 | this.fireEvent(event.name, event); |
| 1793 | }, |
| 1794 | onTime: function (event) { |
| 1795 | this.fireEvent(event.name, event); |
| 1796 | }, |
| 1797 | initEventIdCookies: function (key) { |
| 1798 | var ids = {}; |
| 1799 | ids[key] = pys_generate_token(36) |
| 1800 | Cookies.set('pys_fb_event_id', JSON.stringify(ids)); |
| 1801 | }, |
| 1802 | updateEventId:function(key) { |
| 1803 | var cooData = Cookies.get("pys_fb_event_id") |
| 1804 | if(cooData === undefined) { |
| 1805 | this.initEventIdCookies(key); |
| 1806 | } else { |
| 1807 | var data = JSON.parse(cooData); |
| 1808 | data[key] = pys_generate_token(36); |
| 1809 | Cookies.set('pys_fb_event_id', JSON.stringify(data) ); |
| 1810 | } |
| 1811 | }, |
| 1812 | |
| 1813 | getEventId:function (key) { |
| 1814 | var data = Cookies.get("pys_fb_event_id"); |
| 1815 | if(data === undefined) { |
| 1816 | this.initEventIdCookies(key); |
| 1817 | data = Cookies.get("pys_fb_event_id"); |
| 1818 | } |
| 1819 | return JSON.parse(data)[key]; |
| 1820 | }, |
| 1821 | }; |
| 1822 | |
| 1823 | }(options); |
| 1824 | |
| 1825 | var Analytics = function (options) { |
| 1826 | |
| 1827 | var initialized = false; |
| 1828 | |
| 1829 | /** |
| 1830 | * Fires event |
| 1831 | * |
| 1832 | * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data |
| 1833 | * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/events |
| 1834 | * @link: https://developers.google.com/gtagjs/reference/event |
| 1835 | * @link: https://developers.google.com/gtagjs/reference/parameter |
| 1836 | * |
| 1837 | * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets |
| 1838 | * |
| 1839 | * @param name |
| 1840 | * @param data |
| 1841 | */ |
| 1842 | function fireEvent(name, data) { |
| 1843 | |
| 1844 | if(typeof window.pys_event_data_filter === "function" && window.pys_disable_event_filter(name,'ga')) { |
| 1845 | return; |
| 1846 | } |
| 1847 | |
| 1848 | var eventParams = Utils.copyProperties(data, {}); |
| 1849 | |
| 1850 | var _fireEvent = function (tracking_id,name,params) { |
| 1851 | |
| 1852 | params['send_to'] = tracking_id; |
| 1853 | |
| 1854 | if (options.debug) { |
| 1855 | console.log('[Google Analytics #' + tracking_id + '] ' + name, params); |
| 1856 | } |
| 1857 | |
| 1858 | gtag('event', name, params); |
| 1859 | |
| 1860 | }; |
| 1861 | |
| 1862 | options.ga.trackingIds.forEach(function (tracking_id) { |
| 1863 | var copyParams = Utils.copyProperties(eventParams, {}); // copy params because mapParamsTov4 can modify it |
| 1864 | var params = mapParamsTov4(tracking_id,name,copyParams) |
| 1865 | _fireEvent(tracking_id,name,params); |
| 1866 | }); |
| 1867 | |
| 1868 | } |
| 1869 | function mapParamsTov4(tag,name,param) { |
| 1870 | //GA4 automatically collects a number of parameters for all events |
| 1871 | delete param.page_title; |
| 1872 | delete param.event_url; |
| 1873 | delete param.landing_page; |
| 1874 | // end |
| 1875 | if(isv4(tag)) { |
| 1876 | delete param.traffic_source; |
| 1877 | delete param.event_category; |
| 1878 | delete param.event_label; |
| 1879 | delete param.ecomm_prodid; |
| 1880 | delete param.ecomm_pagetype; |
| 1881 | delete param.ecomm_totalvalue; |
| 1882 | delete param.non_interaction; |
| 1883 | if(name === 'search') { |
| 1884 | param['search'] = param.search_term; |
| 1885 | delete param.search_term; |
| 1886 | delete param.non_interaction; |
| 1887 | delete param.dynx_itemid; |
| 1888 | delete param.dynx_pagetype; |
| 1889 | delete param.dynx_totalvalue; |
| 1890 | } |
| 1891 | } else { |
| 1892 | |
| 1893 | switch (name) { |
| 1894 | |
| 1895 | case 'Comment' : |
| 1896 | case 'login' : |
| 1897 | case 'sign_up' : |
| 1898 | case 'EmailClick' : |
| 1899 | case 'TelClick' : { |
| 1900 | let params = { |
| 1901 | event_category: "Key Actions", |
| 1902 | event_action: name, |
| 1903 | non_interaction: param.non_interaction, |
| 1904 | } |
| 1905 | return params; |
| 1906 | } |
| 1907 | case 'Form' : { |
| 1908 | let params = { |
| 1909 | event_category: "Key Actions", |
| 1910 | event_action: name, |
| 1911 | non_interaction: param.non_interaction, |
| 1912 | } |
| 1913 | var formClass = (typeof param.form_class != 'undefined') ? 'class: ' + param.form_class : ''; |
| 1914 | if(formClass != "") { |
| 1915 | params["event_label"] = formClass; |
| 1916 | } |
| 1917 | return params; |
| 1918 | } |
| 1919 | case 'Download' : { |
| 1920 | let params = { |
| 1921 | event_category: "Key Actions", |
| 1922 | event_action: name, |
| 1923 | event_label: param.download_name, |
| 1924 | non_interaction: param.non_interaction, |
| 1925 | } |
| 1926 | return params; |
| 1927 | } |
| 1928 | case 'TimeOnPage' : |
| 1929 | case 'PageScroll' : { |
| 1930 | let params = { |
| 1931 | event_category: "Key Actions", |
| 1932 | event_action: name, |
| 1933 | event_label: document.title, |
| 1934 | non_interaction: param.non_interaction, |
| 1935 | } |
| 1936 | return params; |
| 1937 | } |
| 1938 | case 'search' : { |
| 1939 | let params = { |
| 1940 | event_category: "Key Actions", |
| 1941 | event_action: name, |
| 1942 | event_label: param.search_term, |
| 1943 | non_interaction: param.non_interaction, |
| 1944 | } |
| 1945 | return params; |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | //delete standard params |
| 1950 | |
| 1951 | delete param.post_type; |
| 1952 | delete param.post_id; |
| 1953 | delete param.plugin; |
| 1954 | delete param.user_role; |
| 1955 | delete param.cartlows; |
| 1956 | delete param.cartflows_flow; |
| 1957 | delete param.cartflows_step; |
| 1958 | } |
| 1959 | return param; |
| 1960 | } |
| 1961 | |
| 1962 | function isv4(tag) { |
| 1963 | return tag.indexOf('G') === 0; |
| 1964 | } |
| 1965 | |
| 1966 | /** |
| 1967 | * Public API |
| 1968 | */ |
| 1969 | return { |
| 1970 | tag: function() { |
| 1971 | return "ga"; |
| 1972 | }, |
| 1973 | isEnabled: function () { |
| 1974 | return options.hasOwnProperty('ga'); |
| 1975 | }, |
| 1976 | |
| 1977 | disable: function () { |
| 1978 | initialized = false; |
| 1979 | }, |
| 1980 | |
| 1981 | loadPixel: function () { |
| 1982 | |
| 1983 | if (initialized || !this.isEnabled() || !Utils.consentGiven('analytics')) { |
| 1984 | return; |
| 1985 | } |
| 1986 | |
| 1987 | Utils.loadGoogleTag(options.ga.trackingIds[0]); |
| 1988 | |
| 1989 | var config = { |
| 1990 | 'link_attribution': options.ga.enhanceLinkAttr, |
| 1991 | 'anonymize_ip': options.ga.anonimizeIP |
| 1992 | }; |
| 1993 | |
| 1994 | // Cross-Domain tracking |
| 1995 | if (options.ga.crossDomainEnabled) { |
| 1996 | config.linker = { |
| 1997 | accept_incoming: options.ga.crossDomainAcceptIncoming, |
| 1998 | domains: options.ga.crossDomainDomains |
| 1999 | }; |
| 2000 | } |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | // configure tracking ids |
| 2005 | options.ga.trackingIds.forEach(function (trackingId,index) { |
| 2006 | var obj = options.ga.isDebugEnabled; |
| 2007 | var searchValue = "index_"+index; |
| 2008 | config.debug_mode = false; |
| 2009 | |
| 2010 | for (var key in obj) { |
| 2011 | if (obj.hasOwnProperty(key) && obj[key] === searchValue) { |
| 2012 | config.debug_mode = true; |
| 2013 | break; |
| 2014 | } |
| 2015 | } |
| 2016 | if(!config.debug_mode) |
| 2017 | { |
| 2018 | delete config.debug_mode; |
| 2019 | } |
| 2020 | if(isv4(trackingId)) { |
| 2021 | if(options.ga.disableAdvertisingFeatures) { |
| 2022 | config.allow_google_signals = false |
| 2023 | } |
| 2024 | if(options.ga.disableAdvertisingPersonalization) { |
| 2025 | config.allow_ad_personalization_signals = false |
| 2026 | } |
| 2027 | } |
| 2028 | if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { |
| 2029 | |
| 2030 | var cookiebot_consent_category = options.gdpr['cookiebot_analytics_consent_category']; |
| 2031 | if (options.gdpr['analytics_prior_consent_enabled']) { |
| 2032 | if (Cookiebot.consented === true && Cookiebot.consent[cookiebot_consent_category]) { |
| 2033 | gtag('config', trackingId, config); |
| 2034 | } |
| 2035 | } else { |
| 2036 | if (Cookiebot.consent[cookiebot_consent_category]) { |
| 2037 | gtag('config', trackingId, config); |
| 2038 | } |
| 2039 | } |
| 2040 | |
| 2041 | } |
| 2042 | else |
| 2043 | { |
| 2044 | gtag('config', trackingId, config); |
| 2045 | } |
| 2046 | }); |
| 2047 | |
| 2048 | initialized = true; |
| 2049 | |
| 2050 | Utils.fireStaticEvents('ga'); |
| 2051 | |
| 2052 | }, |
| 2053 | |
| 2054 | fireEvent: function (name, data) { |
| 2055 | |
| 2056 | if (!initialized || !this.isEnabled()) { |
| 2057 | return false; |
| 2058 | } |
| 2059 | |
| 2060 | data.delay = data.delay || 0; |
| 2061 | data.params = data.params || {}; |
| 2062 | |
| 2063 | if (data.delay === 0) { |
| 2064 | |
| 2065 | fireEvent(name, data.params); |
| 2066 | |
| 2067 | } else { |
| 2068 | |
| 2069 | setTimeout(function (name, params) { |
| 2070 | fireEvent(name, params); |
| 2071 | }, data.delay * 1000, name, data.params); |
| 2072 | |
| 2073 | } |
| 2074 | |
| 2075 | return true; |
| 2076 | |
| 2077 | }, |
| 2078 | |
| 2079 | onCommentEvent: function (event) { |
| 2080 | this.fireEvent(event.name, event); |
| 2081 | }, |
| 2082 | |
| 2083 | onDownloadEvent: function (event) { |
| 2084 | this.fireEvent(event.name, event); |
| 2085 | }, |
| 2086 | |
| 2087 | onFormEvent: function (event) { |
| 2088 | this.fireEvent(event.name, event); |
| 2089 | }, |
| 2090 | |
| 2091 | onWooAddToCartOnButtonEvent: function (product_id) { |
| 2092 | |
| 2093 | if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) |
| 2094 | return; |
| 2095 | var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); |
| 2096 | |
| 2097 | if (window.pysWooProductData.hasOwnProperty(product_id)) { |
| 2098 | if (window.pysWooProductData[product_id].hasOwnProperty('ga')) { |
| 2099 | Utils.copyProperties(window.pysWooProductData[product_id]['ga'].params, event.params) |
| 2100 | this.fireEvent(event.name, event); |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | |
| 2105 | }, |
| 2106 | |
| 2107 | onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, $form) { |
| 2108 | |
| 2109 | window.pysWooProductData = window.pysWooProductData || []; |
| 2110 | |
| 2111 | if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) |
| 2112 | return; |
| 2113 | var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); |
| 2114 | |
| 2115 | if (product_type === Utils.PRODUCT_VARIABLE && !options.ga.wooVariableAsSimple) { |
| 2116 | product_id = parseInt($form.find('input[name="variation_id"]').val()); |
| 2117 | } |
| 2118 | |
| 2119 | if (window.pysWooProductData.hasOwnProperty(product_id)) { |
| 2120 | if (window.pysWooProductData[product_id].hasOwnProperty('ga')) { |
| 2121 | |
| 2122 | Utils.copyProperties(window.pysWooProductData[product_id]['ga'].params, event.params); |
| 2123 | if(product_type === Utils.PRODUCT_GROUPED ) { |
| 2124 | var groupValue = 0; |
| 2125 | $form.find(".woocommerce-grouped-product-list .qty").each(function(index){ |
| 2126 | var childId = $(this).attr('name').replaceAll("quantity[","").replaceAll("]",""); |
| 2127 | var quantity = parseInt($(this).val()); |
| 2128 | if(isNaN(quantity)) { |
| 2129 | quantity = 0; |
| 2130 | } |
| 2131 | var childItem = window.pysWooProductData[product_id]['ga'].grouped[childId]; |
| 2132 | // update quantity |
| 2133 | event.params.items.forEach(function(el,index,array) { |
| 2134 | if(el.id == childItem.content_id) { |
| 2135 | if(quantity > 0){ |
| 2136 | el.quantity = quantity; |
| 2137 | } else { |
| 2138 | array.splice(index, 1); |
| 2139 | } |
| 2140 | } |
| 2141 | }); |
| 2142 | groupValue += childItem.price * quantity; |
| 2143 | }); |
| 2144 | if(options.woo.addToCartOnButtonValueEnabled && |
| 2145 | options.woo.addToCartOnButtonValueOption !== 'global' && |
| 2146 | event.params.hasOwnProperty('ecomm_totalvalue')) { |
| 2147 | event.params.ecomm_totalvalue = groupValue; |
| 2148 | } |
| 2149 | |
| 2150 | if(groupValue == 0) return; // skip if no items selected |
| 2151 | } else { |
| 2152 | // update items qty param |
| 2153 | event.params.items[0].quantity = qty; |
| 2154 | } |
| 2155 | |
| 2156 | // maybe customize value option |
| 2157 | if (options.woo.addToCartOnButtonValueEnabled && |
| 2158 | options.woo.addToCartOnButtonValueOption !== 'global' && |
| 2159 | product_type !== Utils.PRODUCT_GROUPED) |
| 2160 | { |
| 2161 | if(event.params.hasOwnProperty('ecomm_totalvalue')) { |
| 2162 | event.params.ecomm_totalvalue = event.params.items[0].price * qty; |
| 2163 | } |
| 2164 | |
| 2165 | } |
| 2166 | |
| 2167 | |
| 2168 | this.fireEvent(event.name, event); |
| 2169 | } |
| 2170 | } |
| 2171 | |
| 2172 | }, |
| 2173 | |
| 2174 | onWooRemoveFromCartEvent: function (event) { |
| 2175 | |
| 2176 | this.fireEvent(event.name, event); |
| 2177 | |
| 2178 | }, |
| 2179 | |
| 2180 | onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { |
| 2181 | |
| 2182 | if(!options.dynamicEvents.edd_add_to_cart_on_button_click.hasOwnProperty(this.tag())) |
| 2183 | return; |
| 2184 | var event = Utils.clone(options.dynamicEvents.edd_add_to_cart_on_button_click[this.tag()]); |
| 2185 | |
| 2186 | |
| 2187 | if (window.pysEddProductData.hasOwnProperty(download_id)) { |
| 2188 | |
| 2189 | var index; |
| 2190 | |
| 2191 | if (price_index) { |
| 2192 | index = download_id + '_' + price_index; |
| 2193 | } else { |
| 2194 | index = download_id; |
| 2195 | } |
| 2196 | |
| 2197 | if (window.pysEddProductData[download_id].hasOwnProperty(index)) { |
| 2198 | if (window.pysEddProductData[download_id][index].hasOwnProperty('ga')) { |
| 2199 | |
| 2200 | Utils.copyProperties(window.pysEddProductData[download_id][index]['ga'].params, event.params); |
| 2201 | |
| 2202 | // update items qty param |
| 2203 | event.params.items[0].quantity = qty; |
| 2204 | |
| 2205 | this.fireEvent(event.name,event); |
| 2206 | |
| 2207 | } |
| 2208 | } |
| 2209 | |
| 2210 | } |
| 2211 | |
| 2212 | }, |
| 2213 | |
| 2214 | onEddRemoveFromCartEvent: function (event) { |
| 2215 | this.fireEvent(event.name, event); |
| 2216 | }, |
| 2217 | onPageScroll: function (event) { |
| 2218 | this.fireEvent(event.name, event); |
| 2219 | }, |
| 2220 | onTime: function (event) { |
| 2221 | this.fireEvent(event.name, event); |
| 2222 | }, |
| 2223 | |
| 2224 | }; |
| 2225 | |
| 2226 | }(options); |
| 2227 | |
| 2228 | window.pys = window.pys || {}; |
| 2229 | window.pys.Facebook = Facebook; |
| 2230 | window.pys.Analytics = Analytics; |
| 2231 | window.pys.Utils = Utils; |
| 2232 | |
| 2233 | |
| 2234 | |
| 2235 | |
| 2236 | $(document).ready(function () { |
| 2237 | |
| 2238 | if($("#pys_late_event").length > 0) { |
| 2239 | var events = JSON.parse($("#pys_late_event").attr("dir")); |
| 2240 | for(var key in events) { |
| 2241 | var event = {}; |
| 2242 | event[events[key].e_id] = [events[key]]; |
| 2243 | if(options.staticEvents.hasOwnProperty(key)) { |
| 2244 | Object.assign(options.staticEvents[key], event); |
| 2245 | } else { |
| 2246 | options.staticEvents[key] = event; |
| 2247 | } |
| 2248 | |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | var Pinterest = Utils.setupPinterestObject(); |
| 2253 | var Bing = Utils.setupBingObject(); |
| 2254 | |
| 2255 | if(options.hasOwnProperty('cookie')) |
| 2256 | { |
| 2257 | if(options.cookie.externalID_disabled_by_api || options.cookie.disabled_all_cookie) |
| 2258 | { |
| 2259 | Cookies.remove('pbid') |
| 2260 | } |
| 2261 | if(options.cookie.disabled_advanced_form_data_cookie || options.cookie.disabled_all_cookie) |
| 2262 | { |
| 2263 | Cookies.remove('pys_advanced_form_data') |
| 2264 | } |
| 2265 | if(options.cookie.disabled_landing_page_cookie || options.cookie.disabled_all_cookie) |
| 2266 | { |
| 2267 | Cookies.remove('pys_landing_page') |
| 2268 | Cookies.remove('last_pys_landing_page') |
| 2269 | } |
| 2270 | if(options.cookie.disabled_trafficsource_cookie || options.cookie.disabled_all_cookie) |
| 2271 | { |
| 2272 | Cookies.remove('pysTrafficSource') |
| 2273 | Cookies.remove('last_pysTrafficSource') |
| 2274 | } |
| 2275 | if(options.cookie.disabled_first_visit_cookie || options.cookie.disabled_all_cookie) |
| 2276 | { |
| 2277 | Cookies.remove('pys_first_visit') |
| 2278 | |
| 2279 | } |
| 2280 | if(options.cookie.disabled_utmTerms_cookie || options.cookie.disabled_all_cookie) |
| 2281 | { |
| 2282 | $.each(Utils.utmTerms, function (index, name) { |
| 2283 | Cookies.remove('pys_' + name) |
| 2284 | }); |
| 2285 | $.each(Utils.utmTerms, function (index, name) { |
| 2286 | Cookies.remove('last_pys_' + name) |
| 2287 | }); |
| 2288 | } |
| 2289 | if(options.cookie.disabled_utmId_cookie || options.cookie.disabled_all_cookie) |
| 2290 | { |
| 2291 | $.each(Utils.utmId,function(index,name) { |
| 2292 | Cookies.remove('pys_' + name) |
| 2293 | }) |
| 2294 | $.each(Utils.utmId,function(index,name) { |
| 2295 | Cookies.remove('last_pys_' + name) |
| 2296 | }); |
| 2297 | } |
| 2298 | } |
| 2299 | |
| 2300 | |
| 2301 | Utils.manageCookies(); |
| 2302 | Utils.setupGdprCallbacks(); |
| 2303 | // page scroll event |
| 2304 | if ( options.dynamicEvents.hasOwnProperty("automatic_event_scroll") |
| 2305 | ) { |
| 2306 | |
| 2307 | var singlePageScroll = function () { |
| 2308 | |
| 2309 | |
| 2310 | var docHeight = $(document).height() - $(window).height(); |
| 2311 | var isFired = false; |
| 2312 | |
| 2313 | if (options.dynamicEvents.hasOwnProperty("automatic_event_scroll")) { |
| 2314 | var pixels = Object.keys(options.dynamicEvents.automatic_event_scroll); |
| 2315 | for(var i = 0;i<pixels.length;i++) { |
| 2316 | var event = Utils.clone(options.dynamicEvents.automatic_event_scroll[pixels[i]]); |
| 2317 | var scroll = Math.round(docHeight * event.scroll_percent / 100)// convert % to absolute positions |
| 2318 | |
| 2319 | if(scroll < $(window).scrollTop()) { |
| 2320 | Utils.copyProperties(Utils.getRequestParams(), event.params); |
| 2321 | getPixelBySlag(pixels[i]).onPageScroll(event); |
| 2322 | isFired = true |
| 2323 | } |
| 2324 | } |
| 2325 | } |
| 2326 | if(isFired) { |
| 2327 | $(document).off("scroll",singlePageScroll); |
| 2328 | } |
| 2329 | } |
| 2330 | $(document).on("scroll",singlePageScroll); |
| 2331 | } |
| 2332 | |
| 2333 | |
| 2334 | if (options.dynamicEvents.hasOwnProperty("automatic_event_time_on_page")) { |
| 2335 | var pixels = Object.keys(options.dynamicEvents.automatic_event_time_on_page); |
| 2336 | var time = options.dynamicEvents.automatic_event_time_on_page[pixels[0]].time_on_page; // the same for all pixel |
| 2337 | setTimeout(function(){ |
| 2338 | for(var i = 0;i<pixels.length;i++) { |
| 2339 | var event = Utils.clone(options.dynamicEvents.automatic_event_time_on_page[pixels[i]]); |
| 2340 | Utils.copyProperties(Utils.getRequestParams(), event.params); |
| 2341 | getPixelBySlag(pixels[i]).onTime(event); |
| 2342 | } |
| 2343 | },time*1000); |
| 2344 | } |
| 2345 | |
| 2346 | // setup Click Event |
| 2347 | if (options.dynamicEvents.hasOwnProperty("automatic_event_download")) { |
| 2348 | |
| 2349 | $(document).onFirst('click', 'a, button, input[type="button"], input[type="submit"]', function (e) { |
| 2350 | |
| 2351 | var $elem = $(this); |
| 2352 | |
| 2353 | // Download |
| 2354 | if(options.dynamicEvents.hasOwnProperty("automatic_event_download") |
| 2355 | ) { |
| 2356 | var isFired = false; |
| 2357 | if ($elem.is('a')) { |
| 2358 | var href = $elem.attr('href'); |
| 2359 | if (typeof href !== "string") { |
| 2360 | return; |
| 2361 | } |
| 2362 | href = href.trim(); |
| 2363 | var extension = Utils.getLinkExtension(href); |
| 2364 | var track_download = false; |
| 2365 | |
| 2366 | if (extension.length > 0) { |
| 2367 | |
| 2368 | if(options.dynamicEvents.hasOwnProperty("automatic_event_download") ) { |
| 2369 | var pixels = Object.keys(options.dynamicEvents.automatic_event_download); |
| 2370 | for (var i = 0; i < pixels.length; i++) { |
| 2371 | var event = Utils.clone(options.dynamicEvents.automatic_event_download[pixels[i]]); |
| 2372 | var extensions = event.extensions; |
| 2373 | if (extensions.includes(extension)) { |
| 2374 | |
| 2375 | if(pixels[i] == "tiktok") { |
| 2376 | getPixelBySlag(pixels[i]).fireEvent(tikEvent.name, event); |
| 2377 | } else { |
| 2378 | if (options.enable_remove_download_url_param) { |
| 2379 | href = href.split('?')[0]; |
| 2380 | } |
| 2381 | event.params.download_url = href; |
| 2382 | event.params.download_type = extension; |
| 2383 | event.params.download_name = Utils.getLinkFilename(href); |
| 2384 | getPixelBySlag(pixels[i]).onDownloadEvent(event); |
| 2385 | } |
| 2386 | |
| 2387 | isFired = true; |
| 2388 | } |
| 2389 | } |
| 2390 | } |
| 2391 | } |
| 2392 | } |
| 2393 | if(isFired) { // prevent duplicate events on the same element |
| 2394 | return; |
| 2395 | } |
| 2396 | } |
| 2397 | }); |
| 2398 | } |
| 2399 | |
| 2400 | |
| 2401 | // setup Dynamic events |
| 2402 | $.each(options.triggerEventTypes, function (triggerType, events) { |
| 2403 | |
| 2404 | $.each(events, function (eventId, triggers) { |
| 2405 | |
| 2406 | switch (triggerType) { |
| 2407 | case 'url_click': |
| 2408 | //@see: Utils.setupURLClickEvents() |
| 2409 | break; |
| 2410 | |
| 2411 | case 'css_click': |
| 2412 | Utils.setupCSSClickEvents(eventId, triggers); |
| 2413 | break; |
| 2414 | |
| 2415 | case 'css_mouseover': |
| 2416 | Utils.setupMouseOverClickEvents(eventId, triggers); |
| 2417 | break; |
| 2418 | |
| 2419 | case 'scroll_pos': |
| 2420 | Utils.setupScrollPosEvents(eventId, triggers); |
| 2421 | break; |
| 2422 | case 'comment': |
| 2423 | Utils.setupCommentEvents(eventId, triggers); |
| 2424 | break; |
| 2425 | } |
| 2426 | |
| 2427 | }); |
| 2428 | |
| 2429 | }); |
| 2430 | // setup WooCommerce events |
| 2431 | if (options.woo.enabled) { |
| 2432 | |
| 2433 | // WooCommerce AddToCart |
| 2434 | if (options.dynamicEvents.hasOwnProperty("woo_add_to_cart_on_button_click") |
| 2435 | && options.woo.hasOwnProperty("addToCartCatchMethod") |
| 2436 | && options.woo.addToCartCatchMethod === "add_cart_js" |
| 2437 | ) { |
| 2438 | |
| 2439 | // Loop, any kind of "simple" product, except external |
| 2440 | $('.add_to_cart_button:not(.product_type_variable,.product_type_bundle,.single_add_to_cart_button)').on("click",function (e) { |
| 2441 | |
| 2442 | var product_id = $(this).data('product_id'); |
| 2443 | |
| 2444 | if (typeof product_id !== 'undefined') { |
| 2445 | Facebook.onWooAddToCartOnButtonEvent(product_id); |
| 2446 | Analytics.onWooAddToCartOnButtonEvent(product_id); |
| 2447 | Pinterest.onWooAddToCartOnButtonEvent(product_id); |
| 2448 | Bing.onWooAddToCartOnButtonEvent(product_id); |
| 2449 | } |
| 2450 | |
| 2451 | }); |
| 2452 | |
| 2453 | // Single Product |
| 2454 | // tap try to https://stackoverflow.com/questions/30990967/on-tap-click-event-firing-twice-how-to-avoid-it |
| 2455 | // $(document) not work |
| 2456 | $('body').onFirst('click','button.single_add_to_cart_button,.single_add_to_cart_button',function (e) { |
| 2457 | |
| 2458 | var $button = $(this); |
| 2459 | |
| 2460 | if ($button.hasClass('disabled')) { |
| 2461 | return; |
| 2462 | } |
| 2463 | |
| 2464 | var $form = $button.closest('form'); |
| 2465 | |
| 2466 | var product_type = Utils.PRODUCT_SIMPLE; |
| 2467 | |
| 2468 | if ($form.length === 0) { |
| 2469 | return ; |
| 2470 | } else if ($form.hasClass('variations_form')) { |
| 2471 | product_type = Utils.PRODUCT_VARIABLE; |
| 2472 | } else if($form.hasClass('bundle_form')) { |
| 2473 | product_type = Utils.PRODUCT_BUNDLE; |
| 2474 | } else if($form.hasClass('grouped_form')) { |
| 2475 | product_type = Utils.PRODUCT_GROUPED; |
| 2476 | } |
| 2477 | |
| 2478 | |
| 2479 | |
| 2480 | |
| 2481 | var product_id; |
| 2482 | var qty; |
| 2483 | |
| 2484 | if (product_type === Utils.PRODUCT_GROUPED) { |
| 2485 | qty = 1; |
| 2486 | product_id = parseInt($form.find('*[name="add-to-cart"]').val()); |
| 2487 | } else if (product_type === Utils.PRODUCT_VARIABLE) { |
| 2488 | product_id = parseInt($form.find('*[name="add-to-cart"]').val()); |
| 2489 | var qtyTag = $form.find('input[name="quantity"]'); |
| 2490 | if(qtyTag.length <= 0) { |
| 2491 | qtyTag = $form.find('select[name="quantity"]'); |
| 2492 | } |
| 2493 | qty = parseInt(qtyTag.val()); |
| 2494 | } else { |
| 2495 | product_id = parseInt($form.find('*[name="add-to-cart"]').val()); |
| 2496 | var qtyTag = $form.find('input[name="quantity"]'); |
| 2497 | if(qtyTag.length <= 0) { |
| 2498 | qtyTag = $form.find('select[name="quantity"]'); |
| 2499 | } |
| 2500 | qty = parseInt(qtyTag.val()); |
| 2501 | } |
| 2502 | |
| 2503 | Facebook.onWooAddToCartOnSingleEvent(product_id, qty, product_type, $form); |
| 2504 | Analytics.onWooAddToCartOnSingleEvent(product_id, qty, product_type, $form); |
| 2505 | |
| 2506 | Pinterest.onWooAddToCartOnSingleEvent(product_id, qty, product_type, false, $form); |
| 2507 | Bing.onWooAddToCartOnSingleEvent(product_id, qty, product_type, false, $form); |
| 2508 | |
| 2509 | }); |
| 2510 | |
| 2511 | } |
| 2512 | |
| 2513 | // WooCommerce RemoveFromCart |
| 2514 | if (options.dynamicEvents.hasOwnProperty("woo_remove_from_cart")) { |
| 2515 | |
| 2516 | $('body').on('click', options.woo.removeFromCartSelector, function (e) { |
| 2517 | |
| 2518 | var $a = $(e.currentTarget), |
| 2519 | href = $a.attr('href'); |
| 2520 | |
| 2521 | // extract cart item hash from remove button URL |
| 2522 | var regex = new RegExp("[\\?&]remove_item=([^&#]*)"), |
| 2523 | results = regex.exec(href); |
| 2524 | |
| 2525 | if (results !== null) { |
| 2526 | |
| 2527 | var item_hash = results[1]; |
| 2528 | |
| 2529 | if (options.dynamicEvents["woo_remove_from_cart"].hasOwnProperty(item_hash)) { |
| 2530 | var events = options.dynamicEvents["woo_remove_from_cart"][item_hash]; |
| 2531 | Utils.fireEventForAllPixel("onWooRemoveFromCartEvent",events) |
| 2532 | } |
| 2533 | |
| 2534 | } |
| 2535 | |
| 2536 | }); |
| 2537 | } |
| 2538 | } |
| 2539 | |
| 2540 | // setup EDD events |
| 2541 | if (options.edd.enabled) { |
| 2542 | |
| 2543 | // EDD AddToCart |
| 2544 | if (options.dynamicEvents.hasOwnProperty("edd_add_to_cart_on_button_click")) { |
| 2545 | |
| 2546 | $('form.edd_download_purchase_form .edd-add-to-cart').on("click",function (e) { |
| 2547 | |
| 2548 | var $button = $(this); |
| 2549 | var $form = $button.closest('form'); |
| 2550 | var variable_price = $button.data('variablePrice'); // yes/no |
| 2551 | var price_mode = $button.data('priceMode'); // single/multi |
| 2552 | var ids = []; |
| 2553 | var quantities = []; |
| 2554 | var qty; |
| 2555 | var id; |
| 2556 | |
| 2557 | if (variable_price === 'yes' && price_mode === 'multi') { |
| 2558 | |
| 2559 | id = $form.find('input[name="download_id"]').val(); |
| 2560 | |
| 2561 | // get selected variants |
| 2562 | $.each($form.find('input[name="edd_options[price_id][]"]:checked'), function (i, el) { |
| 2563 | ids.push(id + '_' + $(el).val()); |
| 2564 | }); |
| 2565 | |
| 2566 | // get qty for selected variants |
| 2567 | $.each(ids, function (i, variant_id) { |
| 2568 | |
| 2569 | var variant_index = variant_id.split('_', 2); |
| 2570 | qty = $form.find('input[name="edd_download_quantity_' + variant_index[1] + '"]').val(); |
| 2571 | |
| 2572 | if (typeof qty !== 'undefined') { |
| 2573 | quantities.push(qty); |
| 2574 | } else { |
| 2575 | quantities.push(1); |
| 2576 | } |
| 2577 | |
| 2578 | }); |
| 2579 | |
| 2580 | } else if (variable_price === 'yes' && price_mode === 'single') { |
| 2581 | |
| 2582 | id = $form.find('input[name="download_id"]').val(); |
| 2583 | ids.push(id + '_' + $form.find('input[name="edd_options[price_id][]"]:checked').val()); |
| 2584 | |
| 2585 | qty = $form.find('input[name="edd_download_quantity"]').val(); |
| 2586 | |
| 2587 | if (typeof qty !== 'undefined') { |
| 2588 | quantities.push(qty); |
| 2589 | } else { |
| 2590 | quantities.push(1); |
| 2591 | } |
| 2592 | |
| 2593 | } else { |
| 2594 | |
| 2595 | ids.push($button.data('downloadId')); |
| 2596 | |
| 2597 | qty = $form.find('input[name="edd_download_quantity"]').val(); |
| 2598 | |
| 2599 | if (typeof qty !== 'undefined') { |
| 2600 | quantities.push(qty); |
| 2601 | } else { |
| 2602 | quantities.push(1); |
| 2603 | } |
| 2604 | } |
| 2605 | |
| 2606 | // fire event for each download/variant |
| 2607 | $.each(ids, function (i, download_id) { |
| 2608 | |
| 2609 | var q = parseInt(quantities[i]); |
| 2610 | var variant_index = download_id.toString().split('_', 2); |
| 2611 | var price_index; |
| 2612 | |
| 2613 | if (variant_index.length === 2) { |
| 2614 | download_id = variant_index[0]; |
| 2615 | price_index = variant_index[1]; |
| 2616 | } |
| 2617 | |
| 2618 | Facebook.onEddAddToCartOnButtonEvent(download_id, price_index, q); |
| 2619 | Analytics.onEddAddToCartOnButtonEvent(download_id, price_index, q); |
| 2620 | Pinterest.onEddAddToCartOnButtonEvent(download_id, price_index, q); |
| 2621 | Bing.onEddAddToCartOnButtonEvent(download_id, price_index, q); |
| 2622 | |
| 2623 | }); |
| 2624 | |
| 2625 | }); |
| 2626 | |
| 2627 | } |
| 2628 | |
| 2629 | |
| 2630 | // EDD RemoveFromCart |
| 2631 | if (options.dynamicEvents.hasOwnProperty("edd_remove_from_cart") ) { |
| 2632 | |
| 2633 | $('form#edd_checkout_cart_form .edd_cart_remove_item_btn').on("click",function (e) { |
| 2634 | |
| 2635 | var href = $(this).attr('href'); |
| 2636 | if(href) { |
| 2637 | var key = href.substring(href.indexOf('=') + 1).charAt(0); |
| 2638 | if (options.dynamicEvents.edd_remove_from_cart.hasOwnProperty(key)) { |
| 2639 | var events = options.dynamicEvents.edd_remove_from_cart[key]; |
| 2640 | Utils.fireEventForAllPixel("onEddRemoveFromCartEvent",events) |
| 2641 | } |
| 2642 | } |
| 2643 | }); |
| 2644 | |
| 2645 | } |
| 2646 | |
| 2647 | } |
| 2648 | |
| 2649 | // setup Comment Event |
| 2650 | if (options.dynamicEvents.hasOwnProperty("automatic_event_comment") |
| 2651 | ) { |
| 2652 | |
| 2653 | $('form.comment-form').on("submit",function () { |
| 2654 | if (options.dynamicEvents.hasOwnProperty("automatic_event_comment")) { |
| 2655 | var pixels = Object.keys(options.dynamicEvents.automatic_event_comment); |
| 2656 | for (var i = 0; i < pixels.length; i++) { |
| 2657 | var event = Utils.clone(options.dynamicEvents.automatic_event_comment[pixels[i]]); |
| 2658 | Utils.copyProperties(Utils.getRequestParams(), event.params); |
| 2659 | getPixelBySlag(pixels[i]).onCommentEvent(event); |
| 2660 | } |
| 2661 | } |
| 2662 | }); |
| 2663 | |
| 2664 | } |
| 2665 | |
| 2666 | |
| 2667 | // setup Form Event |
| 2668 | if ( options.dynamicEvents.hasOwnProperty("automatic_event_form")) { |
| 2669 | |
| 2670 | $(document).onFirst('submit', 'form', function (e) { |
| 2671 | |
| 2672 | var $form = $(this); |
| 2673 | |
| 2674 | // exclude WP forms |
| 2675 | if ($form.hasClass('comment-form') || $form.hasClass('search-form') || $form.attr('id') === 'adminbarsearch') { |
| 2676 | return; |
| 2677 | } |
| 2678 | |
| 2679 | // exclude Woo forms |
| 2680 | if ($form.hasClass('woocommerce-product-search') || $form.hasClass('cart') || $form.hasClass('woocommerce-cart-form') || |
| 2681 | $form.hasClass('woocommerce-shipping-calculator') || $form.hasClass('checkout') || $form.hasClass('checkout_coupon')) { |
| 2682 | return; |
| 2683 | } |
| 2684 | |
| 2685 | // exclude EDD forms |
| 2686 | if ($form.hasClass('edd_form') || $form.hasClass('edd_download_purchase_form')) { |
| 2687 | return; |
| 2688 | } |
| 2689 | // exclude CF7 forms |
| 2690 | if ($form.hasClass('wpcf7-form')) { |
| 2691 | return; |
| 2692 | } |
| 2693 | // exclude Forminator forms |
| 2694 | if ($form.hasClass('forminator-custom-form') || $form.hasClass('forminator_ajax')) { |
| 2695 | return; |
| 2696 | } |
| 2697 | // exclude WPforms forms |
| 2698 | if ($form.hasClass('wpforms-form') || $form.hasClass('wpforms-ajax-form')) { |
| 2699 | return; |
| 2700 | } |
| 2701 | // exclude Formidable forms |
| 2702 | /*if ($form.hasClass('frm-show-form')) { |
| 2703 | return; |
| 2704 | }*/ |
| 2705 | // exclude Ninja Forms forms |
| 2706 | if ($form.parent().hasClass('nf-form-layout')) { |
| 2707 | return; |
| 2708 | } |
| 2709 | // exclude Fluent forms |
| 2710 | if ($form.hasClass('frm-fluent-form')) { |
| 2711 | return; |
| 2712 | } |
| 2713 | if(!options.enable_success_send_form) { |
| 2714 | var params = { |
| 2715 | form_id: $form.attr('id'), |
| 2716 | form_class: $form.attr('class'), |
| 2717 | text: $form.find('[type="submit"]').is('input') ? |
| 2718 | $form.find('[type="submit"]').val() : $form.find('[type="submit"]').text() |
| 2719 | }; |
| 2720 | |
| 2721 | if (options.dynamicEvents.hasOwnProperty("automatic_event_form")) { |
| 2722 | var pixels = Object.keys(options.dynamicEvents.automatic_event_form); |
| 2723 | for (var i = 0; i < pixels.length; i++) { |
| 2724 | var event = Utils.clone(options.dynamicEvents.automatic_event_form[pixels[i]]); |
| 2725 | |
| 2726 | if (pixels[i] === "tiktok") { |
| 2727 | getPixelBySlag(pixels[i]).fireEvent(event.name, event); |
| 2728 | } else { |
| 2729 | Utils.copyProperties(params, event.params,) |
| 2730 | Utils.copyProperties(Utils.getRequestParams(), event.params); |
| 2731 | getPixelBySlag(pixels[i]).onFormEvent(event); |
| 2732 | } |
| 2733 | } |
| 2734 | } |
| 2735 | } |
| 2736 | }); |
| 2737 | |
| 2738 | document.addEventListener( 'wpcf7mailsent', function( event ) { |
| 2739 | var form_id = event.detail.contactFormId; |
| 2740 | sendFormAction($(event.target), form_id); |
| 2741 | }, false ); |
| 2742 | //Forminator |
| 2743 | $(document).on( 'forminator:form:submit:success', function( event ){ |
| 2744 | var form_id = $(event.target).find('input[name="form_id"]').val(); |
| 2745 | sendFormAction($(event.target), form_id); |
| 2746 | }); |
| 2747 | |
| 2748 | //WPForm |
| 2749 | $('form.wpforms-form').on('wpformsAjaxSubmitSuccess', (event) => { |
| 2750 | var form_id = $(event.target).attr('data-formid'); |
| 2751 | sendFormAction($(event.target), form_id); |
| 2752 | }) |
| 2753 | $(document).on( 'frmFormComplete', function( event, form, response ) { |
| 2754 | const form_id = $(form).find('input[name="form_id"]').val(); |
| 2755 | sendFormAction($(event.target), form_id); |
| 2756 | }); |
| 2757 | // Ninja Forms |
| 2758 | $(document).onFirst('nfFormSubmitResponse', function (event, data) { |
| 2759 | const form_id = data.response.data.form_id; |
| 2760 | sendFormAction($(event.target), form_id); |
| 2761 | }); |
| 2762 | |
| 2763 | var fluentForms = $('form.frm-fluent-form'); |
| 2764 | fluentForms.each(function() { |
| 2765 | var $form = $(this); |
| 2766 | $form.on('fluentform_submission_success', function(event) { |
| 2767 | var $formItem = $(this); |
| 2768 | var form_id = $formItem.attr('data-form_id'); |
| 2769 | sendFormAction($(event.target), form_id); |
| 2770 | }); |
| 2771 | }); |
| 2772 | |
| 2773 | } |
| 2774 | |
| 2775 | |
| 2776 | // load pixel APIs |
| 2777 | Utils.loadPixels(); |
| 2778 | // setup Enrich content |
| 2779 | if(Utils.isCheckoutPage()) { |
| 2780 | Utils.addCheckoutFields(); |
| 2781 | } |
| 2782 | }); |
| 2783 | |
| 2784 | var sendFormAction = function (form_target, formId){ |
| 2785 | var params = { |
| 2786 | form_id: formId, |
| 2787 | text: form_target.find('[type="submit"]').is('input') ? form_target.find('[type="submit"]').val() : |
| 2788 | form_target.find('.forminator-button-submit').text() != '' ? form_target.find('.forminator-button-submit').text() : |
| 2789 | form_target.find('[type="submit"]').text() |
| 2790 | }; |
| 2791 | |
| 2792 | if (options.dynamicEvents.hasOwnProperty("automatic_event_form")) { |
| 2793 | var pixels = Object.keys(options.dynamicEvents.automatic_event_form); |
| 2794 | for (var i = 0; i < pixels.length; i++) { |
| 2795 | var event = options.dynamicEvents.automatic_event_form[pixels[i]]; |
| 2796 | if (pixels[i] === "tiktok") { |
| 2797 | getPixelBySlag(pixels[i]).fireEvent(event.name, event); |
| 2798 | } else { |
| 2799 | Utils.copyProperties(params, event.params) |
| 2800 | Utils.copyProperties(Utils.getRequestParams(), event.params); |
| 2801 | getPixelBySlag(pixels[i]).onFormEvent(event); |
| 2802 | } |
| 2803 | } |
| 2804 | } |
| 2805 | } |
| 2806 | |
| 2807 | }(jQuery, pysOptions); |
| 2808 | |
| 2809 | function pys_generate_token(length){ |
| 2810 | //edit the token allowed characters |
| 2811 | var a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".split(""); |
| 2812 | var b = []; |
| 2813 | for (var i=0; i<length; i++) { |
| 2814 | var j = (Math.random() * (a.length-1)).toFixed(0); |
| 2815 | b[i] = a[j]; |
| 2816 | } |
| 2817 | return b.join(""); |
| 2818 | } |
| 2819 | |
| 2820 | function getBundlePriceOnSingleProduct(data) { |
| 2821 | var items_sum = 0; |
| 2822 | jQuery(".bundle_form .bundled_product").each(function(index){ |
| 2823 | var id = jQuery(this).find(".cart").data("bundled_item_id"); |
| 2824 | var item_price = data.prices[id]; |
| 2825 | var item_quantity = jQuery(this).find(".bundled_qty").val(); |
| 2826 | if(!jQuery(this).hasClass("bundled_item_optional") || |
| 2827 | jQuery(this).find(".bundled_product_optional_checkbox input").prop('checked')) { |
| 2828 | items_sum += item_price*item_quantity; |
| 2829 | } |
| 2830 | }); |
| 2831 | return items_sum; |
| 2832 | } |
| 2833 | |
| 2834 | function getPixelBySlag(slug) { |
| 2835 | switch (slug) { |
| 2836 | case "facebook": return window.pys.Facebook; |
| 2837 | case "ga": return window.pys.Analytics; |
| 2838 | case "bing": return window.pys.Bing; |
| 2839 | case "pinterest": return window.pys.Pinterest; |
| 2840 | } |
| 2841 | } |
| 2842 | var getUrlParameter = function getUrlParameter(sParam) { |
| 2843 | var sPageURL = window.location.search.substring(1), |
| 2844 | sURLVariables = sPageURL.split('&'), |
| 2845 | sParameterName, |
| 2846 | i; |
| 2847 | |
| 2848 | for (i = 0; i < sURLVariables.length; i++) { |
| 2849 | sParameterName = sURLVariables[i].split('='); |
| 2850 | |
| 2851 | if (sParameterName[0] === sParam) { |
| 2852 | return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); |
| 2853 | } |
| 2854 | } |
| 2855 | return false; |
| 2856 | }; |