-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlg_utils.js
54 lines (45 loc) · 1.68 KB
/
lg_utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import settings from "../settings";
export function googleAnalyticsParamValues(wtbEntity, product, category, source) {
const params = {
productName: product.name,
categoryName: category.name,
source
};
if (wtbEntity) {
params.model = wtbEntity.model_name ? wtbEntity.model_name.split('.')[0] : wtbEntity.name.split(' - ')[0]
params.modelWithSuffix = wtbEntity.model_name || 'N/A'
params.identifier = wtbEntity.key;
const section = wtbEntity.section || '';
const pageCategoryLevels = section.split(' > ');
for (let i = 0; i < 3; i++) {
params['pageCategoryL' + (i + 1)] = pageCategoryLevels[i] || 'N/A'
}
} else {
params.model = 'N/A'
params.modelWithSuffix = 'N/A'
params.identifier = 'N/A';
for (let i = 0; i < 3; i++) {
params['pageCategoryL' + (i + 1)] = 'N/A'
}
}
const categoryMetadata = settings.categoryMetadata[category.id] || {};
const categoryAnalyticsSpecsFields = categoryMetadata.analyticsSpecDimensions || [];
categoryAnalyticsSpecsFields.forEach((field, idx) => {
params['spec' + (idx+1)] = product.specs[field];
})
return params
}
export function generateAnalyticsParams(analyticsParamsValues, analyticsSettings) {
const params = {
send_to: analyticsSettings.id
}
for (const field of Object.keys(analyticsSettings.mapping)) {
const paramValue = analyticsParamsValues[field]
if (!paramValue) {
continue
}
const dimensionIndex = analyticsSettings.mapping[field];
params['dimension' + dimensionIndex] = paramValue
}
return params
}