@getuserfeedback/adapters 0.4.2 → 0.4.4
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.
|
@@ -10,6 +10,21 @@ export type TemplateCondition = {
|
|
|
10
10
|
export type TemplateValueValidator = {
|
|
11
11
|
type: "NON_EMPTY";
|
|
12
12
|
};
|
|
13
|
+
export type TemplateSimpleTableTextColumn = {
|
|
14
|
+
defaultValue?: string;
|
|
15
|
+
displayName: string;
|
|
16
|
+
name: string;
|
|
17
|
+
type: "TEXT";
|
|
18
|
+
};
|
|
19
|
+
export type TemplateSimpleTableSelectColumn = {
|
|
20
|
+
defaultValue?: string;
|
|
21
|
+
displayName: string;
|
|
22
|
+
name: string;
|
|
23
|
+
type: "SELECT";
|
|
24
|
+
isUnique?: boolean;
|
|
25
|
+
macrosInSelect?: boolean;
|
|
26
|
+
selectItems: TemplateSelectItem[];
|
|
27
|
+
};
|
|
13
28
|
export type TemplateParameter = {
|
|
14
29
|
type: "TEXT";
|
|
15
30
|
name: string;
|
|
@@ -46,15 +61,7 @@ export type TemplateParameter = {
|
|
|
46
61
|
help?: string;
|
|
47
62
|
defaultValue?: Array<Record<string, string>>;
|
|
48
63
|
newRowButtonText: string;
|
|
49
|
-
simpleTableColumns: Array<
|
|
50
|
-
defaultValue?: string;
|
|
51
|
-
displayName: string;
|
|
52
|
-
name: string;
|
|
53
|
-
type: "SELECT";
|
|
54
|
-
isUnique?: boolean;
|
|
55
|
-
macrosInSelect?: boolean;
|
|
56
|
-
selectItems: TemplateSelectItem[];
|
|
57
|
-
}>;
|
|
64
|
+
simpleTableColumns: Array<TemplateSimpleTableTextColumn | TemplateSimpleTableSelectColumn>;
|
|
58
65
|
valueValidators?: TemplateValueValidator[];
|
|
59
66
|
enablingConditions?: TemplateCondition[];
|
|
60
67
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-generation.d.ts","sourceRoot":"","sources":["../../src/gtm/template-generation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
|
type: "EQUALS",
|
|
27
27
|
},
|
|
28
28
|
];
|
|
29
|
+
const IDENTIFY_ADVANCED_MODE_CONDITION = [
|
|
30
|
+
{
|
|
31
|
+
paramName: "identifyMode",
|
|
32
|
+
paramValue: "advanced",
|
|
33
|
+
type: "EQUALS",
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
const INTELLIGENT_IDENTIFY_USER_ID_KEYS = [
|
|
37
|
+
"userId",
|
|
38
|
+
"user.userId",
|
|
39
|
+
"user.id",
|
|
40
|
+
"traits.userId",
|
|
41
|
+
"traits.id",
|
|
42
|
+
"context.userId",
|
|
43
|
+
"context.user.id",
|
|
44
|
+
];
|
|
45
|
+
const INTELLIGENT_IDENTIFY_EMAIL_KEYS = [
|
|
46
|
+
"email",
|
|
47
|
+
"user.email",
|
|
48
|
+
"traits.email",
|
|
49
|
+
"context.email",
|
|
50
|
+
"context.user.email",
|
|
51
|
+
];
|
|
52
|
+
const INTELLIGENT_IDENTIFY_PHONE_KEYS = [
|
|
53
|
+
"phone",
|
|
54
|
+
"user.phone",
|
|
55
|
+
"traits.phone",
|
|
56
|
+
"context.phone",
|
|
57
|
+
"context.user.phone",
|
|
58
|
+
];
|
|
59
|
+
const ADVANCED_PRIMARY_IDENTITY_SELECT_ITEMS = [
|
|
60
|
+
{
|
|
61
|
+
displayValue: "User ID",
|
|
62
|
+
value: "userId",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
displayValue: "Phone",
|
|
66
|
+
value: "phone",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
displayValue: "Email",
|
|
70
|
+
value: "email",
|
|
71
|
+
},
|
|
72
|
+
];
|
|
29
73
|
const buildAutomaticDefaultScopeMappings = () => DEFAULT_GTM_SCOPE_MAPPINGS.filter((mapping) => isHostConfigurableGtmScope(mapping.scope)).map((mapping) => ({
|
|
30
74
|
scope: mapping.scope,
|
|
31
75
|
mapping: mapping.consentType,
|
|
@@ -261,6 +305,77 @@ export function buildGtmTemplateParameters(_options) {
|
|
|
261
305
|
},
|
|
262
306
|
],
|
|
263
307
|
},
|
|
308
|
+
{
|
|
309
|
+
type: "GROUP",
|
|
310
|
+
name: "identifyGroup",
|
|
311
|
+
displayName: "User Identity",
|
|
312
|
+
groupStyle: "ZIPPY_CLOSED",
|
|
313
|
+
subParams: [
|
|
314
|
+
{
|
|
315
|
+
type: "RADIO",
|
|
316
|
+
name: "identifyMode",
|
|
317
|
+
displayName: "Identification mode",
|
|
318
|
+
simpleValueType: true,
|
|
319
|
+
defaultValue: "intelligent",
|
|
320
|
+
radioItems: [
|
|
321
|
+
{
|
|
322
|
+
value: "intelligent",
|
|
323
|
+
displayValue: "Intelligent",
|
|
324
|
+
help: "Automatically read common data layer keys for user ID, email, and phone. User ID is sent as `identify(userId)` and email or phone stay as raw traits.",
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
value: "disabled",
|
|
328
|
+
displayValue: "Disabled",
|
|
329
|
+
help: "Do not send identify data from this GTM tag.",
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
value: "advanced",
|
|
333
|
+
displayValue: "Advanced",
|
|
334
|
+
help: "Choose how GTM encodes the primary identity and add any extra traits you want to send from GTM variables.",
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
type: "SELECT",
|
|
340
|
+
name: "identifyPrimaryIdentityType",
|
|
341
|
+
displayName: "Primary identity",
|
|
342
|
+
simpleValueType: true,
|
|
343
|
+
macrosInSelect: false,
|
|
344
|
+
defaultValue: "userId",
|
|
345
|
+
selectItems: [...ADVANCED_PRIMARY_IDENTITY_SELECT_ITEMS],
|
|
346
|
+
help: "Choose whether GTM should encode the primary identity as `identify(userId)` or as a raw identity trait like `email` or `phone`.",
|
|
347
|
+
enablingConditions: [...IDENTIFY_ADVANCED_MODE_CONDITION],
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
type: "TEXT",
|
|
351
|
+
name: "identifyPrimaryIdentityValue",
|
|
352
|
+
displayName: "Primary identity value",
|
|
353
|
+
simpleValueType: true,
|
|
354
|
+
help: "Use a GTM variable that resolves to the selected primary identity value.",
|
|
355
|
+
enablingConditions: [...IDENTIFY_ADVANCED_MODE_CONDITION],
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
type: "SIMPLE_TABLE",
|
|
359
|
+
name: "identifyTraits",
|
|
360
|
+
displayName: "Traits",
|
|
361
|
+
help: "Add any traits you want to send from GTM variables. Common examples are `email`, `phone`, `name`, and `plan`. Empty rows are ignored.",
|
|
362
|
+
newRowButtonText: "Add Trait",
|
|
363
|
+
simpleTableColumns: [
|
|
364
|
+
{
|
|
365
|
+
displayName: "Trait Name",
|
|
366
|
+
name: "name",
|
|
367
|
+
type: "TEXT",
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
displayName: "Trait Value",
|
|
371
|
+
name: "value",
|
|
372
|
+
type: "TEXT",
|
|
373
|
+
},
|
|
374
|
+
],
|
|
375
|
+
enablingConditions: [...IDENTIFY_ADVANCED_MODE_CONDITION],
|
|
376
|
+
},
|
|
377
|
+
],
|
|
378
|
+
},
|
|
264
379
|
];
|
|
265
380
|
}
|
|
266
381
|
export function buildGtmRuntimeSource(input) {
|
|
@@ -274,6 +389,7 @@ const queryPermission = require("queryPermission");
|
|
|
274
389
|
const createQueue = require("createQueue");
|
|
275
390
|
const isConsentGranted = require("isConsentGranted");
|
|
276
391
|
const encodeUriComponent = require("encodeUriComponent");
|
|
392
|
+
const copyFromDataLayer = require("copyFromDataLayer");
|
|
277
393
|
|
|
278
394
|
const loaderScriptBaseUrl = ${JSON.stringify(loaderScriptBaseUrl)};
|
|
279
395
|
const gtmConsentTypes = ${JSON.stringify(GTM_CONSENT_TYPES)};
|
|
@@ -282,6 +398,9 @@ const defaultScopeMappings = ${JSON.stringify(defaultTemplateScopeMappings)};
|
|
|
282
398
|
const hostConfigurableScopes = ${JSON.stringify(defaultTemplateScopeMappings.map((row) => row.scope))};
|
|
283
399
|
const defaultAutoDetectColorSchemeAttrs = ${JSON.stringify(DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS)};
|
|
284
400
|
const queueKey = ${JSON.stringify(GTM_QUEUE_KEY)};
|
|
401
|
+
const intelligentIdentifyUserIdKeys = ${JSON.stringify(INTELLIGENT_IDENTIFY_USER_ID_KEYS)};
|
|
402
|
+
const intelligentIdentifyEmailKeys = ${JSON.stringify(INTELLIGENT_IDENTIFY_EMAIL_KEYS)};
|
|
403
|
+
const intelligentIdentifyPhoneKeys = ${JSON.stringify(INTELLIGENT_IDENTIFY_PHONE_KEYS)};
|
|
285
404
|
|
|
286
405
|
const trimString = function(value) {
|
|
287
406
|
return typeof value === "string" ? value.trim() : "";
|
|
@@ -329,6 +448,159 @@ const normalizeThemeInput = function(inputValue) {
|
|
|
329
448
|
return undefined;
|
|
330
449
|
};
|
|
331
450
|
|
|
451
|
+
const isListLike = function(value) {
|
|
452
|
+
return (
|
|
453
|
+
!!value &&
|
|
454
|
+
typeof value.length === "number" &&
|
|
455
|
+
typeof value.map === "function"
|
|
456
|
+
);
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
const normalizeTraitValue = function(value) {
|
|
460
|
+
if (value === undefined || value === null) {
|
|
461
|
+
return undefined;
|
|
462
|
+
}
|
|
463
|
+
if (typeof value === "string") {
|
|
464
|
+
const trimmedValue = value.trim();
|
|
465
|
+
return trimmedValue ? trimmedValue : undefined;
|
|
466
|
+
}
|
|
467
|
+
return value;
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
const normalizeUserIdValue = function(value) {
|
|
471
|
+
if (typeof value !== "string") {
|
|
472
|
+
return undefined;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
const trimmedValue = value.trim();
|
|
476
|
+
return trimmedValue ? trimmedValue : undefined;
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const addTrait = function(result, name, value) {
|
|
480
|
+
const traitName = trimString(name);
|
|
481
|
+
const traitValue = normalizeTraitValue(value);
|
|
482
|
+
if (!traitName || traitValue === undefined) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
result[traitName] = traitValue;
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const getIntelligentIdentifyValue = function(keys) {
|
|
489
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
490
|
+
const key = keys[index];
|
|
491
|
+
if (!queryPermission("read_data_layer", key)) {
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const value = copyFromDataLayer(key);
|
|
496
|
+
const normalizedValue = normalizeTraitValue(value);
|
|
497
|
+
if (normalizedValue !== undefined) {
|
|
498
|
+
return normalizedValue;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return undefined;
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
const getIntelligentIdentifyTraits = function() {
|
|
506
|
+
const traits = {};
|
|
507
|
+
addTrait(traits, "email", getIntelligentIdentifyValue(intelligentIdentifyEmailKeys));
|
|
508
|
+
addTrait(traits, "phone", getIntelligentIdentifyValue(intelligentIdentifyPhoneKeys));
|
|
509
|
+
return traits;
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
const getAdvancedIdentifyTraits = function(templateData) {
|
|
513
|
+
const traits = {};
|
|
514
|
+
const rows = isListLike(templateData.identifyTraits)
|
|
515
|
+
? templateData.identifyTraits
|
|
516
|
+
: [];
|
|
517
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
518
|
+
const row = rows[index];
|
|
519
|
+
if (!row || typeof row !== "object") {
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
addTrait(traits, row.name, row.value);
|
|
523
|
+
}
|
|
524
|
+
return traits;
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
const hasOwnKeys = function(value) {
|
|
528
|
+
for (const key in value) {
|
|
529
|
+
return !!key;
|
|
530
|
+
}
|
|
531
|
+
return false;
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
const getIdentifyCommandFromUserIdAndTraits = function(userId, traits) {
|
|
535
|
+
const hasTraits = hasOwnKeys(traits);
|
|
536
|
+
|
|
537
|
+
if (userId && hasTraits) {
|
|
538
|
+
return {
|
|
539
|
+
kind: "identify",
|
|
540
|
+
userId: userId,
|
|
541
|
+
traits: traits,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
if (userId) {
|
|
545
|
+
return {
|
|
546
|
+
kind: "identify",
|
|
547
|
+
userId: userId,
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
if (hasTraits) {
|
|
551
|
+
return {
|
|
552
|
+
kind: "identify",
|
|
553
|
+
traits: traits,
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
return undefined;
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
const getIntelligentIdentifyCommand = function() {
|
|
560
|
+
const userId = normalizeUserIdValue(
|
|
561
|
+
getIntelligentIdentifyValue(intelligentIdentifyUserIdKeys),
|
|
562
|
+
);
|
|
563
|
+
const traits = getIntelligentIdentifyTraits();
|
|
564
|
+
return getIdentifyCommandFromUserIdAndTraits(userId, traits);
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
const getAdvancedIdentifyCommand = function(templateData) {
|
|
568
|
+
const traits = getAdvancedIdentifyTraits(templateData);
|
|
569
|
+
const primaryIdentityType = trimString(templateData.identifyPrimaryIdentityType);
|
|
570
|
+
const primaryIdentityValue = normalizeTraitValue(
|
|
571
|
+
templateData.identifyPrimaryIdentityValue,
|
|
572
|
+
);
|
|
573
|
+
|
|
574
|
+
if (primaryIdentityType === "userId") {
|
|
575
|
+
const userId = normalizeUserIdValue(primaryIdentityValue);
|
|
576
|
+
return getIdentifyCommandFromUserIdAndTraits(userId, traits);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (
|
|
580
|
+
primaryIdentityType === "email" ||
|
|
581
|
+
primaryIdentityType === "phone"
|
|
582
|
+
) {
|
|
583
|
+
addTrait(traits, primaryIdentityType, primaryIdentityValue);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return hasOwnKeys(traits)
|
|
587
|
+
? {
|
|
588
|
+
kind: "identify",
|
|
589
|
+
traits: traits,
|
|
590
|
+
}
|
|
591
|
+
: undefined;
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
const getIdentifyCommand = function(templateData) {
|
|
595
|
+
if (templateData.identifyMode === "intelligent") {
|
|
596
|
+
return getIntelligentIdentifyCommand();
|
|
597
|
+
}
|
|
598
|
+
if (templateData.identifyMode === "advanced") {
|
|
599
|
+
return getAdvancedIdentifyCommand(templateData);
|
|
600
|
+
}
|
|
601
|
+
return undefined;
|
|
602
|
+
};
|
|
603
|
+
|
|
332
604
|
const getThemeInput = function(templateData) {
|
|
333
605
|
if (templateData.themeMode === "variable") {
|
|
334
606
|
return templateData.themeModeVariable;
|
|
@@ -389,14 +661,6 @@ const isHostConfigurableScope = function(scope) {
|
|
|
389
661
|
return false;
|
|
390
662
|
};
|
|
391
663
|
|
|
392
|
-
const isListLike = function(value) {
|
|
393
|
-
return (
|
|
394
|
-
!!value &&
|
|
395
|
-
typeof value.length === "number" &&
|
|
396
|
-
typeof value.map === "function"
|
|
397
|
-
);
|
|
398
|
-
};
|
|
399
|
-
|
|
400
664
|
const getManualScopeMappings = function(templateData) {
|
|
401
665
|
const rawRows = isListLike(templateData.scopeMappings)
|
|
402
666
|
? templateData.scopeMappings
|
|
@@ -520,6 +784,11 @@ queuePush({
|
|
|
520
784
|
opts: initOptions,
|
|
521
785
|
});
|
|
522
786
|
|
|
787
|
+
const identifyCommand = getIdentifyCommand(data);
|
|
788
|
+
if (identifyCommand !== undefined) {
|
|
789
|
+
queuePush(identifyCommand);
|
|
790
|
+
}
|
|
791
|
+
|
|
523
792
|
log("Loading getuserfeedback loader:", widgetUrl);
|
|
524
793
|
|
|
525
794
|
if (queryPermission("inject_script", widgetUrl)) {
|
|
@@ -568,6 +837,16 @@ export function buildGtmPermissions(input) {
|
|
|
568
837
|
]))),
|
|
569
838
|
},
|
|
570
839
|
]),
|
|
840
|
+
buildPermission("read_data_layer", [
|
|
841
|
+
{
|
|
842
|
+
key: "keyPatterns",
|
|
843
|
+
value: listValue([
|
|
844
|
+
...INTELLIGENT_IDENTIFY_USER_ID_KEYS,
|
|
845
|
+
...INTELLIGENT_IDENTIFY_EMAIL_KEYS,
|
|
846
|
+
...INTELLIGENT_IDENTIFY_PHONE_KEYS,
|
|
847
|
+
].map((key) => stringValue(key))),
|
|
848
|
+
},
|
|
849
|
+
]),
|
|
571
850
|
];
|
|
572
851
|
}
|
|
573
852
|
export function buildGtmTemplateInfo(input) {
|