saasco-sdk 0.1.40 → 0.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +293 -539
- package/index.esm.js +292 -535
- package/package.json +3 -2
- package/src/lib/analytics.d.ts +2 -1
- package/src/lib/integrations/index.d.ts +1 -0
- package/src/lib/integrations/tiktok-pixel.d.ts +59 -0
package/index.cjs.js
CHANGED
|
@@ -4,17 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
6
|
var psl = require('psl');
|
|
7
|
-
var
|
|
8
|
-
var require$$1 = require('buffer');
|
|
7
|
+
var jsSha256 = require('js-sha256');
|
|
9
8
|
var uuid$1 = require('@lukeed/uuid');
|
|
10
9
|
var zod = require('zod');
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
15
|
-
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
16
|
-
|
|
17
|
-
var version = "0.1.40";
|
|
11
|
+
var version = "0.1.42";
|
|
18
12
|
|
|
19
13
|
const timezones = {
|
|
20
14
|
'Asia/Barnaul': 'RU',
|
|
@@ -561,535 +555,8 @@ function getBrowserContext() {
|
|
|
561
555
|
};
|
|
562
556
|
}
|
|
563
557
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
var sha256 = {exports: {}};
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* [js-sha256]{@link https://github.com/emn178/js-sha256}
|
|
570
|
-
*
|
|
571
|
-
* @version 0.11.1
|
|
572
|
-
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
573
|
-
* @copyright Chen, Yi-Cyuan 2014-2025
|
|
574
|
-
* @license MIT
|
|
575
|
-
*/
|
|
576
|
-
|
|
577
|
-
(function (module) {
|
|
578
|
-
/*jslint bitwise: true */
|
|
579
|
-
(function () {
|
|
580
|
-
|
|
581
|
-
var ERROR = 'input is invalid type';
|
|
582
|
-
var WINDOW = typeof window === 'object';
|
|
583
|
-
var root = WINDOW ? window : {};
|
|
584
|
-
if (root.JS_SHA256_NO_WINDOW) {
|
|
585
|
-
WINDOW = false;
|
|
586
|
-
}
|
|
587
|
-
var WEB_WORKER = !WINDOW && typeof self === 'object';
|
|
588
|
-
var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node && process.type != 'renderer';
|
|
589
|
-
if (NODE_JS) {
|
|
590
|
-
root = commonjsGlobal;
|
|
591
|
-
} else if (WEB_WORKER) {
|
|
592
|
-
root = self;
|
|
593
|
-
}
|
|
594
|
-
var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && 'object' === 'object' && module.exports;
|
|
595
|
-
var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
|
596
|
-
var HEX_CHARS = '0123456789abcdef'.split('');
|
|
597
|
-
var EXTRA = [-2147483648, 8388608, 32768, 128];
|
|
598
|
-
var SHIFT = [24, 16, 8, 0];
|
|
599
|
-
var K = [
|
|
600
|
-
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
601
|
-
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
602
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
603
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
604
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
605
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
606
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
607
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
608
|
-
];
|
|
609
|
-
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
|
|
610
|
-
|
|
611
|
-
var blocks = [];
|
|
612
|
-
|
|
613
|
-
if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
|
|
614
|
-
Array.isArray = function (obj) {
|
|
615
|
-
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
|
|
620
|
-
ArrayBuffer.isView = function (obj) {
|
|
621
|
-
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
var createOutputMethod = function (outputType, is224) {
|
|
626
|
-
return function (message) {
|
|
627
|
-
return new Sha256(is224, true).update(message)[outputType]();
|
|
628
|
-
};
|
|
629
|
-
};
|
|
630
|
-
|
|
631
|
-
var createMethod = function (is224) {
|
|
632
|
-
var method = createOutputMethod('hex', is224);
|
|
633
|
-
if (NODE_JS) {
|
|
634
|
-
method = nodeWrap(method, is224);
|
|
635
|
-
}
|
|
636
|
-
method.create = function () {
|
|
637
|
-
return new Sha256(is224);
|
|
638
|
-
};
|
|
639
|
-
method.update = function (message) {
|
|
640
|
-
return method.create().update(message);
|
|
641
|
-
};
|
|
642
|
-
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
643
|
-
var type = OUTPUT_TYPES[i];
|
|
644
|
-
method[type] = createOutputMethod(type, is224);
|
|
645
|
-
}
|
|
646
|
-
return method;
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
var nodeWrap = function (method, is224) {
|
|
650
|
-
var crypto = require$$0__default["default"];
|
|
651
|
-
var Buffer = require$$1__default["default"].Buffer;
|
|
652
|
-
var algorithm = is224 ? 'sha224' : 'sha256';
|
|
653
|
-
var bufferFrom;
|
|
654
|
-
if (Buffer.from && !root.JS_SHA256_NO_BUFFER_FROM) {
|
|
655
|
-
bufferFrom = Buffer.from;
|
|
656
|
-
} else {
|
|
657
|
-
bufferFrom = function (message) {
|
|
658
|
-
return new Buffer(message);
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
var nodeMethod = function (message) {
|
|
662
|
-
if (typeof message === 'string') {
|
|
663
|
-
return crypto.createHash(algorithm).update(message, 'utf8').digest('hex');
|
|
664
|
-
} else {
|
|
665
|
-
if (message === null || message === undefined) {
|
|
666
|
-
throw new Error(ERROR);
|
|
667
|
-
} else if (message.constructor === ArrayBuffer) {
|
|
668
|
-
message = new Uint8Array(message);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
if (Array.isArray(message) || ArrayBuffer.isView(message) ||
|
|
672
|
-
message.constructor === Buffer) {
|
|
673
|
-
return crypto.createHash(algorithm).update(bufferFrom(message)).digest('hex');
|
|
674
|
-
} else {
|
|
675
|
-
return method(message);
|
|
676
|
-
}
|
|
677
|
-
};
|
|
678
|
-
return nodeMethod;
|
|
679
|
-
};
|
|
680
|
-
|
|
681
|
-
var createHmacOutputMethod = function (outputType, is224) {
|
|
682
|
-
return function (key, message) {
|
|
683
|
-
return new HmacSha256(key, is224, true).update(message)[outputType]();
|
|
684
|
-
};
|
|
685
|
-
};
|
|
686
|
-
|
|
687
|
-
var createHmacMethod = function (is224) {
|
|
688
|
-
var method = createHmacOutputMethod('hex', is224);
|
|
689
|
-
method.create = function (key) {
|
|
690
|
-
return new HmacSha256(key, is224);
|
|
691
|
-
};
|
|
692
|
-
method.update = function (key, message) {
|
|
693
|
-
return method.create(key).update(message);
|
|
694
|
-
};
|
|
695
|
-
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
696
|
-
var type = OUTPUT_TYPES[i];
|
|
697
|
-
method[type] = createHmacOutputMethod(type, is224);
|
|
698
|
-
}
|
|
699
|
-
return method;
|
|
700
|
-
};
|
|
701
|
-
|
|
702
|
-
function Sha256(is224, sharedMemory) {
|
|
703
|
-
if (sharedMemory) {
|
|
704
|
-
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
|
|
705
|
-
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
|
|
706
|
-
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
|
707
|
-
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
708
|
-
this.blocks = blocks;
|
|
709
|
-
} else {
|
|
710
|
-
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
if (is224) {
|
|
714
|
-
this.h0 = 0xc1059ed8;
|
|
715
|
-
this.h1 = 0x367cd507;
|
|
716
|
-
this.h2 = 0x3070dd17;
|
|
717
|
-
this.h3 = 0xf70e5939;
|
|
718
|
-
this.h4 = 0xffc00b31;
|
|
719
|
-
this.h5 = 0x68581511;
|
|
720
|
-
this.h6 = 0x64f98fa7;
|
|
721
|
-
this.h7 = 0xbefa4fa4;
|
|
722
|
-
} else { // 256
|
|
723
|
-
this.h0 = 0x6a09e667;
|
|
724
|
-
this.h1 = 0xbb67ae85;
|
|
725
|
-
this.h2 = 0x3c6ef372;
|
|
726
|
-
this.h3 = 0xa54ff53a;
|
|
727
|
-
this.h4 = 0x510e527f;
|
|
728
|
-
this.h5 = 0x9b05688c;
|
|
729
|
-
this.h6 = 0x1f83d9ab;
|
|
730
|
-
this.h7 = 0x5be0cd19;
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
this.block = this.start = this.bytes = this.hBytes = 0;
|
|
734
|
-
this.finalized = this.hashed = false;
|
|
735
|
-
this.first = true;
|
|
736
|
-
this.is224 = is224;
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
Sha256.prototype.update = function (message) {
|
|
740
|
-
if (this.finalized) {
|
|
741
|
-
return;
|
|
742
|
-
}
|
|
743
|
-
var notString, type = typeof message;
|
|
744
|
-
if (type !== 'string') {
|
|
745
|
-
if (type === 'object') {
|
|
746
|
-
if (message === null) {
|
|
747
|
-
throw new Error(ERROR);
|
|
748
|
-
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
749
|
-
message = new Uint8Array(message);
|
|
750
|
-
} else if (!Array.isArray(message)) {
|
|
751
|
-
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
|
752
|
-
throw new Error(ERROR);
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
} else {
|
|
756
|
-
throw new Error(ERROR);
|
|
757
|
-
}
|
|
758
|
-
notString = true;
|
|
759
|
-
}
|
|
760
|
-
var code, index = 0, i, length = message.length, blocks = this.blocks;
|
|
761
|
-
while (index < length) {
|
|
762
|
-
if (this.hashed) {
|
|
763
|
-
this.hashed = false;
|
|
764
|
-
blocks[0] = this.block;
|
|
765
|
-
this.block = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
|
|
766
|
-
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
|
|
767
|
-
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
|
768
|
-
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
if (notString) {
|
|
772
|
-
for (i = this.start; index < length && i < 64; ++index) {
|
|
773
|
-
blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3];
|
|
774
|
-
}
|
|
775
|
-
} else {
|
|
776
|
-
for (i = this.start; index < length && i < 64; ++index) {
|
|
777
|
-
code = message.charCodeAt(index);
|
|
778
|
-
if (code < 0x80) {
|
|
779
|
-
blocks[i >>> 2] |= code << SHIFT[i++ & 3];
|
|
780
|
-
} else if (code < 0x800) {
|
|
781
|
-
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
|
|
782
|
-
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
783
|
-
} else if (code < 0xd800 || code >= 0xe000) {
|
|
784
|
-
blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
|
|
785
|
-
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
786
|
-
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
787
|
-
} else {
|
|
788
|
-
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
|
789
|
-
blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
|
|
790
|
-
blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
|
|
791
|
-
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
792
|
-
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
this.lastByteIndex = i;
|
|
798
|
-
this.bytes += i - this.start;
|
|
799
|
-
if (i >= 64) {
|
|
800
|
-
this.block = blocks[16];
|
|
801
|
-
this.start = i - 64;
|
|
802
|
-
this.hash();
|
|
803
|
-
this.hashed = true;
|
|
804
|
-
} else {
|
|
805
|
-
this.start = i;
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
if (this.bytes > 4294967295) {
|
|
809
|
-
this.hBytes += this.bytes / 4294967296 << 0;
|
|
810
|
-
this.bytes = this.bytes % 4294967296;
|
|
811
|
-
}
|
|
812
|
-
return this;
|
|
813
|
-
};
|
|
814
|
-
|
|
815
|
-
Sha256.prototype.finalize = function () {
|
|
816
|
-
if (this.finalized) {
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
this.finalized = true;
|
|
820
|
-
var blocks = this.blocks, i = this.lastByteIndex;
|
|
821
|
-
blocks[16] = this.block;
|
|
822
|
-
blocks[i >>> 2] |= EXTRA[i & 3];
|
|
823
|
-
this.block = blocks[16];
|
|
824
|
-
if (i >= 56) {
|
|
825
|
-
if (!this.hashed) {
|
|
826
|
-
this.hash();
|
|
827
|
-
}
|
|
828
|
-
blocks[0] = this.block;
|
|
829
|
-
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
|
|
830
|
-
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
|
|
831
|
-
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
|
832
|
-
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
833
|
-
}
|
|
834
|
-
blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
|
|
835
|
-
blocks[15] = this.bytes << 3;
|
|
836
|
-
this.hash();
|
|
837
|
-
};
|
|
838
|
-
|
|
839
|
-
Sha256.prototype.hash = function () {
|
|
840
|
-
var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6,
|
|
841
|
-
h = this.h7, blocks = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
|
|
842
|
-
|
|
843
|
-
for (j = 16; j < 64; ++j) {
|
|
844
|
-
// rightrotate
|
|
845
|
-
t1 = blocks[j - 15];
|
|
846
|
-
s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3);
|
|
847
|
-
t1 = blocks[j - 2];
|
|
848
|
-
s1 = ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10);
|
|
849
|
-
blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1 << 0;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
bc = b & c;
|
|
853
|
-
for (j = 0; j < 64; j += 4) {
|
|
854
|
-
if (this.first) {
|
|
855
|
-
if (this.is224) {
|
|
856
|
-
ab = 300032;
|
|
857
|
-
t1 = blocks[0] - 1413257819;
|
|
858
|
-
h = t1 - 150054599 << 0;
|
|
859
|
-
d = t1 + 24177077 << 0;
|
|
860
|
-
} else {
|
|
861
|
-
ab = 704751109;
|
|
862
|
-
t1 = blocks[0] - 210244248;
|
|
863
|
-
h = t1 - 1521486534 << 0;
|
|
864
|
-
d = t1 + 143694565 << 0;
|
|
865
|
-
}
|
|
866
|
-
this.first = false;
|
|
867
|
-
} else {
|
|
868
|
-
s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
|
|
869
|
-
s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
|
|
870
|
-
ab = a & b;
|
|
871
|
-
maj = ab ^ (a & c) ^ bc;
|
|
872
|
-
ch = (e & f) ^ (~e & g);
|
|
873
|
-
t1 = h + s1 + ch + K[j] + blocks[j];
|
|
874
|
-
t2 = s0 + maj;
|
|
875
|
-
h = d + t1 << 0;
|
|
876
|
-
d = t1 + t2 << 0;
|
|
877
|
-
}
|
|
878
|
-
s0 = ((d >>> 2) | (d << 30)) ^ ((d >>> 13) | (d << 19)) ^ ((d >>> 22) | (d << 10));
|
|
879
|
-
s1 = ((h >>> 6) | (h << 26)) ^ ((h >>> 11) | (h << 21)) ^ ((h >>> 25) | (h << 7));
|
|
880
|
-
da = d & a;
|
|
881
|
-
maj = da ^ (d & b) ^ ab;
|
|
882
|
-
ch = (h & e) ^ (~h & f);
|
|
883
|
-
t1 = g + s1 + ch + K[j + 1] + blocks[j + 1];
|
|
884
|
-
t2 = s0 + maj;
|
|
885
|
-
g = c + t1 << 0;
|
|
886
|
-
c = t1 + t2 << 0;
|
|
887
|
-
s0 = ((c >>> 2) | (c << 30)) ^ ((c >>> 13) | (c << 19)) ^ ((c >>> 22) | (c << 10));
|
|
888
|
-
s1 = ((g >>> 6) | (g << 26)) ^ ((g >>> 11) | (g << 21)) ^ ((g >>> 25) | (g << 7));
|
|
889
|
-
cd = c & d;
|
|
890
|
-
maj = cd ^ (c & a) ^ da;
|
|
891
|
-
ch = (g & h) ^ (~g & e);
|
|
892
|
-
t1 = f + s1 + ch + K[j + 2] + blocks[j + 2];
|
|
893
|
-
t2 = s0 + maj;
|
|
894
|
-
f = b + t1 << 0;
|
|
895
|
-
b = t1 + t2 << 0;
|
|
896
|
-
s0 = ((b >>> 2) | (b << 30)) ^ ((b >>> 13) | (b << 19)) ^ ((b >>> 22) | (b << 10));
|
|
897
|
-
s1 = ((f >>> 6) | (f << 26)) ^ ((f >>> 11) | (f << 21)) ^ ((f >>> 25) | (f << 7));
|
|
898
|
-
bc = b & c;
|
|
899
|
-
maj = bc ^ (b & d) ^ cd;
|
|
900
|
-
ch = (f & g) ^ (~f & h);
|
|
901
|
-
t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
|
|
902
|
-
t2 = s0 + maj;
|
|
903
|
-
e = a + t1 << 0;
|
|
904
|
-
a = t1 + t2 << 0;
|
|
905
|
-
this.chromeBugWorkAround = true;
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
this.h0 = this.h0 + a << 0;
|
|
909
|
-
this.h1 = this.h1 + b << 0;
|
|
910
|
-
this.h2 = this.h2 + c << 0;
|
|
911
|
-
this.h3 = this.h3 + d << 0;
|
|
912
|
-
this.h4 = this.h4 + e << 0;
|
|
913
|
-
this.h5 = this.h5 + f << 0;
|
|
914
|
-
this.h6 = this.h6 + g << 0;
|
|
915
|
-
this.h7 = this.h7 + h << 0;
|
|
916
|
-
};
|
|
917
|
-
|
|
918
|
-
Sha256.prototype.hex = function () {
|
|
919
|
-
this.finalize();
|
|
920
|
-
|
|
921
|
-
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5,
|
|
922
|
-
h6 = this.h6, h7 = this.h7;
|
|
923
|
-
|
|
924
|
-
var hex = HEX_CHARS[(h0 >>> 28) & 0x0F] + HEX_CHARS[(h0 >>> 24) & 0x0F] +
|
|
925
|
-
HEX_CHARS[(h0 >>> 20) & 0x0F] + HEX_CHARS[(h0 >>> 16) & 0x0F] +
|
|
926
|
-
HEX_CHARS[(h0 >>> 12) & 0x0F] + HEX_CHARS[(h0 >>> 8) & 0x0F] +
|
|
927
|
-
HEX_CHARS[(h0 >>> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
|
|
928
|
-
HEX_CHARS[(h1 >>> 28) & 0x0F] + HEX_CHARS[(h1 >>> 24) & 0x0F] +
|
|
929
|
-
HEX_CHARS[(h1 >>> 20) & 0x0F] + HEX_CHARS[(h1 >>> 16) & 0x0F] +
|
|
930
|
-
HEX_CHARS[(h1 >>> 12) & 0x0F] + HEX_CHARS[(h1 >>> 8) & 0x0F] +
|
|
931
|
-
HEX_CHARS[(h1 >>> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
|
|
932
|
-
HEX_CHARS[(h2 >>> 28) & 0x0F] + HEX_CHARS[(h2 >>> 24) & 0x0F] +
|
|
933
|
-
HEX_CHARS[(h2 >>> 20) & 0x0F] + HEX_CHARS[(h2 >>> 16) & 0x0F] +
|
|
934
|
-
HEX_CHARS[(h2 >>> 12) & 0x0F] + HEX_CHARS[(h2 >>> 8) & 0x0F] +
|
|
935
|
-
HEX_CHARS[(h2 >>> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
|
|
936
|
-
HEX_CHARS[(h3 >>> 28) & 0x0F] + HEX_CHARS[(h3 >>> 24) & 0x0F] +
|
|
937
|
-
HEX_CHARS[(h3 >>> 20) & 0x0F] + HEX_CHARS[(h3 >>> 16) & 0x0F] +
|
|
938
|
-
HEX_CHARS[(h3 >>> 12) & 0x0F] + HEX_CHARS[(h3 >>> 8) & 0x0F] +
|
|
939
|
-
HEX_CHARS[(h3 >>> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
|
|
940
|
-
HEX_CHARS[(h4 >>> 28) & 0x0F] + HEX_CHARS[(h4 >>> 24) & 0x0F] +
|
|
941
|
-
HEX_CHARS[(h4 >>> 20) & 0x0F] + HEX_CHARS[(h4 >>> 16) & 0x0F] +
|
|
942
|
-
HEX_CHARS[(h4 >>> 12) & 0x0F] + HEX_CHARS[(h4 >>> 8) & 0x0F] +
|
|
943
|
-
HEX_CHARS[(h4 >>> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F] +
|
|
944
|
-
HEX_CHARS[(h5 >>> 28) & 0x0F] + HEX_CHARS[(h5 >>> 24) & 0x0F] +
|
|
945
|
-
HEX_CHARS[(h5 >>> 20) & 0x0F] + HEX_CHARS[(h5 >>> 16) & 0x0F] +
|
|
946
|
-
HEX_CHARS[(h5 >>> 12) & 0x0F] + HEX_CHARS[(h5 >>> 8) & 0x0F] +
|
|
947
|
-
HEX_CHARS[(h5 >>> 4) & 0x0F] + HEX_CHARS[h5 & 0x0F] +
|
|
948
|
-
HEX_CHARS[(h6 >>> 28) & 0x0F] + HEX_CHARS[(h6 >>> 24) & 0x0F] +
|
|
949
|
-
HEX_CHARS[(h6 >>> 20) & 0x0F] + HEX_CHARS[(h6 >>> 16) & 0x0F] +
|
|
950
|
-
HEX_CHARS[(h6 >>> 12) & 0x0F] + HEX_CHARS[(h6 >>> 8) & 0x0F] +
|
|
951
|
-
HEX_CHARS[(h6 >>> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F];
|
|
952
|
-
if (!this.is224) {
|
|
953
|
-
hex += HEX_CHARS[(h7 >>> 28) & 0x0F] + HEX_CHARS[(h7 >>> 24) & 0x0F] +
|
|
954
|
-
HEX_CHARS[(h7 >>> 20) & 0x0F] + HEX_CHARS[(h7 >>> 16) & 0x0F] +
|
|
955
|
-
HEX_CHARS[(h7 >>> 12) & 0x0F] + HEX_CHARS[(h7 >>> 8) & 0x0F] +
|
|
956
|
-
HEX_CHARS[(h7 >>> 4) & 0x0F] + HEX_CHARS[h7 & 0x0F];
|
|
957
|
-
}
|
|
958
|
-
return hex;
|
|
959
|
-
};
|
|
960
|
-
|
|
961
|
-
Sha256.prototype.toString = Sha256.prototype.hex;
|
|
962
|
-
|
|
963
|
-
Sha256.prototype.digest = function () {
|
|
964
|
-
this.finalize();
|
|
965
|
-
|
|
966
|
-
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5,
|
|
967
|
-
h6 = this.h6, h7 = this.h7;
|
|
968
|
-
|
|
969
|
-
var arr = [
|
|
970
|
-
(h0 >>> 24) & 0xFF, (h0 >>> 16) & 0xFF, (h0 >>> 8) & 0xFF, h0 & 0xFF,
|
|
971
|
-
(h1 >>> 24) & 0xFF, (h1 >>> 16) & 0xFF, (h1 >>> 8) & 0xFF, h1 & 0xFF,
|
|
972
|
-
(h2 >>> 24) & 0xFF, (h2 >>> 16) & 0xFF, (h2 >>> 8) & 0xFF, h2 & 0xFF,
|
|
973
|
-
(h3 >>> 24) & 0xFF, (h3 >>> 16) & 0xFF, (h3 >>> 8) & 0xFF, h3 & 0xFF,
|
|
974
|
-
(h4 >>> 24) & 0xFF, (h4 >>> 16) & 0xFF, (h4 >>> 8) & 0xFF, h4 & 0xFF,
|
|
975
|
-
(h5 >>> 24) & 0xFF, (h5 >>> 16) & 0xFF, (h5 >>> 8) & 0xFF, h5 & 0xFF,
|
|
976
|
-
(h6 >>> 24) & 0xFF, (h6 >>> 16) & 0xFF, (h6 >>> 8) & 0xFF, h6 & 0xFF
|
|
977
|
-
];
|
|
978
|
-
if (!this.is224) {
|
|
979
|
-
arr.push((h7 >>> 24) & 0xFF, (h7 >>> 16) & 0xFF, (h7 >>> 8) & 0xFF, h7 & 0xFF);
|
|
980
|
-
}
|
|
981
|
-
return arr;
|
|
982
|
-
};
|
|
983
|
-
|
|
984
|
-
Sha256.prototype.array = Sha256.prototype.digest;
|
|
985
|
-
|
|
986
|
-
Sha256.prototype.arrayBuffer = function () {
|
|
987
|
-
this.finalize();
|
|
988
|
-
|
|
989
|
-
var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
|
|
990
|
-
var dataView = new DataView(buffer);
|
|
991
|
-
dataView.setUint32(0, this.h0);
|
|
992
|
-
dataView.setUint32(4, this.h1);
|
|
993
|
-
dataView.setUint32(8, this.h2);
|
|
994
|
-
dataView.setUint32(12, this.h3);
|
|
995
|
-
dataView.setUint32(16, this.h4);
|
|
996
|
-
dataView.setUint32(20, this.h5);
|
|
997
|
-
dataView.setUint32(24, this.h6);
|
|
998
|
-
if (!this.is224) {
|
|
999
|
-
dataView.setUint32(28, this.h7);
|
|
1000
|
-
}
|
|
1001
|
-
return buffer;
|
|
1002
|
-
};
|
|
1003
|
-
|
|
1004
|
-
function HmacSha256(key, is224, sharedMemory) {
|
|
1005
|
-
var i, type = typeof key;
|
|
1006
|
-
if (type === 'string') {
|
|
1007
|
-
var bytes = [], length = key.length, index = 0, code;
|
|
1008
|
-
for (i = 0; i < length; ++i) {
|
|
1009
|
-
code = key.charCodeAt(i);
|
|
1010
|
-
if (code < 0x80) {
|
|
1011
|
-
bytes[index++] = code;
|
|
1012
|
-
} else if (code < 0x800) {
|
|
1013
|
-
bytes[index++] = (0xc0 | (code >>> 6));
|
|
1014
|
-
bytes[index++] = (0x80 | (code & 0x3f));
|
|
1015
|
-
} else if (code < 0xd800 || code >= 0xe000) {
|
|
1016
|
-
bytes[index++] = (0xe0 | (code >>> 12));
|
|
1017
|
-
bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
|
|
1018
|
-
bytes[index++] = (0x80 | (code & 0x3f));
|
|
1019
|
-
} else {
|
|
1020
|
-
code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
|
|
1021
|
-
bytes[index++] = (0xf0 | (code >>> 18));
|
|
1022
|
-
bytes[index++] = (0x80 | ((code >>> 12) & 0x3f));
|
|
1023
|
-
bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
|
|
1024
|
-
bytes[index++] = (0x80 | (code & 0x3f));
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
key = bytes;
|
|
1028
|
-
} else {
|
|
1029
|
-
if (type === 'object') {
|
|
1030
|
-
if (key === null) {
|
|
1031
|
-
throw new Error(ERROR);
|
|
1032
|
-
} else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
|
|
1033
|
-
key = new Uint8Array(key);
|
|
1034
|
-
} else if (!Array.isArray(key)) {
|
|
1035
|
-
if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
|
|
1036
|
-
throw new Error(ERROR);
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
} else {
|
|
1040
|
-
throw new Error(ERROR);
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
if (key.length > 64) {
|
|
1045
|
-
key = (new Sha256(is224, true)).update(key).array();
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
var oKeyPad = [], iKeyPad = [];
|
|
1049
|
-
for (i = 0; i < 64; ++i) {
|
|
1050
|
-
var b = key[i] || 0;
|
|
1051
|
-
oKeyPad[i] = 0x5c ^ b;
|
|
1052
|
-
iKeyPad[i] = 0x36 ^ b;
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
Sha256.call(this, is224, sharedMemory);
|
|
1056
|
-
|
|
1057
|
-
this.update(iKeyPad);
|
|
1058
|
-
this.oKeyPad = oKeyPad;
|
|
1059
|
-
this.inner = true;
|
|
1060
|
-
this.sharedMemory = sharedMemory;
|
|
1061
|
-
}
|
|
1062
|
-
HmacSha256.prototype = new Sha256();
|
|
1063
|
-
|
|
1064
|
-
HmacSha256.prototype.finalize = function () {
|
|
1065
|
-
Sha256.prototype.finalize.call(this);
|
|
1066
|
-
if (this.inner) {
|
|
1067
|
-
this.inner = false;
|
|
1068
|
-
var innerHash = this.array();
|
|
1069
|
-
Sha256.call(this, this.is224, this.sharedMemory);
|
|
1070
|
-
this.update(this.oKeyPad);
|
|
1071
|
-
this.update(innerHash);
|
|
1072
|
-
Sha256.prototype.finalize.call(this);
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
|
-
|
|
1076
|
-
var exports = createMethod();
|
|
1077
|
-
exports.sha256 = exports;
|
|
1078
|
-
exports.sha224 = createMethod(true);
|
|
1079
|
-
exports.sha256.hmac = createHmacMethod();
|
|
1080
|
-
exports.sha224.hmac = createHmacMethod(true);
|
|
1081
|
-
|
|
1082
|
-
if (COMMON_JS) {
|
|
1083
|
-
module.exports = exports;
|
|
1084
|
-
} else {
|
|
1085
|
-
root.sha256 = exports.sha256;
|
|
1086
|
-
root.sha224 = exports.sha224;
|
|
1087
|
-
}
|
|
1088
|
-
})();
|
|
1089
|
-
}(sha256));
|
|
1090
|
-
|
|
1091
|
-
const isBrowser$1 = typeof window !== 'undefined';
|
|
1092
|
-
const isServer$1 = !isBrowser$1;
|
|
558
|
+
const isBrowser$2 = typeof window !== 'undefined';
|
|
559
|
+
const isServer$2 = !isBrowser$2;
|
|
1093
560
|
const standardFacebookEvents = ['AddPaymentInfo', 'AddToCart', 'AddToWishlist', 'CompleteRegistration', 'Contact', 'CustomizeProduct', 'Donate', 'FindLocation', 'InitiateCheckout', 'Lead', 'Purchase', 'Schedule', 'Search', 'StartTrial', 'SubmitApplication', 'Subscribe', 'ViewContent', 'PageView'];
|
|
1094
561
|
/**
|
|
1095
562
|
* Create a Facebook Pixel integration instance
|
|
@@ -1100,7 +567,7 @@ function createFacebookPixelIntegration(config) {
|
|
|
1100
567
|
name: 'facebook-pixel',
|
|
1101
568
|
environments: ['client'],
|
|
1102
569
|
init: () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1103
|
-
if (isServer$
|
|
570
|
+
if (isServer$2) {
|
|
1104
571
|
// On server, Facebook Pixel is a no-op but doesn't throw
|
|
1105
572
|
// This allows the integration to be registered but remain inactive
|
|
1106
573
|
return;
|
|
@@ -1179,9 +646,13 @@ function createFacebookPixelIntegration(config) {
|
|
|
1179
646
|
const amValues = coerceMetaConversionsAmValues(Object.assign(Object.assign({}, properties || {}), userId ? {
|
|
1180
647
|
external_id: userId
|
|
1181
648
|
} : {}));
|
|
649
|
+
// Advanced Matching
|
|
650
|
+
// Add event to identify user and hash email field
|
|
651
|
+
// FB pixel handles hashing automatically
|
|
652
|
+
// https://developers.facebook.com/docs/meta-pixel/advanced/advanced-matching/
|
|
1182
653
|
const am = {};
|
|
1183
654
|
if (amValues.external_id) am['external_id'] = amValues.external_id;
|
|
1184
|
-
if (amValues.em) am['em'] =
|
|
655
|
+
if (amValues.em) am['em'] = jsSha256.sha256(amValues.em);
|
|
1185
656
|
if (amValues.fn) am['fn'] = amValues.fn;
|
|
1186
657
|
if (amValues.ln) am['ln'] = amValues.ln;
|
|
1187
658
|
if (amValues.ph) am['ph'] = amValues.ph;
|
|
@@ -1207,6 +678,18 @@ function getFacebookEventName(eventName, eventMapping) {
|
|
|
1207
678
|
if (!eventMapping) return eventName;
|
|
1208
679
|
return eventMapping[eventName] || eventName;
|
|
1209
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* Get Advanced Matching values from properties
|
|
683
|
+
*
|
|
684
|
+
* Documentation for Pixel
|
|
685
|
+
* https://developers.facebook.com/docs/meta-pixel/advanced/advanced-matching/
|
|
686
|
+
*
|
|
687
|
+
* Documentation for Conversions API
|
|
688
|
+
* https://developers.secure.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters
|
|
689
|
+
*
|
|
690
|
+
* @param properties
|
|
691
|
+
* @returns
|
|
692
|
+
*/
|
|
1210
693
|
function coerceMetaConversionsAmValues(properties) {
|
|
1211
694
|
const coerce = [{
|
|
1212
695
|
key: 'em',
|
|
@@ -1314,6 +797,214 @@ function coerceMetaConversionsAmValues(properties) {
|
|
|
1314
797
|
}
|
|
1315
798
|
}];
|
|
1316
799
|
const result = {};
|
|
800
|
+
for (const {
|
|
801
|
+
key,
|
|
802
|
+
coerceFrom,
|
|
803
|
+
transform
|
|
804
|
+
} of coerce) {
|
|
805
|
+
const foundValue = findFirstProperty$1(properties, coerceFrom);
|
|
806
|
+
if (foundValue !== null && transform) {
|
|
807
|
+
const transformedValue = transform(foundValue);
|
|
808
|
+
if (transformedValue) {
|
|
809
|
+
result[key] = transformedValue;
|
|
810
|
+
}
|
|
811
|
+
} else if (foundValue !== null && typeof foundValue === 'string') {
|
|
812
|
+
result[key] = foundValue;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
return result;
|
|
816
|
+
}
|
|
817
|
+
function findFirstProperty$1(properties, keys) {
|
|
818
|
+
for (const key of keys) {
|
|
819
|
+
if (properties[key] !== undefined) {
|
|
820
|
+
return properties[key];
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
return null;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* TikTok Pixel Integration
|
|
828
|
+
*
|
|
829
|
+
* This integration provides TikTok Pixel tracking capabilities including:
|
|
830
|
+
* - Event tracking for standard and custom events
|
|
831
|
+
* - Advanced matching with hashed user identification data
|
|
832
|
+
* - Automatic script loading and initialization
|
|
833
|
+
*
|
|
834
|
+
* Key Resources:
|
|
835
|
+
* - Advanced Matching: https://business-api.tiktok.com/portal/docs?rid=5ipocbxyw8v&id=1739585700402178
|
|
836
|
+
* - Standard Events: https://business-api.tiktok.com/portal/docs?id=1771101186666498
|
|
837
|
+
*/
|
|
838
|
+
const isBrowser$1 = typeof window !== 'undefined';
|
|
839
|
+
const isServer$1 = !isBrowser$1;
|
|
840
|
+
/**
|
|
841
|
+
* Standard TikTok events supported by the pixel
|
|
842
|
+
*
|
|
843
|
+
* Note: This list reflects TikTok's official standard events. Events like 'CompletePayment'
|
|
844
|
+
* are not standard events and should be tracked as custom events if needed.
|
|
845
|
+
*
|
|
846
|
+
* Documentation: https://business-api.tiktok.com/portal/docs?id=1771101186666498
|
|
847
|
+
*/
|
|
848
|
+
const standardTikTokEvents = ['AddPaymentInfo', 'AddToCart', 'AddToWishlist', 'ApplicationApproval', 'CompleteRegistration', 'Contact', 'CustomizeProduct', 'Download', 'FindLocation', 'InitiateCheckout', 'Lead', 'Purchase', 'Schedule', 'Search', 'StartTrial', 'SubmitApplication', 'Subscribe', 'ViewContent', 'PageView'];
|
|
849
|
+
/**
|
|
850
|
+
* Create a TikTok Pixel integration instance
|
|
851
|
+
*/
|
|
852
|
+
function createTikTokPixelIntegration(config) {
|
|
853
|
+
let isPixelReady = false;
|
|
854
|
+
return {
|
|
855
|
+
name: 'tiktok-pixel',
|
|
856
|
+
environments: ['client'],
|
|
857
|
+
init: () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
858
|
+
if (isServer$1) {
|
|
859
|
+
// On server, TikTok Pixel is a no-op but doesn't throw
|
|
860
|
+
// This allows the integration to be registered but remain inactive
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
// Check if TikTok Pixel is already loaded
|
|
864
|
+
if (window.ttq) {
|
|
865
|
+
console.warn('TikTok Pixel is already initialized');
|
|
866
|
+
isPixelReady = true;
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
// Initialize TikTok Pixel
|
|
870
|
+
return new Promise((resolve, reject) => {
|
|
871
|
+
try {
|
|
872
|
+
(function (w, d, t) {
|
|
873
|
+
w.TiktokAnalyticsObject = t;
|
|
874
|
+
const ttq = w[t] = w[t] || [];
|
|
875
|
+
ttq.methods = ['page', 'track', 'identify', 'instances', 'debug', 'on', 'off', 'once', 'ready', 'alias', 'group', 'enableCookie', 'disableCookie', 'holdConsent', 'revokeConsent', 'grantConsent'];
|
|
876
|
+
ttq.setAndDefer = function (t, e) {
|
|
877
|
+
t[e] = function () {
|
|
878
|
+
t.push([e].concat(Array.prototype.slice.call(arguments, 0)));
|
|
879
|
+
};
|
|
880
|
+
};
|
|
881
|
+
for (let i = 0; i < ttq.methods.length; i++) ttq.setAndDefer(ttq, ttq.methods[i]);
|
|
882
|
+
ttq.instance = function (t) {
|
|
883
|
+
const e = ttq._i[t] || [];
|
|
884
|
+
for (let n = 0; n < ttq.methods.length; n++) ttq.setAndDefer(e, ttq.methods[n]);
|
|
885
|
+
return e;
|
|
886
|
+
};
|
|
887
|
+
ttq.load = function (e, n) {
|
|
888
|
+
const r = 'https://analytics.tiktok.com/i18n/pixel/events.js';
|
|
889
|
+
const o = n && n.partner;
|
|
890
|
+
ttq._i = ttq._i || {};
|
|
891
|
+
ttq._i[e] = [];
|
|
892
|
+
ttq._i[e]._u = r;
|
|
893
|
+
ttq._t = ttq._t || {};
|
|
894
|
+
ttq._t[e] = +new Date();
|
|
895
|
+
ttq._o = ttq._o || {};
|
|
896
|
+
ttq._o[e] = n || {};
|
|
897
|
+
const script = document.createElement('script');
|
|
898
|
+
script.type = 'text/javascript';
|
|
899
|
+
script.async = true;
|
|
900
|
+
script.src = r + '?sdkid=' + e + '&lib=' + t;
|
|
901
|
+
// Add load event listener
|
|
902
|
+
script.onload = () => {
|
|
903
|
+
isPixelReady = true;
|
|
904
|
+
resolve();
|
|
905
|
+
};
|
|
906
|
+
script.onerror = () => {
|
|
907
|
+
reject(new Error('Failed to load TikTok Pixel script'));
|
|
908
|
+
};
|
|
909
|
+
const firstScript = document.getElementsByTagName('script')[0];
|
|
910
|
+
firstScript.parentNode.insertBefore(script, firstScript);
|
|
911
|
+
};
|
|
912
|
+
// Load the pixel with the provided ID
|
|
913
|
+
ttq.load(config.pixelId, config.testMode ? {
|
|
914
|
+
test_mode: true
|
|
915
|
+
} : undefined);
|
|
916
|
+
ttq.page();
|
|
917
|
+
// If script loads synchronously, mark as ready
|
|
918
|
+
if (window.ttq && typeof window.ttq === 'function') {
|
|
919
|
+
isPixelReady = true;
|
|
920
|
+
resolve();
|
|
921
|
+
}
|
|
922
|
+
})(window, document, 'ttq');
|
|
923
|
+
} catch (error) {
|
|
924
|
+
reject(error);
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
}),
|
|
928
|
+
track: (eventName, properties, context) => {
|
|
929
|
+
if (!isPixelReady || !window.ttq) return;
|
|
930
|
+
const ttEventName = getTikTokEventName(eventName, config.eventMapping);
|
|
931
|
+
// Handle PageView separately as it uses ttq.page()
|
|
932
|
+
if (ttEventName === 'PageView') {
|
|
933
|
+
window.ttq.page();
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
// Map parameters based on specific event requirements
|
|
937
|
+
const ttParams = mapTikTokEventParameters(ttEventName, properties);
|
|
938
|
+
if (ttParams && Object.keys(ttParams).length > 0) {
|
|
939
|
+
window.ttq.track(ttEventName, ttParams);
|
|
940
|
+
} else {
|
|
941
|
+
window.ttq.track(ttEventName);
|
|
942
|
+
}
|
|
943
|
+
},
|
|
944
|
+
identify: (userId, properties, context) => {
|
|
945
|
+
try {
|
|
946
|
+
if (typeof window !== 'undefined' && window.ttq) {
|
|
947
|
+
const identifyData = coerceTikTokIdentifyValues(Object.assign(Object.assign({}, properties || {}), userId ? {
|
|
948
|
+
external_id: userId
|
|
949
|
+
} : {}));
|
|
950
|
+
if (Object.keys(identifyData).length > 0) {
|
|
951
|
+
window.ttq.identify(identifyData);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
} catch (error) {
|
|
955
|
+
console.error('Error identifying user in TikTok Pixel:', error);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
function getTikTokEventName(eventName, eventMapping) {
|
|
961
|
+
// Convert default saasco Page View event by default
|
|
962
|
+
if (eventName === 'Page View') return 'PageView';
|
|
963
|
+
if (!eventMapping) return eventName;
|
|
964
|
+
return eventMapping[eventName] || eventName;
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Get identification values from properties for TikTok Pixel
|
|
968
|
+
*
|
|
969
|
+
* Advanced Matching Documentation:
|
|
970
|
+
* https://business-api.tiktok.com/portal/docs?rid=5ipocbxyw8v&id=1739585700402178
|
|
971
|
+
*
|
|
972
|
+
* Standard Events Documentation:
|
|
973
|
+
* https://business-api.tiktok.com/portal/docs?id=1771101186666498
|
|
974
|
+
*
|
|
975
|
+
* @param properties
|
|
976
|
+
* @returns
|
|
977
|
+
*/
|
|
978
|
+
function coerceTikTokIdentifyValues(properties) {
|
|
979
|
+
const coerce = [{
|
|
980
|
+
key: 'email',
|
|
981
|
+
coerceFrom: ['email', 'user_email', 'userEmail', 'email_address', 'emailAddress', 'e_mail', 'E_Mail', 'mail', 'Mail', 'contact_email', 'contactEmail', 'primary_email', 'primaryEmail'],
|
|
982
|
+
transform: value => {
|
|
983
|
+
if (typeof value !== 'string') return undefined;
|
|
984
|
+
const normalized = value.trim().toLowerCase();
|
|
985
|
+
// TikTok requires hashed email
|
|
986
|
+
return normalized ? jsSha256.sha256(normalized) : undefined;
|
|
987
|
+
}
|
|
988
|
+
}, {
|
|
989
|
+
key: 'phone_number',
|
|
990
|
+
coerceFrom: ['phone', 'phone_number', 'phoneNumber', 'mobile', 'mobile_number', 'mobileNumber', 'contact_number', 'contactNumber', 'tel', 'telephone'],
|
|
991
|
+
transform: value => {
|
|
992
|
+
if (typeof value !== 'string' && typeof value !== 'number') return undefined;
|
|
993
|
+
const phoneStr = String(value).replace(/\D/g, '');
|
|
994
|
+
// TikTok requires hashed phone number
|
|
995
|
+
return phoneStr ? jsSha256.sha256(phoneStr) : undefined;
|
|
996
|
+
}
|
|
997
|
+
}, {
|
|
998
|
+
key: 'external_id',
|
|
999
|
+
coerceFrom: ['external_id', 'externalId', 'user_id', 'userId', 'id', 'distinctId', 'distinct_id', 'customer_id', 'customerId', 'member_id', 'memberId'],
|
|
1000
|
+
transform: value => {
|
|
1001
|
+
if (value == null) return undefined;
|
|
1002
|
+
const stringValue = String(value);
|
|
1003
|
+
// TikTok requires hashed external_id
|
|
1004
|
+
return stringValue ? jsSha256.sha256(stringValue) : undefined;
|
|
1005
|
+
}
|
|
1006
|
+
}];
|
|
1007
|
+
const result = {};
|
|
1317
1008
|
for (const {
|
|
1318
1009
|
key,
|
|
1319
1010
|
coerceFrom,
|
|
@@ -1339,6 +1030,63 @@ function findFirstProperty(properties, keys) {
|
|
|
1339
1030
|
}
|
|
1340
1031
|
return null;
|
|
1341
1032
|
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Maps event properties to TikTok-specific parameters based on event type
|
|
1035
|
+
*
|
|
1036
|
+
* Parameter Documentation: https://ads.tiktok.com/help/article/about-parameters
|
|
1037
|
+
* Standard Events: https://business-api.tiktok.com/portal/docs?id=1771101186666498
|
|
1038
|
+
*/
|
|
1039
|
+
function mapTikTokEventParameters(eventName, properties) {
|
|
1040
|
+
if (!properties) return null;
|
|
1041
|
+
const params = {};
|
|
1042
|
+
// Helper to safely add parameters, skipping objects/null/undefined
|
|
1043
|
+
const addParam = (key, value) => {
|
|
1044
|
+
if (value != null && typeof value !== 'object') {
|
|
1045
|
+
params[key] = value;
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
switch (eventName) {
|
|
1049
|
+
case 'AddToCart':
|
|
1050
|
+
case 'Purchase':
|
|
1051
|
+
case 'ViewContent':
|
|
1052
|
+
addParam('content_type', properties['content_type']);
|
|
1053
|
+
addParam('content_ids', properties['content_ids']);
|
|
1054
|
+
addParam('quantity', properties['quantity']);
|
|
1055
|
+
addParam('description', properties['description']);
|
|
1056
|
+
addParam('currency', properties['currency']);
|
|
1057
|
+
addParam('value', properties['value']);
|
|
1058
|
+
addParam('content_name', properties['content_name']);
|
|
1059
|
+
addParam('content_category', properties['content_category']);
|
|
1060
|
+
break;
|
|
1061
|
+
case 'StartTrial':
|
|
1062
|
+
addParam('content_ids', properties['content_ids']);
|
|
1063
|
+
addParam('currency', properties['currency']);
|
|
1064
|
+
addParam('value', properties['value']);
|
|
1065
|
+
break;
|
|
1066
|
+
case 'Search':
|
|
1067
|
+
const searchString = properties['search_string'] || properties['query'] || properties['search_query'];
|
|
1068
|
+
addParam('search_string', searchString);
|
|
1069
|
+
break;
|
|
1070
|
+
case 'InitiateCheckout':
|
|
1071
|
+
case 'AddPaymentInfo':
|
|
1072
|
+
addParam('value', properties['value']);
|
|
1073
|
+
addParam('currency', properties['currency']);
|
|
1074
|
+
addParam('content_ids', properties['content_ids']);
|
|
1075
|
+
addParam('quantity', properties['quantity']);
|
|
1076
|
+
break;
|
|
1077
|
+
case 'CompleteRegistration':
|
|
1078
|
+
case 'Subscribe':
|
|
1079
|
+
addParam('value', properties['value']);
|
|
1080
|
+
addParam('currency', properties['currency']);
|
|
1081
|
+
break;
|
|
1082
|
+
default:
|
|
1083
|
+
// Pass through common parameters for any other events
|
|
1084
|
+
addParam('value', properties['value']);
|
|
1085
|
+
addParam('currency', properties['currency']);
|
|
1086
|
+
break;
|
|
1087
|
+
}
|
|
1088
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
1089
|
+
}
|
|
1342
1090
|
|
|
1343
1091
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1344
1092
|
class AnalyticsLogger {
|
|
@@ -1867,6 +1615,10 @@ class Saasco {
|
|
|
1867
1615
|
this.logger.log('Registering Facebook Pixel integration with ID:', integrationConfig.config.pixelId);
|
|
1868
1616
|
const fbIntegration = createFacebookPixelIntegration(integrationConfig.config);
|
|
1869
1617
|
yield this.integrationManager.registerIntegration(fbIntegration);
|
|
1618
|
+
} else if (integrationConfig.type === 'tiktok-pixel') {
|
|
1619
|
+
this.logger.log('Registering TikTok Pixel integration with ID:', integrationConfig.config.pixelId);
|
|
1620
|
+
const tiktokIntegration = createTikTokPixelIntegration(integrationConfig.config);
|
|
1621
|
+
yield this.integrationManager.registerIntegration(tiktokIntegration);
|
|
1870
1622
|
}
|
|
1871
1623
|
} catch (error) {
|
|
1872
1624
|
this.logger.log(`Failed to register ${integrationConfig.type} integration:`, error);
|
|
@@ -2132,6 +1884,8 @@ exports.Logger = Logger;
|
|
|
2132
1884
|
exports.Saasco = Saasco;
|
|
2133
1885
|
exports.browserContextSchema = browserContextSchema;
|
|
2134
1886
|
exports.createFacebookPixelIntegration = createFacebookPixelIntegration;
|
|
1887
|
+
exports.createTikTokPixelIntegration = createTikTokPixelIntegration;
|
|
2135
1888
|
exports.getBrowserContext = getBrowserContext;
|
|
2136
1889
|
exports.standardFacebookEvents = standardFacebookEvents;
|
|
1890
|
+
exports.standardTikTokEvents = standardTikTokEvents;
|
|
2137
1891
|
exports.timezones = timezones;
|