@jitsu/js 1.7.2 → 1.9.0-canary.548.20240108170646
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/.turbo/turbo-build.log +85 -105
- package/.turbo/turbo-clean.log +5 -5
- package/.turbo/turbo-test.log +1955 -1369
- package/__tests__/node/nodejs.test.ts +12 -8
- package/__tests__/playwright/cases/basic.html +1 -1
- package/__tests__/playwright/cases/url-bug.html +20 -0
- package/__tests__/playwright/integration.test.ts +60 -8
- package/dist/analytics-plugin.d.ts +6 -1
- package/dist/jitsu.cjs.js +204 -112
- package/dist/jitsu.d.ts +6 -0
- package/dist/jitsu.es.js +204 -112
- package/dist/version.d.ts +2 -1
- package/dist/web/p.js.txt +206 -114
- package/package.json +3 -3
- package/src/analytics-plugin.ts +138 -85
- package/src/browser.ts +3 -2
- package/src/index.ts +87 -17
- package/src/jitsu.ts +7 -0
- package/src/version.ts +4 -1
package/dist/web/p.js.txt
CHANGED
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
var __awaiter$
|
|
114
|
+
var __awaiter$5 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
115
115
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
116
116
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
117
117
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
const tagPlugin = {
|
|
124
124
|
id: "tag",
|
|
125
125
|
handle(config, payload) {
|
|
126
|
-
return __awaiter$
|
|
126
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
127
127
|
if (!applyFilters(payload, config)) {
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
@@ -192,7 +192,7 @@
|
|
|
192
192
|
return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
var __awaiter$
|
|
195
|
+
var __awaiter$4 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
196
196
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
197
197
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
198
198
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -204,7 +204,7 @@
|
|
|
204
204
|
const logrocketPlugin = {
|
|
205
205
|
id: "logrocket",
|
|
206
206
|
handle(config, payload) {
|
|
207
|
-
return __awaiter$
|
|
207
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
208
208
|
if (!applyFilters(payload, config)) {
|
|
209
209
|
return;
|
|
210
210
|
}
|
|
@@ -246,7 +246,7 @@
|
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
function initLogrocketIfNeeded(appId) {
|
|
249
|
-
return __awaiter$
|
|
249
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
250
250
|
if (getLogRocketState() !== "fresh") {
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
@@ -272,7 +272,7 @@
|
|
|
272
272
|
});
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
var __awaiter$
|
|
275
|
+
var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
276
276
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
277
277
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
278
278
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -286,7 +286,7 @@
|
|
|
286
286
|
id: "gtm",
|
|
287
287
|
handle(config, payload) {
|
|
288
288
|
var _a, _b;
|
|
289
|
-
return __awaiter$
|
|
289
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
290
290
|
if (!applyFilters(payload, config)) {
|
|
291
291
|
return;
|
|
292
292
|
}
|
|
@@ -323,7 +323,7 @@
|
|
|
323
323
|
window["__jitsuGtmState"] = s;
|
|
324
324
|
}
|
|
325
325
|
function initGtmIfNeeded(config, payload) {
|
|
326
|
-
return __awaiter$
|
|
326
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
327
327
|
if (getGtmState() !== "fresh") {
|
|
328
328
|
return;
|
|
329
329
|
}
|
|
@@ -357,7 +357,7 @@
|
|
|
357
357
|
});
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
-
var __awaiter$
|
|
360
|
+
var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
361
361
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
362
362
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
363
363
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -371,7 +371,7 @@
|
|
|
371
371
|
id: "ga4-tag",
|
|
372
372
|
handle(config, payload) {
|
|
373
373
|
var _a, _b;
|
|
374
|
-
return __awaiter$
|
|
374
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
375
375
|
if (!applyFilters(payload, config)) {
|
|
376
376
|
return;
|
|
377
377
|
}
|
|
@@ -419,7 +419,7 @@
|
|
|
419
419
|
window["__jitsuGa4State"] = s;
|
|
420
420
|
}
|
|
421
421
|
function initGa4IfNeeded(config, payload) {
|
|
422
|
-
return __awaiter$
|
|
422
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
423
423
|
if (getGa4State() !== "fresh") {
|
|
424
424
|
return;
|
|
425
425
|
}
|
|
@@ -485,8 +485,9 @@
|
|
|
485
485
|
[logrocketPlugin.id]: logrocketPlugin,
|
|
486
486
|
};
|
|
487
487
|
|
|
488
|
-
|
|
489
|
-
|
|
488
|
+
//import pkg from "../package.json";
|
|
489
|
+
const jitsuVersion = "0.0.0";
|
|
490
|
+
const jitsuLibraryName = "@jitsu/js";
|
|
490
491
|
|
|
491
492
|
const publicSuffixes = "ac,com.ac,edu.ac,gov.ac,net.ac,mil.ac,org.ac,ad,nom.ad,ae,co.ae,net.ae,org.ae,sch.ae,ac.ae,gov.ae,mil.ae,aero,af,gov.af,com.af,org.af,net.af,edu.af,ag,com.ag,org.ag,net.ag,co.ag,nom.ag,ai,off.ai,com.ai,net.ai,org.ai,al,com.al,edu.al,gov.al,mil.al,net.al,org.al,am,co.am,com.am,commune.am,net.am,org.am,ao,ed.ao,gv.ao,og.ao,co.ao,pb.ao,it.ao,aq,ar,bet.ar,com.ar,coop.ar,edu.ar,gob.ar,gov.ar,int.ar,mil.ar,musica.ar,mutual.ar,net.ar,org.ar,senasa.ar,tur.ar,arpa,e164.arpa,in-addr.arpa,ip6.arpa,iris.arpa,uri.arpa,urn.arpa,as,gov.as,asia,at,ac.at,co.at,gv.at,or.at,sth.ac.at,au,com.au,net.au,org.au,edu.au,gov.au,asn.au,id.au,act.au,nsw.au,nt.au,qld.au,sa.au,tas.au,vic.au,wa.au,aw,com.aw,ax,az,com.az,net.az,int.az,gov.az,org.az,edu.az,info.az,pp.az,mil.az,name.az,pro.az,biz.az,ba,com.ba,edu.ba,gov.ba,mil.ba,net.ba,org.ba,bb,biz.bb,co.bb,com.bb,edu.bb,gov.bb,info.bb,net.bb,org.bb,store.bb,tv.bb,bd,be,ac.be,bf,gov.bf,bg,a.bg,b.bg,c.bg,d.bg,e.bg,f.bg,g.bg,h.bg,i.bg,j.bg,k.bg,l.bg,m.bg,n.bg,o.bg,p.bg,q.bg,r.bg,s.bg,t.bg,u.bg,v.bg,w.bg,x.bg,y.bg,z.bg,0.bg,1.bg,2.bg,3.bg,4.bg,5.bg,6.bg,7.bg,8.bg,9.bg,bh,com.bh,edu.bh,net.bh,org.bh,gov.bh,bi,co.bi,com.bi,edu.bi,or.bi,org.bi,biz,bj,africa.bj,agro.bj,architectes.bj,assur.bj,avocats.bj,co.bj,com.bj,eco.bj,econo.bj,edu.bj,info.bj,loisirs.bj,money.bj,net.bj,org.bj,ote.bj,resto.bj,restaurant.bj,tourism.bj,univ.bj,bm,com.bm,edu.bm,gov.bm,net.bm,org.bm,bn,com.bn,edu.bn,gov.bn,net.bn,org.bn,bo,com.bo,edu.bo,gob.bo,int.bo,org.bo,net.bo,mil.bo,tv.bo,web.bo,br,9guacu.br,abc.br,adm.br,adv.br,agr.br,aju.br,am.br,anani.br,aparecida.br,app.br,arq.br,art.br,ato.br,b.br,barueri.br,belem.br,bhz.br,bib.br,bio.br,blog.br,bmd.br,boavista.br,bsb.br,campinagrande.br,campinas.br,caxias.br,cim.br,cng.br,cnt.br,com.br,contagem.br,coop.br,coz.br,cri.br,cuiaba.br,curitiba.br,def.br,des.br,det.br,dev.br,ecn.br,eco.br,edu.br,emp.br,enf.br,eng.br,esp.br,etc.br,eti.br,far.br,feira.br,flog.br,floripa.br,fm.br,fnd.br,fortal.br,fot.br,foz.br,fst.br,g12.br,geo.br,ggf.br,goiania.br,gov.br,gru.br,imb.br,ind.br,inf.br,jab.br,jampa.br,jdf.br,joinville.br,jor.br,jus.br,leg.br,lel.br,log.br,londrina.br,macapa.br,maceio.br,manaus.br,maringa.br,mat.br,med.br,mil.br,morena.br,mp.br,mus.br,natal.br,net.br,niteroi.br,nom.br,not.br,ntr.br,odo.br,ong.br,org.br,osasco.br,palmas.br,poa.br,ppg.br,pro.br,psc.br,psi.br,pvh.br,qsl.br,radio.br,rec.br,recife.br,rep.br,ribeirao.br,rio.br,riobranco.br,riopreto.br,salvador.br,sampa.br,santamaria.br,santoandre.br,saobernardo.br,saogonca.br,seg.br,sjc.br,slg.br,slz.br,sorocaba.br,srv.br,taxi.br,tc.br,tec.br,teo.br,the.br,tmp.br,trd.br,tur.br,tv.br,udi.br,vet.br,vix.br,vlog.br,wiki.br,zlg.br,bs,com.bs,net.bs,org.bs,edu.bs,gov.bs,bt,com.bt,edu.bt,gov.bt,net.bt,org.bt,bv,bw,co.bw,org.bw,by,gov.by,mil.by,com.by,of.by,bz,com.bz,net.bz,org.bz,edu.bz,gov.bz,ca,ab.ca,bc.ca,mb.ca,nb.ca,nf.ca,nl.ca,ns.ca,nt.ca,nu.ca,on.ca,pe.ca,qc.ca,sk.ca,yk.ca,gc.ca,cat,cc,cd,gov.cd,cf,cg,ch,ci,org.ci,or.ci,com.ci,co.ci,edu.ci,ed.ci,ac.ci,net.ci,go.ci,asso.ci,aéroport.ci,int.ci,presse.ci,md.ci,gouv.ci,ck,cl,co.cl,gob.cl,gov.cl,mil.cl,cm,co.cm,com.cm,gov.cm,net.cm,cn,ac.cn,com.cn,edu.cn,gov.cn,net.cn,org.cn,mil.cn,co,arts.co,com.co,edu.co,firm.co,gov.co,info.co,int.co,mil.co,net.co,nom.co,org.co,rec.co,web.co,com,coop,cr,ac.cr,co.cr,ed.cr,fi.cr,go.cr,or.cr,sa.cr,cu,com.cu,edu.cu,org.cu,net.cu,gov.cu,inf.cu,cv,com.cv,edu.cv,int.cv,nome.cv,org.cv,cw,com.cw,edu.cw,net.cw,org.cw,cx,gov.cx,cy,ac.cy,biz.cy,com.cy,ekloges.cy,gov.cy,ltd.cy,mil.cy,net.cy,org.cy,press.cy,pro.cy,tm.cy,cz,de,dj,dk,dm,com.dm,net.dm,org.dm,edu.dm,gov.dm,do,art.do,com.do,edu.do,gob.do,gov.do,mil.do,net.do,org.do,sld.do,web.do,dz,art.dz,asso.dz,com.dz,edu.dz,gov.dz,org.dz,net.dz,pol.dz,soc.dz,tm.dz,ec,com.ec,info.ec,net.ec,fin.ec,k12.ec,med.ec,pro.ec,org.ec,edu.ec,gov.ec,gob.ec,mil.ec,edu,ee,edu.ee,gov.ee,riik.ee,lib.ee,med.ee,com.ee,pri.ee,aip.ee,org.ee,fie.ee,eg,com.eg,edu.eg,eun.eg,gov.eg,mil.eg,name.eg,net.eg,org.eg,sci.eg,er,es,com.es,nom.es,org.es,gob.es,edu.es,et,com.et,gov.et,org.et,edu.et,biz.et,name.et,info.et,net.et,eu,fi,aland.fi,fj,ac.fj,biz.fj,com.fj,gov.fj,info.fj,mil.fj,name.fj,net.fj,org.fj,pro.fj,fk,com.fm,edu.fm,net.fm,org.fm,fm,fo,fr,asso.fr,com.fr,gouv.fr,nom.fr,prd.fr,tm.fr,aeroport.fr,avocat.fr,avoues.fr,cci.fr,chambagri.fr,chirurgiens-dentistes.fr,experts-comptables.fr,geometre-expert.fr,greta.fr,huissier-justice.fr,medecin.fr,notaires.fr,pharmacien.fr,port.fr,veterinaire.fr,ga,gb,edu.gd,gov.gd,gd,ge,com.ge,edu.ge,gov.ge,org.ge,mil.ge,net.ge,pvt.ge,gf,gg,co.gg,net.gg,org.gg,gh,com.gh,edu.gh,gov.gh,org.gh,mil.gh,gi,com.gi,ltd.gi,gov.gi,mod.gi,edu.gi,org.gi,gl,co.gl,com.gl,edu.gl,net.gl,org.gl,gm,gn,ac.gn,com.gn,edu.gn,gov.gn,org.gn,net.gn,gov,gp,com.gp,net.gp,mobi.gp,edu.gp,org.gp,asso.gp,gq,gr,com.gr,edu.gr,net.gr,org.gr,gov.gr,gs,gt,com.gt,edu.gt,gob.gt,ind.gt,mil.gt,net.gt,org.gt,gu,com.gu,edu.gu,gov.gu,guam.gu,info.gu,net.gu,org.gu,web.gu,gw,gy,co.gy,com.gy,edu.gy,gov.gy,net.gy,org.gy,hk,com.hk,edu.hk,gov.hk,idv.hk,net.hk,org.hk,hm,hn,com.hn,edu.hn,org.hn,net.hn,mil.hn,gob.hn,hr,iz.hr,from.hr,name.hr,com.hr,ht,com.ht,shop.ht,firm.ht,info.ht,adult.ht,net.ht,pro.ht,org.ht,med.ht,art.ht,coop.ht,pol.ht,asso.ht,edu.ht,rel.ht,gouv.ht,perso.ht,hu,co.hu,info.hu,org.hu,priv.hu,sport.hu,tm.hu,2000.hu,agrar.hu,bolt.hu,casino.hu,city.hu,erotica.hu,erotika.hu,film.hu,forum.hu,games.hu,hotel.hu,ingatlan.hu,jogasz.hu,konyvelo.hu,lakas.hu,media.hu,news.hu,reklam.hu,sex.hu,shop.hu,suli.hu,szex.hu,tozsde.hu,utazas.hu,video.hu,id,ac.id,biz.id,co.id,desa.id,go.id,mil.id,my.id,net.id,or.id,ponpes.id,sch.id,web.id,ie,gov.ie,il,ac.il,co.il,gov.il,idf.il,k12.il,muni.il,net.il,org.il,im,ac.im,co.im,com.im,ltd.co.im,net.im,org.im,plc.co.im,tt.im,tv.im,in,5g.in,6g.in,ac.in,ai.in,am.in,bihar.in,biz.in,business.in,ca.in,cn.in,co.in,com.in,coop.in,cs.in,delhi.in,dr.in,edu.in,er.in,firm.in,gen.in,gov.in,gujarat.in,ind.in,info.in,int.in,internet.in,io.in,me.in,mil.in,net.in,nic.in,org.in,pg.in,post.in,pro.in,res.in,travel.in,tv.in,uk.in,up.in,us.in,info,int,eu.int,io,com.io,iq,gov.iq,edu.iq,mil.iq,com.iq,org.iq,net.iq,ir,ac.ir,co.ir,gov.ir,id.ir,net.ir,org.ir,sch.ir,is,net.is,com.is,edu.is,gov.is,org.is,int.is,it,gov.it,edu.it,je,co.je,net.je,org.je,jm,jo,com.jo,org.jo,net.jo,edu.jo,sch.jo,gov.jo,mil.jo,name.jo,jobs,jp,ac.jp,ad.jp,co.jp,ed.jp,go.jp,gr.jp,lg.jp,ne.jp,or.jp,ke,ac.ke,co.ke,go.ke,info.ke,me.ke,mobi.ke,ne.ke,or.ke,sc.ke,kg,org.kg,net.kg,com.kg,edu.kg,gov.kg,mil.kg,kh,ki,edu.ki,biz.ki,net.ki,org.ki,gov.ki,info.ki,com.ki,km,org.km,nom.km,gov.km,prd.km,tm.km,edu.km,mil.km,ass.km,com.km,kn,net.kn,org.kn,edu.kn,gov.kn,kp,com.kp,edu.kp,gov.kp,org.kp,rep.kp,tra.kp,kr,ac.kr,co.kr,es.kr,go.kr,hs.kr,kg.kr,mil.kr,ms.kr,ne.kr,or.kr,pe.kr,re.kr,sc.kr,kw,com.kw,edu.kw,emb.kw,gov.kw,ind.kw,net.kw,org.kw,ky,com.ky,edu.ky,net.ky,org.ky,kz,org.kz,edu.kz,net.kz,gov.kz,mil.kz,com.kz,la,int.la,net.la,info.la,edu.la,gov.la,per.la,com.la,org.la,lb,com.lb,edu.lb,gov.lb,net.lb,org.lb,lc,com.lc,net.lc,co.lc,org.lc,edu.lc,gov.lc,li,lk,gov.lk,sch.lk,net.lk,int.lk,com.lk,org.lk,edu.lk,ngo.lk,soc.lk,web.lk,ltd.lk,assn.lk,grp.lk,hotel.lk,ac.lk,lr,com.lr,edu.lr,gov.lr,org.lr,net.lr,ls,ac.ls,biz.ls,co.ls,edu.ls,gov.ls,info.ls,net.ls,org.ls,sc.ls,lt,gov.lt,lu,lv,com.lv,edu.lv,gov.lv,org.lv,mil.lv,id.lv,net.lv,asn.lv,conf.lv,ly,com.ly,net.ly,gov.ly,plc.ly,edu.ly,sch.ly,med.ly,org.ly,id.ly,ma,co.ma,net.ma,gov.ma,org.ma,ac.ma,press.ma,mc,tm.mc,asso.mc,md,me,co.me,net.me,org.me,edu.me,ac.me,gov.me,its.me,priv.me,mg,org.mg,nom.mg,gov.mg,prd.mg,tm.mg,edu.mg,mil.mg,com.mg,co.mg,mh,mil,mk,com.mk,org.mk,net.mk,edu.mk,gov.mk,inf.mk,name.mk,ml,com.ml,edu.ml,gouv.ml,gov.ml,net.ml,org.ml,presse.ml,mm,mn,gov.mn,edu.mn,org.mn,mo,com.mo,net.mo,org.mo,edu.mo,gov.mo,mobi,mp,mq,mr,gov.mr,ms,com.ms,edu.ms,gov.ms,net.ms,org.ms,mt,com.mt,edu.mt,net.mt,org.mt,mu,com.mu,net.mu,org.mu,gov.mu,ac.mu,co.mu,or.mu,museum,mv,aero.mv,biz.mv,com.mv,coop.mv,edu.mv,gov.mv,info.mv,int.mv,mil.mv,museum.mv,name.mv,net.mv,org.mv,pro.mv,mw,ac.mw,biz.mw,co.mw,com.mw,coop.mw,edu.mw,gov.mw,int.mw,museum.mw,net.mw,org.mw,mx,com.mx,org.mx,gob.mx,edu.mx,net.mx,my,biz.my,com.my,edu.my,gov.my,mil.my,name.my,net.my,org.my,mz,ac.mz,adv.mz,co.mz,edu.mz,gov.mz,mil.mz,net.mz,org.mz,na,info.na,pro.na,name.na,school.na,or.na,dr.na,us.na,mx.na,ca.na,in.na,cc.na,tv.na,ws.na,mobi.na,co.na,com.na,org.na,name,nc,asso.nc,nom.nc,ne,net,nf,com.nf,net.nf,per.nf,rec.nf,web.nf,arts.nf,firm.nf,info.nf,other.nf,store.nf,ng,com.ng,edu.ng,gov.ng,i.ng,mil.ng,mobi.ng,name.ng,net.ng,org.ng,sch.ng,ni,ac.ni,biz.ni,co.ni,com.ni,edu.ni,gob.ni,in.ni,info.ni,int.ni,mil.ni,net.ni,nom.ni,org.ni,web.ni,nl,no,fhs.no,vgs.no,fylkesbibl.no,folkebibl.no,museum.no,idrett.no,priv.no,mil.no,stat.no,dep.no,kommune.no,herad.no,np,nr,biz.nr,info.nr,gov.nr,edu.nr,org.nr,net.nr,com.nr,nu,nz,ac.nz,co.nz,cri.nz,geek.nz,gen.nz,govt.nz,health.nz,iwi.nz,kiwi.nz,maori.nz,mil.nz,māori.nz,net.nz,org.nz,parliament.nz,school.nz,om,co.om,com.om,edu.om,gov.om,med.om,museum.om,net.om,org.om,pro.om,onion,org,pa,ac.pa,gob.pa,com.pa,org.pa,sld.pa,edu.pa,net.pa,ing.pa,abo.pa,med.pa,nom.pa,pe,edu.pe,gob.pe,nom.pe,mil.pe,org.pe,com.pe,net.pe,pf,com.pf,org.pf,edu.pf,pg,ph,com.ph,net.ph,org.ph,gov.ph,edu.ph,ngo.ph,mil.ph,i.ph,pk,com.pk,net.pk,edu.pk,org.pk,fam.pk,biz.pk,web.pk,gov.pk,gob.pk,gok.pk,gon.pk,gop.pk,gos.pk,info.pk,pl,com.pl,net.pl,org.pl,aid.pl,agro.pl,atm.pl,auto.pl,biz.pl,edu.pl,gmina.pl,gsm.pl,info.pl,mail.pl,miasta.pl,media.pl,mil.pl,nieruchomosci.pl,nom.pl,pc.pl,powiat.pl,priv.pl,realestate.pl,rel.pl,sex.pl,shop.pl,sklep.pl,sos.pl,szkola.pl,targi.pl,tm.pl,tourism.pl,travel.pl,turystyka.pl,pm,pn,gov.pn,co.pn,org.pn,edu.pn,net.pn,post,pr,com.pr,net.pr,org.pr,gov.pr,edu.pr,isla.pr,pro.pr,biz.pr,info.pr,name.pr,est.pr,prof.pr,ac.pr,pro,aaa.pro,aca.pro,acct.pro,avocat.pro,bar.pro,cpa.pro,eng.pro,jur.pro,law.pro,med.pro,recht.pro,ps,edu.ps,gov.ps,sec.ps,plo.ps,com.ps,org.ps,net.ps,pt,net.pt,gov.pt,org.pt,edu.pt,int.pt,publ.pt,com.pt,nome.pt,pw,co.pw,ne.pw,or.pw,ed.pw,go.pw,belau.pw,py,com.py,coop.py,edu.py,gov.py,mil.py,net.py,org.py,qa,com.qa,edu.qa,gov.qa,mil.qa,name.qa,net.qa,org.qa,sch.qa,re,asso.re,com.re,nom.re,ro,arts.ro,com.ro,firm.ro,info.ro,nom.ro,nt.ro,org.ro,rec.ro,store.ro,tm.ro,www.ro,rs,ac.rs,co.rs,edu.rs,gov.rs,in.rs,org.rs,ru,rw,ac.rw,co.rw,coop.rw,gov.rw,mil.rw,net.rw,org.rw,sa,com.sa,net.sa,org.sa,gov.sa,med.sa,pub.sa,edu.sa,sch.sa,sb,com.sb,edu.sb,gov.sb,net.sb,org.sb,sc,com.sc,gov.sc,net.sc,org.sc,edu.sc,sd,com.sd,net.sd,org.sd,edu.sd,med.sd,tv.sd,gov.sd,info.sd,se,a.se,ac.se,b.se,bd.se,brand.se,c.se,d.se,e.se,f.se,fh.se,fhsk.se,fhv.se,g.se,h.se,i.se,k.se,komforb.se,kommunalforbund.se,komvux.se,l.se,lanbib.se,m.se,n.se,naturbruksgymn.se,o.se,org.se,p.se,parti.se,pp.se,press.se,r.se,s.se,t.se,tm.se,u.se,w.se,x.se,y.se,z.se,sg,com.sg,net.sg,org.sg,gov.sg,edu.sg,per.sg,sh,com.sh,net.sh,gov.sh,org.sh,mil.sh,si,sj,sk,sl,com.sl,net.sl,edu.sl,gov.sl,org.sl,sm,sn,art.sn,com.sn,edu.sn,gouv.sn,org.sn,perso.sn,univ.sn,so,com.so,edu.so,gov.so,me.so,net.so,org.so,sr,ss,biz.ss,com.ss,edu.ss,gov.ss,me.ss,net.ss,org.ss,sch.ss,st,co.st,com.st,consulado.st,edu.st,embaixada.st,mil.st,net.st,org.st,principe.st,saotome.st,store.st,su,sv,com.sv,edu.sv,gob.sv,org.sv,red.sv,sx,gov.sx,sy,edu.sy,gov.sy,net.sy,mil.sy,com.sy,org.sy,sz,co.sz,ac.sz,org.sz,tc,td,tel,tf,tg,th,ac.th,co.th,go.th,in.th,mi.th,net.th,or.th,tj,ac.tj,biz.tj,co.tj,com.tj,edu.tj,go.tj,gov.tj,int.tj,mil.tj,name.tj,net.tj,nic.tj,org.tj,test.tj,web.tj,tk,tl,gov.tl,tm,com.tm,co.tm,org.tm,net.tm,nom.tm,gov.tm,mil.tm,edu.tm,tn,com.tn,ens.tn,fin.tn,gov.tn,ind.tn,info.tn,intl.tn,mincom.tn,nat.tn,net.tn,org.tn,perso.tn,tourism.tn,to,com.to,gov.to,net.to,org.to,edu.to,mil.to,tr,av.tr,bbs.tr,bel.tr,biz.tr,com.tr,dr.tr,edu.tr,gen.tr,gov.tr,info.tr,mil.tr,k12.tr,kep.tr,name.tr,net.tr,org.tr,pol.tr,tel.tr,tsk.tr,tv.tr,web.tr,nc.tr,tt,co.tt,com.tt,org.tt,net.tt,biz.tt,info.tt,pro.tt,int.tt,coop.tt,jobs.tt,mobi.tt,travel.tt,museum.tt,aero.tt,name.tt,gov.tt,edu.tt,tv,tw,edu.tw,gov.tw,mil.tw,com.tw,net.tw,org.tw,idv.tw,game.tw,ebiz.tw,club.tw,tz,ac.tz,co.tz,go.tz,hotel.tz,info.tz,me.tz,mil.tz,mobi.tz,ne.tz,or.tz,sc.tz,tv.tz,ua,com.ua,edu.ua,gov.ua,in.ua,net.ua,org.ua,ug,co.ug,or.ug,ac.ug,sc.ug,go.ug,ne.ug,com.ug,org.ug,uk,ac.uk,co.uk,gov.uk,ltd.uk,me.uk,net.uk,nhs.uk,org.uk,plc.uk,police.uk,us,dni.us,fed.us,isa.us,kids.us,nsn.us,ak.us,al.us,ar.us,as.us,az.us,ca.us,co.us,ct.us,dc.us,de.us,fl.us,ga.us,gu.us,hi.us,ia.us,id.us,il.us,in.us,ks.us,ky.us,la.us,ma.us,md.us,me.us,mi.us,mn.us,mo.us,ms.us,mt.us,nc.us,nd.us,ne.us,nh.us,nj.us,nm.us,nv.us,ny.us,oh.us,ok.us,or.us,pa.us,pr.us,ri.us,sc.us,sd.us,tn.us,tx.us,ut.us,vi.us,vt.us,va.us,wa.us,wi.us,wv.us,wy.us,uy,com.uy,edu.uy,gub.uy,mil.uy,net.uy,org.uy,uz,co.uz,com.uz,net.uz,org.uz,va,vc,com.vc,net.vc,org.vc,gov.vc,mil.vc,edu.vc,ve,arts.ve,bib.ve,co.ve,com.ve,e12.ve,edu.ve,firm.ve,gob.ve,gov.ve,info.ve,int.ve,mil.ve,net.ve,nom.ve,org.ve,rar.ve,rec.ve,store.ve,tec.ve,web.ve,vg,vi,co.vi,com.vi,k12.vi,net.vi,org.vi,vn,ac.vn,ai.vn,biz.vn,com.vn,edu.vn,gov.vn,health.vn,id.vn,info.vn,int.vn,io.vn,name.vn,net.vn,org.vn,pro.vn,vu,com.vu,edu.vu,net.vu,org.vu,wf,ws,com.ws,net.ws,org.ws,gov.ws,edu.ws,yt,ye,com.ye,edu.ye,gov.ye,net.ye,mil.ye,org.ye,ac.za,agric.za,alt.za,co.za,edu.za,gov.za,grondar.za,law.za,mil.za,net.za,ngo.za,nic.za,nis.za,nom.za,org.za,school.za,tm.za,web.za,zm,ac.zm,biz.zm,co.zm,com.zm,edu.zm,gov.zm,info.zm,mil.zm,net.zm,org.zm,sch.zm,zw,ac.zw,co.zw,gov.zw,mil.zw,org.zw".split(",");
|
|
492
493
|
//convert to Map
|
|
@@ -513,7 +514,7 @@
|
|
|
513
514
|
}
|
|
514
515
|
|
|
515
516
|
/* global analytics */
|
|
516
|
-
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
517
|
+
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
517
518
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
518
519
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
519
520
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -532,6 +533,7 @@
|
|
|
532
533
|
echoEvents: false,
|
|
533
534
|
cookieDomain: undefined,
|
|
534
535
|
runtime: undefined,
|
|
536
|
+
s2s: undefined,
|
|
535
537
|
};
|
|
536
538
|
const parseQuery = (qs) => {
|
|
537
539
|
if (!qs) {
|
|
@@ -564,11 +566,21 @@
|
|
|
564
566
|
}
|
|
565
567
|
}
|
|
566
568
|
function restoreTraits(storage) {
|
|
567
|
-
|
|
569
|
+
let val = storage.getItem("__user_traits");
|
|
568
570
|
if (typeof val === "string") {
|
|
569
|
-
|
|
571
|
+
val = safeCall(() => JSON.parse(val), {});
|
|
572
|
+
}
|
|
573
|
+
if (typeof val !== "object" || val === null) {
|
|
574
|
+
val = {};
|
|
570
575
|
}
|
|
571
|
-
|
|
576
|
+
let groupVal = storage.getItem("__group_traits");
|
|
577
|
+
if (typeof groupVal === "string") {
|
|
578
|
+
groupVal = safeCall(() => JSON.parse(groupVal), {});
|
|
579
|
+
}
|
|
580
|
+
if (typeof groupVal !== "object" || groupVal === null) {
|
|
581
|
+
groupVal = {};
|
|
582
|
+
}
|
|
583
|
+
return Object.assign(Object.assign({}, (groupVal || {})), (val || {}));
|
|
572
584
|
}
|
|
573
585
|
function getCookie(name) {
|
|
574
586
|
const value = `; ${document.cookie}`;
|
|
@@ -770,20 +782,34 @@
|
|
|
770
782
|
function isInBrowser() {
|
|
771
783
|
return typeof document !== "undefined" && typeof window !== "undefined";
|
|
772
784
|
}
|
|
773
|
-
|
|
785
|
+
/**
|
|
786
|
+
* Fixes a weird bug in analytics URL where path
|
|
787
|
+
* of https://test.com becomes //test.com
|
|
788
|
+
*/
|
|
789
|
+
function fixPath(path) {
|
|
790
|
+
if (path.indexOf("//") === 0 && path.lastIndexOf("/") === 1) {
|
|
791
|
+
return "/";
|
|
792
|
+
}
|
|
793
|
+
return path;
|
|
794
|
+
}
|
|
795
|
+
function adjustPayload(payload, config, storage, s2s) {
|
|
774
796
|
var _a, _b;
|
|
775
797
|
const runtime = config.runtime || (isInBrowser() ? windowRuntime(config) : emptyRuntime(config));
|
|
776
798
|
const url = runtime.pageUrl();
|
|
777
799
|
const parsedUrl = safeCall(() => new URL(url), undefined);
|
|
778
800
|
const query = parsedUrl ? parseQuery(parsedUrl.search) : {};
|
|
779
801
|
const properties = payload.properties || {};
|
|
802
|
+
if (properties.path) {
|
|
803
|
+
properties.path = fixPath(properties.path);
|
|
804
|
+
}
|
|
780
805
|
const customContext = ((_a = payload.properties) === null || _a === void 0 ? void 0 : _a.context) || {};
|
|
781
806
|
(_b = payload.properties) === null || _b === void 0 ? true : delete _b.context;
|
|
782
807
|
const referrer = runtime.referrer();
|
|
783
808
|
const context = {
|
|
784
809
|
library: {
|
|
785
|
-
name:
|
|
786
|
-
version:
|
|
810
|
+
name: jitsuLibraryName,
|
|
811
|
+
version: jitsuVersion,
|
|
812
|
+
env: s2s ? "node" : "browser",
|
|
787
813
|
},
|
|
788
814
|
userAgent: runtime.userAgent(),
|
|
789
815
|
locale: runtime.language(),
|
|
@@ -802,13 +828,13 @@
|
|
|
802
828
|
clientIds: Object.assign({ fbc: runtime.getCookie("_fbc"), fbp: runtime.getCookie("_fbp") }, getGa4Ids(runtime)),
|
|
803
829
|
campaign: parseUtms(query),
|
|
804
830
|
};
|
|
805
|
-
const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: maskWriteKey(config.writeKey), context: deepMerge(context, customContext) });
|
|
831
|
+
const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: maskWriteKey(config.writeKey), groupId: storage.getItem("__group_id"), context: deepMerge(context, customContext) });
|
|
806
832
|
delete withContext.meta;
|
|
807
833
|
delete withContext.options;
|
|
808
834
|
return withContext;
|
|
809
835
|
}
|
|
810
836
|
function processDestinations(destinations, method, originalEvent, debug, analyticsInstance) {
|
|
811
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
837
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
812
838
|
const promises = [];
|
|
813
839
|
for (const destination of destinations) {
|
|
814
840
|
let newEvents = [originalEvent];
|
|
@@ -900,86 +926,69 @@
|
|
|
900
926
|
return writeKey;
|
|
901
927
|
}
|
|
902
928
|
function send(method, payload, jitsuConfig, instance, store) {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
const url = `${jitsuConfig.host}/api/s/${method}`;
|
|
908
|
-
const fetch = jitsuConfig.fetch || globalThis.fetch;
|
|
909
|
-
if (!fetch) {
|
|
910
|
-
throw new Error("Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope");
|
|
911
|
-
}
|
|
912
|
-
const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
|
|
913
|
-
// if (jitsuConfig.debug) {
|
|
914
|
-
// console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
|
|
915
|
-
// }
|
|
916
|
-
const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
|
|
917
|
-
const authHeader = jitsuConfig.writeKey ? { "X-Write-Key": jitsuConfig.writeKey } : {};
|
|
918
|
-
return fetch(url, {
|
|
919
|
-
method: "POST",
|
|
920
|
-
headers: Object.assign(Object.assign({ "Content-Type": "application/json" }, authHeader), debugHeader),
|
|
921
|
-
body: JSON.stringify(adjustedPayload),
|
|
922
|
-
})
|
|
923
|
-
.then(res => {
|
|
924
|
-
if (jitsuConfig.debug) {
|
|
925
|
-
console.log(`[JITSU] ${url} replied ${res.status}. Original payload: `, JSON.stringify(adjustedPayload, null, 2));
|
|
929
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
930
|
+
if (jitsuConfig.echoEvents) {
|
|
931
|
+
console.log(`[JITSU DEBUG] sending '${method}' event:`, payload);
|
|
932
|
+
return;
|
|
926
933
|
}
|
|
927
|
-
|
|
928
|
-
|
|
934
|
+
const s2s = jitsuConfig.s2s === undefined ? !isInBrowser() : jitsuConfig.s2s;
|
|
935
|
+
const url = s2s ? `${jitsuConfig.host}/api/s/s2s/${method}` : `${jitsuConfig.host}/api/s/${method}`;
|
|
936
|
+
const fetch = jitsuConfig.fetch || globalThis.fetch;
|
|
937
|
+
if (!fetch) {
|
|
938
|
+
throw new Error("Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope");
|
|
929
939
|
}
|
|
930
|
-
|
|
931
|
-
|
|
940
|
+
const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
|
|
941
|
+
// if (jitsuConfig.debug) {
|
|
942
|
+
// console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
|
|
943
|
+
// }
|
|
944
|
+
const adjustedPayload = adjustPayload(payload, jitsuConfig, store, s2s);
|
|
945
|
+
const authHeader = jitsuConfig.writeKey ? { "X-Write-Key": jitsuConfig.writeKey } : {};
|
|
946
|
+
let fetchResult;
|
|
947
|
+
try {
|
|
948
|
+
fetchResult = yield fetch(url, {
|
|
949
|
+
method: "POST",
|
|
950
|
+
headers: Object.assign(Object.assign({ "Content-Type": "application/json" }, authHeader), debugHeader),
|
|
951
|
+
body: JSON.stringify(adjustedPayload),
|
|
952
|
+
});
|
|
932
953
|
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
954
|
+
catch (e) {
|
|
955
|
+
throw new Error(`Calling ${url} failed: ${e.message}`);
|
|
956
|
+
}
|
|
957
|
+
let responseText;
|
|
936
958
|
try {
|
|
937
|
-
|
|
959
|
+
responseText = yield fetchResult.text();
|
|
960
|
+
}
|
|
961
|
+
catch (e) {
|
|
962
|
+
console.warn(`Can't read response text from ${url} (status - ${fetchResult.status} ${fetchResult.statusText}): ${e === null || e === void 0 ? void 0 : e.message}`);
|
|
963
|
+
}
|
|
964
|
+
if (jitsuConfig.debug) {
|
|
965
|
+
console.log(`[JITSU DEBUG] ${url} replied ${fetchResult.status}: ${responseText}. Original payload:\n${JSON.stringify(adjustedPayload, null, 2)}`);
|
|
966
|
+
}
|
|
967
|
+
if (!fetchResult.ok) {
|
|
968
|
+
throw new Error(`Jitsu ${url} replied ${fetchResult.status} - ${fetchResult.statusText}: ${responseText}`);
|
|
969
|
+
}
|
|
970
|
+
let responseJson;
|
|
971
|
+
try {
|
|
972
|
+
responseJson = JSON.parse(responseText);
|
|
938
973
|
}
|
|
939
974
|
catch (e) {
|
|
940
975
|
return Promise.reject(`Can't parse JSON: ${responseText}: ${e === null || e === void 0 ? void 0 : e.message}`);
|
|
941
976
|
}
|
|
942
|
-
if (
|
|
943
|
-
if (jitsuConfig.
|
|
944
|
-
console.
|
|
977
|
+
if (responseJson.destinations && responseJson.destinations.length > 0) {
|
|
978
|
+
if (jitsuConfig.s2s) {
|
|
979
|
+
console.warn(`[JITSU] ${payload.type} responded with list of ${responseJson.destinations.length} destinations. However, this code is running in server-to-server mode, so destinations will be ignored`, jitsuConfig.debug ? JSON.stringify(responseJson.destinations, null, 2) : undefined);
|
|
980
|
+
}
|
|
981
|
+
else {
|
|
982
|
+
if (jitsuConfig.debug) {
|
|
983
|
+
console.log(`[JITSU] Processing device destinations: `, JSON.stringify(responseJson.destinations, null, 2));
|
|
984
|
+
}
|
|
985
|
+
return processDestinations(responseJson.destinations, method, adjustedPayload, !!jitsuConfig.debug, instance);
|
|
945
986
|
}
|
|
946
|
-
return processDestinations(response.destinations, method, adjustedPayload, !!jitsuConfig.debug, instance);
|
|
947
|
-
}
|
|
948
|
-
})
|
|
949
|
-
.catch(err => {
|
|
950
|
-
if (jitsuConfig.debug) {
|
|
951
|
-
console.error(`Jitsu ${url} failed: `, err);
|
|
952
987
|
}
|
|
988
|
+
return adjustedPayload;
|
|
953
989
|
});
|
|
954
990
|
}
|
|
955
991
|
const jitsuAnalyticsPlugin = (pluginConfig = {}) => {
|
|
956
|
-
const storageCache = {};
|
|
957
|
-
// AnalyticsInstance's storage is async somewhere inside. So if we make 'page' call right after 'identify' call
|
|
958
|
-
// 'page' call will load traits from storage before 'identify' call had a change to save them.
|
|
959
|
-
// to avoid that we use in-memory cache for storage
|
|
960
|
-
const cachingStorageWrapper = (persistentStorage) => ({
|
|
961
|
-
setItem(key, val) {
|
|
962
|
-
if (pluginConfig.debug) {
|
|
963
|
-
console.log(`[JITSU DEBUG] Caching storage setItem: ${key}=${val}`);
|
|
964
|
-
}
|
|
965
|
-
storageCache[key] = val;
|
|
966
|
-
persistentStorage.setItem(key, val);
|
|
967
|
-
},
|
|
968
|
-
getItem(key) {
|
|
969
|
-
const value = storageCache[key] || persistentStorage.getItem(key);
|
|
970
|
-
if (pluginConfig.debug) {
|
|
971
|
-
console.log(`[JITSU DEBUG] Caching storage getItem: ${key}=${value}. Evicted from cache: ${!storageCache[key]}`);
|
|
972
|
-
}
|
|
973
|
-
return value;
|
|
974
|
-
},
|
|
975
|
-
removeItem(key) {
|
|
976
|
-
if (pluginConfig.debug) {
|
|
977
|
-
console.log(`[JITSU DEBUG] Caching storage removeItem: ${key}`);
|
|
978
|
-
}
|
|
979
|
-
delete storageCache[key];
|
|
980
|
-
persistentStorage.removeItem(key);
|
|
981
|
-
},
|
|
982
|
-
});
|
|
983
992
|
const instanceConfig = Object.assign(Object.assign({}, defaultConfig), pluginConfig);
|
|
984
993
|
return {
|
|
985
994
|
name: "jitsu",
|
|
@@ -996,30 +1005,46 @@
|
|
|
996
1005
|
},
|
|
997
1006
|
page: args => {
|
|
998
1007
|
const { payload, config, instance } = args;
|
|
999
|
-
return send("page", payload, config, instance,
|
|
1008
|
+
return send("page", payload, config, instance, pluginConfig.storageWrapper ? pluginConfig.storageWrapper(instance.storage) : instance.storage);
|
|
1000
1009
|
},
|
|
1001
1010
|
track: args => {
|
|
1002
1011
|
const { payload, config, instance } = args;
|
|
1003
|
-
return send("track", payload, config, instance,
|
|
1012
|
+
return send("track", payload, config, instance, pluginConfig.storageWrapper ? pluginConfig.storageWrapper(instance.storage) : instance.storage);
|
|
1004
1013
|
},
|
|
1005
1014
|
identify: args => {
|
|
1006
1015
|
const { payload, config, instance } = args;
|
|
1007
1016
|
// Store traits in cache to be able to use them in page and track events that run asynchronously with current identify.
|
|
1008
|
-
|
|
1009
|
-
|
|
1017
|
+
const storage = pluginConfig.storageWrapper ? pluginConfig.storageWrapper(instance.storage) : instance.storage;
|
|
1018
|
+
storage.setItem("__user_id", payload.userId);
|
|
1019
|
+
if (payload.traits && typeof payload.traits === "object") {
|
|
1020
|
+
storage.setItem("__user_traits", payload.traits);
|
|
1021
|
+
}
|
|
1022
|
+
return send("identify", payload, config, instance, storage);
|
|
1010
1023
|
},
|
|
1011
1024
|
reset: args => {
|
|
1012
1025
|
//clear storage cache
|
|
1013
|
-
|
|
1026
|
+
if (pluginConfig.storageWrapper) {
|
|
1027
|
+
pluginConfig.storageWrapper(args.instance.storage).reset();
|
|
1028
|
+
}
|
|
1014
1029
|
},
|
|
1015
1030
|
methods: {
|
|
1016
1031
|
//analytics doesn't support group as a base method, so we need to add it manually
|
|
1017
1032
|
group(groupId, traits, options, callback) {
|
|
1033
|
+
if (typeof groupId === "number") {
|
|
1034
|
+
//fix potential issues with group id being used incorrectly
|
|
1035
|
+
groupId = groupId + "";
|
|
1036
|
+
}
|
|
1018
1037
|
const analyticsInstance = this.instance;
|
|
1019
|
-
const cacheWrap =
|
|
1038
|
+
const cacheWrap = pluginConfig.storageWrapper
|
|
1039
|
+
? pluginConfig.storageWrapper(analyticsInstance.storage)
|
|
1040
|
+
: analyticsInstance.storage;
|
|
1020
1041
|
const user = analyticsInstance.user();
|
|
1021
1042
|
const userId = (options === null || options === void 0 ? void 0 : options.userId) || (user === null || user === void 0 ? void 0 : user.userId);
|
|
1022
1043
|
const anonymousId = (options === null || options === void 0 ? void 0 : options.anonymousId) || (user === null || user === void 0 ? void 0 : user.anonymousId) || cacheWrap.getItem("__anon_id");
|
|
1044
|
+
cacheWrap.setItem("__group_id", groupId);
|
|
1045
|
+
if (traits && typeof traits === "object") {
|
|
1046
|
+
cacheWrap.setItem("__group_traits", traits);
|
|
1047
|
+
}
|
|
1023
1048
|
return send("group", Object.assign(Object.assign({ type: "group", groupId, traits }, (anonymousId ? { anonymousId } : {})), (userId ? { userId } : {})), instanceConfig, analyticsInstance, cacheWrap);
|
|
1024
1049
|
},
|
|
1025
1050
|
},
|
|
@@ -1047,6 +1072,15 @@
|
|
|
1047
1072
|
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
1048
1073
|
}
|
|
1049
1074
|
|
|
1075
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1076
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1077
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1078
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1079
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1080
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1081
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1082
|
+
});
|
|
1083
|
+
};
|
|
1050
1084
|
function parse(input) {
|
|
1051
1085
|
let value = input;
|
|
1052
1086
|
if ((input === null || input === void 0 ? void 0 : input.indexOf("%7B%22")) === 0) {
|
|
@@ -1072,22 +1106,75 @@
|
|
|
1072
1106
|
}
|
|
1073
1107
|
function createUnderlyingAnalyticsInstance(opts, rt, plugins = []) {
|
|
1074
1108
|
const storage = rt.store();
|
|
1109
|
+
const storageCache = {};
|
|
1110
|
+
// AnalyticsInstance's storage is async somewhere inside. So if we make 'page' call right after 'identify' call
|
|
1111
|
+
// 'page' call will load traits from storage before 'identify' call had a change to save them.
|
|
1112
|
+
// to avoid that we use in-memory cache for storage
|
|
1113
|
+
const cachingStorageWrapper = (persistentStorage) => ({
|
|
1114
|
+
setItem(key, val) {
|
|
1115
|
+
if (opts.debug) {
|
|
1116
|
+
console.log(`[JITSU DEBUG] Caching storage setItem: ${key}=${val}`);
|
|
1117
|
+
}
|
|
1118
|
+
storageCache[key] = val;
|
|
1119
|
+
persistentStorage.setItem(key, val);
|
|
1120
|
+
},
|
|
1121
|
+
getItem(key) {
|
|
1122
|
+
const value = storageCache[key] || persistentStorage.getItem(key);
|
|
1123
|
+
if (opts.debug) {
|
|
1124
|
+
console.log(`[JITSU DEBUG] Caching storage getItem: ${key}=${value}. Evicted from cache: ${!storageCache[key]}`);
|
|
1125
|
+
}
|
|
1126
|
+
return value;
|
|
1127
|
+
},
|
|
1128
|
+
reset() {
|
|
1129
|
+
for (const key of [...Object.keys(storageCache)]) {
|
|
1130
|
+
storage.removeItem(key);
|
|
1131
|
+
delete storageCache[key];
|
|
1132
|
+
}
|
|
1133
|
+
},
|
|
1134
|
+
removeItem(key) {
|
|
1135
|
+
if (opts.debug) {
|
|
1136
|
+
console.log(`[JITSU DEBUG] Caching storage removeItem: ${key}`);
|
|
1137
|
+
}
|
|
1138
|
+
delete storageCache[key];
|
|
1139
|
+
persistentStorage.removeItem(key);
|
|
1140
|
+
},
|
|
1141
|
+
});
|
|
1075
1142
|
const analytics = analyticsLib({
|
|
1076
|
-
app: "test",
|
|
1077
1143
|
debug: !!opts.debug,
|
|
1078
1144
|
storage,
|
|
1079
|
-
plugins: [jitsuAnalyticsPlugin(opts), ...plugins],
|
|
1145
|
+
plugins: [jitsuAnalyticsPlugin(Object.assign(Object.assign({}, opts), { storageWrapper: cachingStorageWrapper })), ...plugins],
|
|
1080
1146
|
});
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1147
|
+
return Object.assign(Object.assign({}, analytics), { page: (...args) => {
|
|
1148
|
+
if (args.length === 2 && typeof args[0] === "string" && typeof args[1] === "object") {
|
|
1149
|
+
return analytics.page(Object.assign({ name: args[0] }, args[1]));
|
|
1150
|
+
}
|
|
1151
|
+
else {
|
|
1152
|
+
return analytics.page(...args);
|
|
1153
|
+
}
|
|
1154
|
+
}, identify: (...args) => {
|
|
1155
|
+
if (args[0] && typeof args[0] !== "object" && typeof args[0] !== "string") {
|
|
1156
|
+
//fix the quirk of analytics.js: if you pass number as first argument, it will be converted to string
|
|
1157
|
+
args[0] = args[0] + "";
|
|
1158
|
+
}
|
|
1159
|
+
//analytics.js sets userId and traits asynchronously, so if
|
|
1160
|
+
//we want them to be available immediately after identify call in subsequent page() calls,
|
|
1161
|
+
//we need to put them into storage manually
|
|
1162
|
+
const storage = analytics.storage;
|
|
1163
|
+
const storageWrapper = cachingStorageWrapper(storage);
|
|
1164
|
+
if (typeof args[0] === "string") {
|
|
1165
|
+
//first argument is user id
|
|
1166
|
+
storageWrapper.setItem("__user_id", args[0]);
|
|
1167
|
+
}
|
|
1168
|
+
else if (typeof args[0] === "object") {
|
|
1169
|
+
//first argument is traits
|
|
1170
|
+
storageWrapper.setItem("__user_traits", args[0]);
|
|
1171
|
+
}
|
|
1172
|
+
if (args.length === 2 && typeof args[1] === "object") {
|
|
1173
|
+
//first argument is user id, second is traits
|
|
1174
|
+
storageWrapper.setItem("__user_traits", args[1]);
|
|
1175
|
+
}
|
|
1176
|
+
return analytics.identify(...args);
|
|
1177
|
+
}, setAnonymousId: (id) => {
|
|
1091
1178
|
if (opts.debug) {
|
|
1092
1179
|
console.log("[JITSU DEBUG] Setting anonymous id to " + id);
|
|
1093
1180
|
//Workaround for analytics.js bug. Underlying setAnonymousId doesn't work set the id immediately,
|
|
@@ -1100,12 +1187,17 @@
|
|
|
1100
1187
|
analytics.setAnonymousId(id);
|
|
1101
1188
|
}
|
|
1102
1189
|
}, group(groupId, traits, options, callback) {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1191
|
+
const results = [];
|
|
1192
|
+
for (const plugin of Object.values(analytics.plugins)) {
|
|
1193
|
+
if (plugin["group"]) {
|
|
1194
|
+
results.push(yield plugin["group"](groupId, traits, options, callback));
|
|
1195
|
+
}
|
|
1106
1196
|
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1197
|
+
//It's incorrect at many levels. First, it's not a dispatched event. Second, we take a first result
|
|
1198
|
+
//However, since returned values are used for debugging purposes only, it's ok
|
|
1199
|
+
return results[0];
|
|
1200
|
+
});
|
|
1109
1201
|
} });
|
|
1110
1202
|
}
|
|
1111
1203
|
function jitsuAnalytics(opts) {
|
|
@@ -1188,7 +1280,7 @@
|
|
|
1188
1280
|
* New callback based queue, see below
|
|
1189
1281
|
*/
|
|
1190
1282
|
//make a copy of the queue
|
|
1191
|
-
const callbackQueue = [...
|
|
1283
|
+
const callbackQueue = window[JITSU_V2_ID + "Q"] && window[JITSU_V2_ID + "Q"].length ? [...window[JITSU_V2_ID + "Q"]] : [];
|
|
1192
1284
|
//replace push with a function that calls callback immediately
|
|
1193
1285
|
window[JITSU_V2_ID + "Q"] = {
|
|
1194
1286
|
push: (callback) => {
|
|
@@ -1201,7 +1293,7 @@
|
|
|
1201
1293
|
},
|
|
1202
1294
|
};
|
|
1203
1295
|
if (options.debug) {
|
|
1204
|
-
console.log(`Jitsu callback queue size: ${callbackQueue.length}`, callbackQueue);
|
|
1296
|
+
console.log(`[JITSU DEBUG] Jitsu callback queue size: ${callbackQueue.length}`, callbackQueue);
|
|
1205
1297
|
}
|
|
1206
1298
|
callbackQueue.forEach((callback) => {
|
|
1207
1299
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jitsu/js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0-canary.548.20240108170646",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Jitsu Dev Team <dev@jitsu.com>",
|
|
6
6
|
"main": "dist/jitsu.cjs.js",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"raw-loader": "^4.0.2",
|
|
34
34
|
"rollup": "^3.2.5",
|
|
35
35
|
"ts-jest": "29.0.5",
|
|
36
|
-
"typescript": "^
|
|
37
|
-
"@jitsu/protocols": "1.
|
|
36
|
+
"typescript": "^5.3.3",
|
|
37
|
+
"@jitsu/protocols": "1.9.0-canary.548.20240108170646"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"analytics": "0.8.9"
|