ec4w_validator 0.0.10011111 → 0.0.1001111221
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/dist/index.js +205 -0
- package/dist/index.umd.cjs +1 -0
- package/package.json +4 -1
- package/.idx/dev.nix +0 -34
- package/.vscode/_keybinds.txt +0 -168
- package/.vscode/launch.json +0 -32
- package/eslint.config.js +0 -34
- package/index.html +0 -16
- package/jsconfig.json +0 -25
- package/src/ec4w_tester copy.js +0 -318
- package/src/ec4w_validator.js +0 -394
- package/src/ec4w_validator.test.js +0 -151
- package/src/main.js +0 -1
- package/vite.config.ts +0 -21
- package/vitest.config.ts +0 -12
- /package/{public → dist}/vite.svg +0 -0
package/src/ec4w_validator.js
DELETED
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
export class EC4W_Validator {
|
|
2
|
-
/** @type {SentRequest[]} */
|
|
3
|
-
#requestList = [];
|
|
4
|
-
|
|
5
|
-
/** @param {SentRequest[]} requestList */
|
|
6
|
-
constructor(
|
|
7
|
-
requestList
|
|
8
|
-
) {
|
|
9
|
-
this.#requestList = requestList;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** @returns {EC4W_Result} */
|
|
13
|
-
conclude() {
|
|
14
|
-
// map // transform
|
|
15
|
-
const sentRequests = [];
|
|
16
|
-
for (const request of this.#requestList) {
|
|
17
|
-
if (!request.url) continue;
|
|
18
|
-
|
|
19
|
-
const Url = new URL(request.url);
|
|
20
|
-
if (UPDE_Request.canBe(request.method, Url)) {
|
|
21
|
-
sentRequests.push(new UPDE_Request(request.method, Url));
|
|
22
|
-
}
|
|
23
|
-
else if (Conversion_Request.canBe(request.method, Url)) {
|
|
24
|
-
sentRequests.push(new Conversion_Request(request.method, Url));
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
// skip
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (sentRequests.length < 1) throw new Error('no ( sentRequest ) detected');
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// groupping pairs
|
|
36
|
-
const EC4W_list = [];
|
|
37
|
-
{
|
|
38
|
-
let lastUPDE = null;
|
|
39
|
-
for (const ping of sentRequests) {
|
|
40
|
-
if (ping instanceof UPDE_Request) {
|
|
41
|
-
lastUPDE = ping;
|
|
42
|
-
}
|
|
43
|
-
else if (ping instanceof Conversion_Request) {
|
|
44
|
-
EC4W_list.push(new EC4W_Request(lastUPDE, ping));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (EC4W_list.length < 1) throw new Error('no ( UPDE | EC4w ) requests detected');
|
|
49
|
-
|
|
50
|
-
return new EC4W_Result(EC4W_list);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** @param {string} em */
|
|
54
|
-
static emIsValid(em) {
|
|
55
|
-
if (!em) return false;
|
|
56
|
-
if (em.startsWith('tv.1') === false) return false;
|
|
57
|
-
if (em === 'tv.1') return false;
|
|
58
|
-
if (/^tv\.1~e[0-9]/.test(em)) return false;
|
|
59
|
-
const part = em.split('~');
|
|
60
|
-
const len = part.length;
|
|
61
|
-
if (len < 2) return false;
|
|
62
|
-
|
|
63
|
-
for (let i = 1; i < len; ++i) {
|
|
64
|
-
if (part[i] === '') return false;
|
|
65
|
-
const [key, value] = part[i].split('.');
|
|
66
|
-
if (!key) return false;
|
|
67
|
-
if (!value) return false;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
export const EC4W_ValidMessages = Object.freeze({
|
|
78
|
-
em_validInConversion: "valid `em` in Conversion payload",
|
|
79
|
-
em_validInUPDE: "valid `em` in UPDE payload",
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
export const EC4W_ErrorMessages = Object.freeze({
|
|
83
|
-
em_invalidInConversion: "invalid `em` in Conversion payload",
|
|
84
|
-
em_invalidInUPDE: "invalid `em` in UPDE payload",
|
|
85
|
-
ecsid_mismatch: "mismatch `ecsid` between UPDE and Conversion payload",
|
|
86
|
-
conversionId_mismatch: "mismatch `Conversion ID` between UPDE and Conversion payload",
|
|
87
|
-
noEC4W_request: "no valid EC4W requests detected at all",
|
|
88
|
-
});
|
|
89
|
-
export class EC4W_Request {
|
|
90
|
-
#UPDE_Request = null;
|
|
91
|
-
#Conversion_Request;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @param {UPDE_Request?} UPDE_Request
|
|
95
|
-
* @param {Conversion_Request} Conversion_Request */
|
|
96
|
-
constructor(
|
|
97
|
-
UPDE_Request,
|
|
98
|
-
Conversion_Request
|
|
99
|
-
) {
|
|
100
|
-
this.#UPDE_Request = UPDE_Request;
|
|
101
|
-
this.#Conversion_Request = Conversion_Request;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
get result() {
|
|
105
|
-
if (!this.#UPDE_Request && !this.#Conversion_Request)
|
|
106
|
-
return new Result(false, EC4W_ErrorMessages.noEC4W_request);
|
|
107
|
-
if (this.#ecsidIsValid() === false)
|
|
108
|
-
return new Result(false, EC4W_ErrorMessages.ecsid_mismatch);
|
|
109
|
-
|
|
110
|
-
return this.#emIsValid();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
#ecsidIsValid() {
|
|
114
|
-
if (this.#Conversion_Request === null) return false;
|
|
115
|
-
if (this.#UPDE_Request === null) {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (!this.#UPDE_Request.ecsid) return false;
|
|
120
|
-
if (!this.#Conversion_Request.ecsid) return false;
|
|
121
|
-
if (this.#UPDE_Request.ecsid !== this.#Conversion_Request.ecsid) return false;
|
|
122
|
-
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
#emIsValid() {
|
|
127
|
-
if (this.#Conversion_Request === null)
|
|
128
|
-
return new Result(false, EC4W_ErrorMessages.em_invalidInConversion);
|
|
129
|
-
|
|
130
|
-
if (this.#UPDE_Request === null) {
|
|
131
|
-
const isValid = this.#Conversion_Request.emIsValid();
|
|
132
|
-
if (isValid) return new Result(isValid, EC4W_ValidMessages.em_validInConversion);
|
|
133
|
-
else return new Result(isValid, EC4W_ErrorMessages.em_invalidInConversion);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (this.#Conversion_Request.em === null) {
|
|
137
|
-
const isValid = this.#UPDE_Request.emIsValid();
|
|
138
|
-
if (isValid) return new Result(isValid, EC4W_ValidMessages.em_validInUPDE);
|
|
139
|
-
else return new Result(isValid, EC4W_ErrorMessages.em_invalidInUPDE);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const isValid = this.#Conversion_Request.emIsValid();
|
|
143
|
-
if (isValid) return new Result(isValid, EC4W_ValidMessages.em_validInConversion);
|
|
144
|
-
else return new Result(isValid, EC4W_ErrorMessages.em_invalidInConversion);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
class Result {
|
|
149
|
-
#isGood;
|
|
150
|
-
get isGood() { return this.#isGood; }
|
|
151
|
-
#message;
|
|
152
|
-
get message() { return this.#message; }
|
|
153
|
-
|
|
154
|
-
/** @param {boolean} isGood
|
|
155
|
-
* @param {string} message */
|
|
156
|
-
constructor(isGood, message) {
|
|
157
|
-
this.#isGood = isGood;
|
|
158
|
-
this.#message = message;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export class UPDE_Request {
|
|
163
|
-
/**
|
|
164
|
-
* @param {string} method
|
|
165
|
-
* @param {URL} Url */
|
|
166
|
-
static canBe(method, Url) {
|
|
167
|
-
if (method !== 'GET') return false;
|
|
168
|
-
if (false === Url.toString().startsWith('https://www.google.com/ccm/form-data/')) return false;
|
|
169
|
-
if (Url.searchParams.get('em') === null) return false;
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
#method;
|
|
174
|
-
get method() { return this.#method; }
|
|
175
|
-
#Url;
|
|
176
|
-
get url() { return this.#Url.toString(); };
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* @param {string} method
|
|
180
|
-
* @param {URL} Url */
|
|
181
|
-
constructor(
|
|
182
|
-
method,
|
|
183
|
-
Url
|
|
184
|
-
) {
|
|
185
|
-
this.#method = method;
|
|
186
|
-
this.#Url = Url;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
get em() {
|
|
190
|
-
return this.#Url.searchParams.get('em');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
get ecsid() {
|
|
194
|
-
return this.#Url.searchParams.get('ecsid');
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
emIsValid() {
|
|
198
|
-
return EC4W_Validator.emIsValid(this.em);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export class Conversion_Request {
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* @param {string} method
|
|
207
|
-
* @param {URL} Url */
|
|
208
|
-
static canBe(method, Url) {
|
|
209
|
-
if (method !== 'GET') return false;
|
|
210
|
-
if (false === Url.toString().startsWith('https://www.googleadservices.com/ccm/conversion/')) return false;
|
|
211
|
-
if (Url.searchParams.get('label') === null) return false;
|
|
212
|
-
return true;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
#method;
|
|
216
|
-
get method() { return this.#method; }
|
|
217
|
-
#Url;
|
|
218
|
-
get url() { return this.#Url.toString(); };
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* @param {string} method
|
|
222
|
-
* @param {URL} Url */
|
|
223
|
-
constructor(
|
|
224
|
-
method,
|
|
225
|
-
Url
|
|
226
|
-
) {
|
|
227
|
-
this.#method = method;
|
|
228
|
-
this.#Url = Url;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
get em() {
|
|
232
|
-
return this.#Url.searchParams.get('em');
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
get ecsid() {
|
|
236
|
-
return this.#Url.searchParams.get('ecsid');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
emIsValid() {
|
|
240
|
-
return EC4W_Validator.emIsValid(this.em);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
export class EC4W_Result {
|
|
246
|
-
/** @type {EC4W_Request[]} */
|
|
247
|
-
EC4W_Requests = [];
|
|
248
|
-
// errors = [];
|
|
249
|
-
messages = [];
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* @param {EC4W_Request[]} EC4W_Requests
|
|
253
|
-
* */
|
|
254
|
-
constructor(
|
|
255
|
-
EC4W_Requests
|
|
256
|
-
) {
|
|
257
|
-
if (!EC4W_Requests || EC4W_Requests.length < 1) throw new Error('no requests detected');
|
|
258
|
-
this.EC4W_Requests = EC4W_Requests;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
get invalidRequest() {
|
|
263
|
-
for (const EC4W_Request of this.EC4W_Requests) {
|
|
264
|
-
if (EC4W_Request.result.isGood === false) return EC4W_Request;
|
|
265
|
-
}
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
get validRequest() {
|
|
270
|
-
for (const EC4W_Request of this.EC4W_Requests) {
|
|
271
|
-
if (EC4W_Request.result.isGood) return EC4W_Request;
|
|
272
|
-
}
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
// get summary() {
|
|
279
|
-
// const summary = [], EC4W_Requests = this.EC4W_Requests;
|
|
280
|
-
// for (const EC4W_Request of EC4W_Requests) {
|
|
281
|
-
// summary.push({
|
|
282
|
-
// EC4W_Request: EC4W_Request,
|
|
283
|
-
// result: EC4W_Request.result,
|
|
284
|
-
// });
|
|
285
|
-
// }
|
|
286
|
-
// return summary;
|
|
287
|
-
// }
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
export class SentRequest {
|
|
294
|
-
url = 'https://';
|
|
295
|
-
method = 'GET';
|
|
296
|
-
|
|
297
|
-
constructor(url, method) {
|
|
298
|
-
this.url = url;
|
|
299
|
-
this.method = method;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
// (function testmain() { // test
|
|
307
|
-
|
|
308
|
-
// class fakeUPDE {
|
|
309
|
-
// constructor(httpMethod, emValue, conversionId) {
|
|
310
|
-
// this.conversionId = conversionId;
|
|
311
|
-
// this.emValue = emValue;
|
|
312
|
-
|
|
313
|
-
// const emParam = `&em=${emValue ? emValue : 'tv.1'}`;
|
|
314
|
-
// this.url = `https://www.google.com/ccm/form-data/${conversionId}?gtm=45be61r1p3v9164572194za200zd9164572194xec&gcd=13l3l3l3l1l1&dma=0&tag_exp=103116026~103200004~104527907~104528501~104684208~104684211~115495939~115616985~115938465~115938468~116185181~116185182~116988316~117041587&gclaw_src=0_1&npa=0&frm=0&gclgs=12&gclst=63271790&gcllp=265921241&gclaw=TestingABC-2026-01-28&pscdl=noapi&auid=712372246.1762244434&uaa=x86&uab=64&uafvl=Google%2520Chrome%3B143.0.7499.203%7CChromium%3B143.0.7499.203%7CNot%2520A(Brand%3B24.0.0.0&uamb=0&uam=&uap=Chrome%20OS&uapv=16463.79.0&uaw=0&ec_mode=c&gap.plf=4.3&ecsid=1296144687.1769663220${emParam}`
|
|
315
|
-
// this.method = httpMethod;
|
|
316
|
-
// }
|
|
317
|
-
// }
|
|
318
|
-
|
|
319
|
-
// class fakeConve {
|
|
320
|
-
// constructor(httpMethod, emValue, conversionId, conversionLabel) {
|
|
321
|
-
// this.emValue = emValue;
|
|
322
|
-
// this.conversionId = conversionId;
|
|
323
|
-
// this.conversionLabel = conversionLabel;
|
|
324
|
-
|
|
325
|
-
// const emParam = emValue ? `&em=${emValue}` : '';
|
|
326
|
-
// this.url = `https://www.googleadservices.com/ccm/conversion/${conversionId}/?random=1769663226870&cv=11&fst=1769663226870&fmt=3&bg=ffffff&guid=ON&async=1&en=conversion>m=45be61r1v9164572194za200zd9164572194xec&gcd=13l3l3l3l1l1&dma=0&tag_exp=103116026~103200004~104527907~104528501~104684208~104684211~115495939~115616985~115938465~115938468~116185181~116185182~116988316~117041587&u_w=1745&u_h=1090&url=https%3A%2F%2Fgrcn-sme.github.io%2Fwordpress-example%2F&ref=https%3A%2F%2Fgrcn-sme.github.io%2Fwordpress-example%2F&gclaw_src=2_3&label=yYk9CMf--98YEMmV45Uq&capi=1>m_ee=1&frm=0&tiba=Wordpress%20Example&value=1¤cy_code=MYR&hn=www.googleadservices.com&npa=0&gclgs=12&gclst=63274872&gcllp=265921241&gclaw=TestingABC-2026-01-28&pscdl=noapi&auid=712372246.1762244434&uaa=x86&uab=64&uafvl=Google%2520Chrome%3B143.0.7499.203%7CChromium%3B143.0.7499.203%7CNot%2520A(Brand%3B24.0.0.0&uamb=0&uam=&uap=Chrome%20OS&uapv=16463.79.0&uaw=0&ec_mode=c&oid=113729285.1769663227&oidsrc=3&ecsid=1296144687.1769663220&_tu=ABA&gcl_ctr=399~0&data=event%3Dconversion&gap.plf=4.3${emParam}`;
|
|
327
|
-
// this.method = httpMethod;
|
|
328
|
-
// }
|
|
329
|
-
// }
|
|
330
|
-
// const defaultEMvalue = 'tv.1~em.h5JGBrQTGorO7q6IaFMfu5cSqqB6XTp1aybOD11spnQ~pn.QizoLG_BckrIeAQvfQVWU6temD0YbmFoJqctQ4S2ivg';
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
// function testValid(testName, inputRequests) {
|
|
334
|
-
// console.log('==========');
|
|
335
|
-
// console.log(testName);
|
|
336
|
-
// try {
|
|
337
|
-
// const sampleRequests = inputRequests || [
|
|
338
|
-
// { url: 'https://www.google.com/ccm/form-data/11319954121?gtm=45be61r1p3v9164572194za200zd9164572194xec&gcd=13l3l3l3l1l1&dma=0&tag_exp=103116026~103200004~104527907~104528501~104684208~104684211~115495939~115616985~115938465~115938468~116185181~116185182~116988316~117041587&gclaw_src=0_1&npa=0&frm=0&gclgs=12&gclst=63271790&gcllp=265921241&gclaw=TestingABC-2026-01-28&pscdl=noapi&auid=712372246.1762244434&uaa=x86&uab=64&uafvl=Google%2520Chrome%3B143.0.7499.203%7CChromium%3B143.0.7499.203%7CNot%2520A(Brand%3B24.0.0.0&uamb=0&uam=&uap=Chrome%20OS&uapv=16463.79.0&uaw=0&ec_mode=c&gap.plf=4.3&ecsid=1296144687.1769663220&em=tv.1~em.h5JGBrQTGorO7q6IaFMfu5cSqqB6XTp1aybOD11spnQ~pn.QizoLG_BckrIeAQvfQVWU6temD0YbmFoJqctQ4S2ivg', method: 'GET' }, // form-data
|
|
339
|
-
// { url: `https://www.googleadservices.com/ccm/conversion/11319954121/?random=1769663226870&cv=11&fst=1769663226870&fmt=3&bg=ffffff&guid=ON&async=1&en=conversion>m=45be61r1v9164572194za200zd9164572194xec&gcd=13l3l3l3l1l1&dma=0&tag_exp=103116026~103200004~104527907~104528501~104684208~104684211~115495939~115616985~115938465~115938468~116185181~116185182~116988316~117041587&u_w=1745&u_h=1090&url=https%3A%2F%2Fgrcn-sme.github.io%2Fwordpress-example%2F&ref=https%3A%2F%2Fgrcn-sme.github.io%2Fwordpress-example%2F&gclaw_src=2_3&label=yYk9CMf--98YEMmV45Uq&capi=1>m_ee=1&frm=0&tiba=Wordpress%20Example&value=1¤cy_code=MYR&hn=www.googleadservices.com&npa=0&gclgs=12&gclst=63274872&gcllp=265921241&gclaw=TestingABC-2026-01-28&pscdl=noapi&auid=712372246.1762244434&uaa=x86&uab=64&uafvl=Google%2520Chrome%3B143.0.7499.203%7CChromium%3B143.0.7499.203%7CNot%2520A(Brand%3B24.0.0.0&uamb=0&uam=&uap=Chrome%20OS&uapv=16463.79.0&uaw=0&ec_mode=c&oid=113729285.1769663227&oidsrc=3&ecsid=1296144687.1769663220&_tu=ABA&gcl_ctr=399~0&data=event%3Dconversion&gap.plf=4.3&em=tv.1~em.h5JGBrQTGorO7q6IaFMfu5cSqqB6XTp1aybOD11spnQ~pn.QizoLG_BckrIeAQvfQVWU6temD0YbmFoJqctQ4S2ivg`, method: 'GET' } // form-data
|
|
340
|
-
// ];
|
|
341
|
-
|
|
342
|
-
// const sentRequests = [];
|
|
343
|
-
// for (const req of sampleRequests) {
|
|
344
|
-
// sentRequests.push(new SentRequest(req.url, req.method));
|
|
345
|
-
// }
|
|
346
|
-
// const validator = new EC4W_Validator(sentRequests);
|
|
347
|
-
// const result = validator.conclude();
|
|
348
|
-
|
|
349
|
-
// console.log({ result });
|
|
350
|
-
// const invalid = result.invalidRequest;
|
|
351
|
-
// console.log({ invalid });
|
|
352
|
-
// console.assert(invalid === null, result);
|
|
353
|
-
// // if (invalid) debugger;
|
|
354
|
-
|
|
355
|
-
// } finally {
|
|
356
|
-
// // console.groupEnd();
|
|
357
|
-
// console.log('==========');
|
|
358
|
-
// }
|
|
359
|
-
// }
|
|
360
|
-
|
|
361
|
-
// testValid('defualt');
|
|
362
|
-
// testValid('good', [
|
|
363
|
-
// new fakeUPDE('GET', null, '11319954121'),
|
|
364
|
-
// new fakeUPDE('GET', null, '11319954121'),
|
|
365
|
-
// new fakeConve('GET', defaultEMvalue, '11319954121', 'xxxxxxxxx'),
|
|
366
|
-
// ]);
|
|
367
|
-
|
|
368
|
-
// testValid('bad', [
|
|
369
|
-
// new fakeUPDE('GET', 'tv.1', '11319954121'),
|
|
370
|
-
// new fakeUPDE('GET', defaultEMvalue, '11319954121'),
|
|
371
|
-
// new fakeConve('GET', 'tv.1', '11319954121', 'xxxxxxxxx'),
|
|
372
|
-
// ]);
|
|
373
|
-
|
|
374
|
-
// testValid('stitching', [
|
|
375
|
-
// new fakeUPDE('GET', 'tv.1', '11319954121'),
|
|
376
|
-
// new fakeUPDE('GET', defaultEMvalue, '11319954121'),
|
|
377
|
-
// new fakeConve('GET', null, '11319954121', 'xxxxxxxxx'),
|
|
378
|
-
// ]);
|
|
379
|
-
|
|
380
|
-
// testValid('stitching: self empty em value', [
|
|
381
|
-
// new fakeUPDE('GET', 'tv.1', '11319954121'),
|
|
382
|
-
// new fakeUPDE('GET', 'defaultEMvalue', '11319954121'),
|
|
383
|
-
// new fakeConve('GET', 'tv.1', '11319954121', 'xxxxxxxxx'),
|
|
384
|
-
// ]);
|
|
385
|
-
|
|
386
|
-
// testValid('stitching: invalid prior em', [
|
|
387
|
-
// new fakeUPDE('GET', 'tv.1', '11319954121'),
|
|
388
|
-
// new fakeUPDE('GET', defaultEMvalue, '11319954121'),
|
|
389
|
-
// new fakeUPDE('GET', 'tv.1', '11319954121'),
|
|
390
|
-
// new fakeConve('GET', null, '11319954121', 'xxxxxxxxx'),
|
|
391
|
-
// ]);
|
|
392
|
-
|
|
393
|
-
// console.log('end');
|
|
394
|
-
// });
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { describe, it, test, expect } from 'vitest';
|
|
2
|
-
import { EC4W_Validator } from "/src/ec4w_validator.js";
|
|
3
|
-
import { EC4W_ValidMessages, EC4W_ErrorMessages } from '/src/ec4w_validator.js';
|
|
4
|
-
|
|
5
|
-
class fakeUPDE {
|
|
6
|
-
constructor({ httpMethod, em, ecsid = null, conversionId }) {
|
|
7
|
-
const updeLink = new URL(`https://www.google.com/ccm/form-data/${conversionId}?gtm=45be61r1p3v9164572194za200zd9164572194xec&gcd=13l3l3l3l1l1&dma=0&tag_exp=103116026~103200004~104527907~104528501~104684208~104684211~115495939~115616985~115938465~115938468~116185181~116185182~116988316~117041587&gclaw_src=0_1&npa=0&frm=0&gclgs=12&gclst=63271790&gcllp=265921241&gclaw=TestingABC-2026-01-28&pscdl=noapi&auid=712372246.1762244434&uaa=x86&uab=64&uafvl=Google%2520Chrome%3B143.0.7499.203%7CChromium%3B143.0.7499.203%7CNot%2520A(Brand%3B24.0.0.0&uamb=0&uam=&uap=Chrome%20OS&uapv=16463.79.0&uaw=0&ec_mode=c&gap.plf=4.3&ecsid=1296144687.1769663220&em=tv.1`);
|
|
8
|
-
const params = updeLink.searchParams;
|
|
9
|
-
params.set('em', em || 'tv.1');
|
|
10
|
-
params.set('ecsid', ecsid ?? '1296144687.1769663220');
|
|
11
|
-
|
|
12
|
-
this.url = updeLink.toString();
|
|
13
|
-
this.method = httpMethod;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class fakeConve {
|
|
18
|
-
constructor({ httpMethod, em, ecsid = null, conversionId, conversionLabel }) {
|
|
19
|
-
const convLink = new URL(`https://www.googleadservices.com/ccm/conversion/${conversionId}/?random=1769663226870&cv=11&fst=1769663226870&fmt=3&bg=ffffff&guid=ON&async=1&en=conversion>m=45be61r1v9164572194za200zd9164572194xec&gcd=13l3l3l3l1l1&dma=0&tag_exp=103116026~103200004~104527907~104528501~104684208~104684211~115495939~115616985~115938465~115938468~116185181~116185182~116988316~117041587&u_w=1745&u_h=1090&url=https%3A%2F%2Fgrcn-sme.github.io%2Fwordpress-example%2F&ref=https%3A%2F%2Fgrcn-sme.github.io%2Fwordpress-example%2F&gclaw_src=2_3&label=yYk9CMf--98YEMmV45Uq&capi=1>m_ee=1&frm=0&tiba=Wordpress%20Example&value=1¤cy_code=MYR&hn=www.googleadservices.com&npa=0&gclgs=12&gclst=63274872&gcllp=265921241&gclaw=TestingABC-2026-01-28&pscdl=noapi&auid=712372246.1762244434&uaa=x86&uab=64&uafvl=Google%2520Chrome%3B143.0.7499.203%7CChromium%3B143.0.7499.203%7CNot%2520A(Brand%3B24.0.0.0&uamb=0&uam=&uap=Chrome%20OS&uapv=16463.79.0&uaw=0&ec_mode=c&oid=113729285.1769663227&oidsrc=3&ecsid=1296144687.1769663220&_tu=ABA&gcl_ctr=399~0&data=event%3Dconversion&gap.plf=4.3&em=tv.1`);
|
|
20
|
-
const params = convLink.searchParams;
|
|
21
|
-
if (em !== null) params.set('em', em);
|
|
22
|
-
else params.delete('em');
|
|
23
|
-
params.set('ecsid', ecsid ?? '1296144687.1769663220');
|
|
24
|
-
params.set('label', conversionLabel);
|
|
25
|
-
|
|
26
|
-
this.url = convLink.toString();
|
|
27
|
-
this.method = httpMethod;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const defaultEMvalue = 'tv.1~em.h5JGBrQTGorO7q6IaFMfu5cSqqB6XTp1aybOD11spnQ~pn.QizoLG_BckrIeAQvfQVWU6temD0YbmFoJqctQ4S2ivg';
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
test('good Conversion em', function () {
|
|
35
|
-
const sample = [
|
|
36
|
-
new fakeUPDE({ httpMethod: 'GET', em: null, conversionId: '11319954121' }),
|
|
37
|
-
new fakeUPDE({ httpMethod: 'GET', em: null, conversionId: '11319954121' }),
|
|
38
|
-
new fakeConve({ httpMethod: 'GET', em: defaultEMvalue, conversionId: '11319954121', conversionLabel: 'xxoos_s_ssw' }),
|
|
39
|
-
];
|
|
40
|
-
const EC4W_validator = new EC4W_Validator(sample);
|
|
41
|
-
const result = EC4W_validator.conclude();
|
|
42
|
-
|
|
43
|
-
expect(result.invalidRequest).toBeNull();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('bad conversion em', function () {
|
|
47
|
-
|
|
48
|
-
const sample = [
|
|
49
|
-
new fakeUPDE({ httpMethod: 'GET', em: 'tv.1', conversionId: '11319954121' }),
|
|
50
|
-
new fakeUPDE({ httpMethod: 'GET', em: defaultEMvalue, conversionId: '11319954121' }),
|
|
51
|
-
new fakeConve({ httpMethod: 'GET', em: 'tv.1', conversionId: '11319954121', conversionLabel: 'xx_x_xxxxxx' }),
|
|
52
|
-
];
|
|
53
|
-
const EC4W_validator = new EC4W_Validator(sample);
|
|
54
|
-
const result = EC4W_validator.conclude();
|
|
55
|
-
|
|
56
|
-
expect(result.invalidRequest).toBeTruthy();
|
|
57
|
-
const re = result.invalidRequest.result;
|
|
58
|
-
expect(re.isGood).toBe(false);
|
|
59
|
-
expect(re.message).toBe(EC4W_ErrorMessages.em_invalidInConversion);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('stitching: proper', function () {
|
|
65
|
-
|
|
66
|
-
const sample = [
|
|
67
|
-
new fakeUPDE({ httpMethod: 'GET', em: 'tv.1', conversionId: '11319954121' }),
|
|
68
|
-
new fakeUPDE({ httpMethod: 'GET', em: defaultEMvalue, conversionId: '11319954121' }),
|
|
69
|
-
new fakeConve({ httpMethod: 'GET', em: null, conversionId: '11319954121', conversionLabel: 'xxxxxxxxx' }),
|
|
70
|
-
];
|
|
71
|
-
const EC4W_validator = new EC4W_Validator(sample);
|
|
72
|
-
const result = EC4W_validator.conclude();
|
|
73
|
-
|
|
74
|
-
expect(result.invalidRequest).toBeNull();
|
|
75
|
-
|
|
76
|
-
const EC4W_Request = result.validRequest;
|
|
77
|
-
expect(EC4W_Request).toBeTruthy();
|
|
78
|
-
const re = EC4W_Request.result;
|
|
79
|
-
expect(re.isGood).toBe(true);
|
|
80
|
-
expect(re.message).toBe(EC4W_ValidMessages.em_validInUPDE);
|
|
81
|
-
expect(re.message).not.toBe(EC4W_ValidMessages.em_validInConversion);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('stitching: self empty em value', function () {
|
|
85
|
-
const sample = [
|
|
86
|
-
new fakeUPDE({ httpMethod: 'GET', em: 'tv.1', conversionId: '11319954121' }),
|
|
87
|
-
new fakeUPDE({ httpMethod: 'GET', em: defaultEMvalue, conversionId: '11319954121' }),
|
|
88
|
-
new fakeConve({ httpMethod: 'GET', em: 'tv.1', conversionId: '11319954121', conversionLabel: 'xxxxxxxxx' }),
|
|
89
|
-
];
|
|
90
|
-
|
|
91
|
-
const EC4W_validator = new EC4W_Validator(sample);
|
|
92
|
-
const result = EC4W_validator.conclude();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
expect(result.invalidRequest).toBeTruthy();
|
|
96
|
-
|
|
97
|
-
const re = result.invalidRequest.result;
|
|
98
|
-
expect(re.isGood).toBe(false);
|
|
99
|
-
expect(re.message).toBe(EC4W_ErrorMessages.em_invalidInConversion);
|
|
100
|
-
expect(re.message).not.toBe(EC4W_ValidMessages.em_validInUPDE);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
test('stitching: invalid prior em', function () {
|
|
108
|
-
|
|
109
|
-
const sample = [
|
|
110
|
-
new fakeUPDE({ httpMethod: 'GET', em: 'tv.1', conversionId: '11319954121' }),
|
|
111
|
-
new fakeUPDE({ httpMethod: 'GET', em: defaultEMvalue, conversionId: '11319954121' }),
|
|
112
|
-
new fakeUPDE({ httpMethod: 'GET', em: 'tv.1', conversionId: '11319954121' }),
|
|
113
|
-
new fakeConve({ httpMethod: 'GET', em: null, conversionId: '11319954121', conversionLabel: 'xxxxxxxxx' }),
|
|
114
|
-
];
|
|
115
|
-
const EC4W_validator = new EC4W_Validator(sample);
|
|
116
|
-
const result = EC4W_validator.conclude();
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
expect(result.invalidRequest).toBeTruthy();
|
|
120
|
-
|
|
121
|
-
const re = result.invalidRequest.result;
|
|
122
|
-
expect(re.isGood).toBe(false);
|
|
123
|
-
expect(re.message).toBe(EC4W_ErrorMessages.em_invalidInUPDE);
|
|
124
|
-
expect(re.message).not.toBe(EC4W_ErrorMessages.em_invalidInConversion);
|
|
125
|
-
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
test('stitching: different ecsid', function () {
|
|
134
|
-
|
|
135
|
-
const sample = [
|
|
136
|
-
new fakeUPDE({ httpMethod: 'GET', em: 'tv.1', ecsid: '1120.0300', conversionId: '11319954121' }),
|
|
137
|
-
new fakeUPDE({ httpMethod: 'GET', em: 'defaultEMvalue', ecsid: '1120.0300', conversionId: '11319954121' }),
|
|
138
|
-
new fakeConve({ httpMethod: 'GET', em: null, ecsid: '9920.22', conversionId: '11319954121', conversionLabel: 'xxxxxxxxx' }),
|
|
139
|
-
];
|
|
140
|
-
const EC4W_validator = new EC4W_Validator(sample);
|
|
141
|
-
const result = EC4W_validator.conclude();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
expect(result.invalidRequest).toBeTruthy();
|
|
145
|
-
|
|
146
|
-
const re = result.invalidRequest.result;
|
|
147
|
-
expect(re.isGood).toBe(false);
|
|
148
|
-
expect(re.message).toBe(EC4W_ErrorMessages.ecsid_mismatch);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
package/src/main.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// import {*} from './ec4w_validator.js';
|
package/vite.config.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
// import dts from 'vite-plugin-dts';
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
// plugins: [dts({ rollupTypes: true })], // Bundles types into one file
|
|
6
|
-
build: {
|
|
7
|
-
lib: {
|
|
8
|
-
entry: './src/ec4w_validator.js',
|
|
9
|
-
name: 'fafafa', // The global variable used in UMD builds
|
|
10
|
-
// fileName: (format) => `index.${format}.js`
|
|
11
|
-
fileName: 'index'
|
|
12
|
-
},
|
|
13
|
-
rollupOptions: {
|
|
14
|
-
// Don't bundle these into the library
|
|
15
|
-
external: ['vue'],
|
|
16
|
-
output: {
|
|
17
|
-
globals: { vue: 'Vue' }
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
})
|
package/vitest.config.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
// Allows you to use 'describe', 'it', and 'expect' without importing them
|
|
6
|
-
globals: true,
|
|
7
|
-
// Simulates a browser environment (important for React/Vue)
|
|
8
|
-
environment: 'jsdom',
|
|
9
|
-
// Path to your test files
|
|
10
|
-
include: ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
11
|
-
},
|
|
12
|
-
});
|
|
File without changes
|