@griddo/cx 10.4.28 → 10.4.30
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/build/index.d.ts +2 -2
- package/build/index.js +30 -27
- package/build/react/GriddoIntegrations/index.d.ts +12 -0
- package/build/react/index.d.ts +2 -2
- package/build/react/index.js +3 -1
- package/build/run-start-render.js +30 -27
- package/build/start-render.js +30 -27
- package/build/types/global.d.ts +1 -1
- package/build/types/pages.d.ts +6 -0
- package/build/utils/integrations.d.ts +26 -0
- package/exporter/adapters/gatsby/index.ts +25 -1
- package/exporter/index.ts +2 -1
- package/exporter/react/GriddoIntegrations/index.tsx +131 -0
- package/exporter/react/index.tsx +2 -2
- package/exporter/start-render.ts +7 -6
- package/exporter/types/global.ts +1 -0
- package/exporter/types/pages.ts +7 -0
- package/exporter/utils/integrations.ts +110 -0
- package/package.json +3 -3
- package/src/components/Head.tsx +18 -64
- package/src/components/template.tsx +11 -19
- package/src/types.ts +2 -14
- package/src/utils.ts +3 -72
- package/build/react/Foo/index.d.ts +0 -3
- package/exporter/react/Foo/index.tsx +0 -7
package/src/utils.ts
CHANGED
|
@@ -7,13 +7,12 @@
|
|
|
7
7
|
//
|
|
8
8
|
// NOTE: Browserify doesn't work with the mixture of typescript + webpack 5 + SSR
|
|
9
9
|
|
|
10
|
-
import type { Dimensions } from "./types";
|
|
11
10
|
import type { Fields } from "@griddo/core";
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Sanitize a string separated by commas.
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
function cleanCommaSeparated(str: string) {
|
|
17
16
|
return str
|
|
18
17
|
.split(",")
|
|
19
18
|
.map((item) => item.trim())
|
|
@@ -30,7 +29,7 @@ export function cleanCommaSeparated(str: string) {
|
|
|
30
29
|
* @param format Format of the image
|
|
31
30
|
* @returns A composed URL for the Cloudinary or DAM service
|
|
32
31
|
*/
|
|
33
|
-
|
|
32
|
+
function formatImage(
|
|
34
33
|
image: Fields.Image | string,
|
|
35
34
|
width: number,
|
|
36
35
|
height: number,
|
|
@@ -71,72 +70,4 @@ function addCloudinaryParams(image: string, params: string) {
|
|
|
71
70
|
return `https://${head}/${params}${fullId}`;
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
* TODO: JSDoc
|
|
76
|
-
*/
|
|
77
|
-
export function composeAnalytics(
|
|
78
|
-
page: {
|
|
79
|
-
pageContext: {
|
|
80
|
-
siteScript: string;
|
|
81
|
-
page: {
|
|
82
|
-
dimensions: Dimensions;
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
},
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
87
|
-
generateAutomaticDimensions = (page: Record<string, unknown>) => null
|
|
88
|
-
) {
|
|
89
|
-
const {
|
|
90
|
-
pageContext: {
|
|
91
|
-
siteScript: siteScriptBulk,
|
|
92
|
-
page: { dimensions },
|
|
93
|
-
},
|
|
94
|
-
} = page;
|
|
95
|
-
|
|
96
|
-
const analyticsScript = siteScriptBulk ? siteScriptBulk.trim() : "";
|
|
97
|
-
|
|
98
|
-
// Las dimensiones o DataLayer
|
|
99
|
-
const dynamicValuePrefix = "__SCRIPT:";
|
|
100
|
-
const dimensionValues = isObject(dimensions?.values)
|
|
101
|
-
? dimensions?.values
|
|
102
|
-
: {};
|
|
103
|
-
const automaticDimensionValues = generateAutomaticDimensions
|
|
104
|
-
? generateAutomaticDimensions(page)
|
|
105
|
-
: {};
|
|
106
|
-
const allDimensionsValues = {
|
|
107
|
-
...dimensionValues,
|
|
108
|
-
...automaticDimensionValues,
|
|
109
|
-
} as Record<string, string>;
|
|
110
|
-
|
|
111
|
-
const allDimensions = [];
|
|
112
|
-
|
|
113
|
-
for (const dimension of Object.keys(allDimensionsValues)) {
|
|
114
|
-
const dimensionValue = allDimensionsValues[dimension];
|
|
115
|
-
allDimensions.push(
|
|
116
|
-
`"${dimension}":${
|
|
117
|
-
dimensionValue?.startsWith(dynamicValuePrefix)
|
|
118
|
-
? `${dimensionValue.slice(
|
|
119
|
-
dynamicValuePrefix.length,
|
|
120
|
-
dimensionValue.endsWith(";") ? -1 : dimensionValue.length
|
|
121
|
-
)}`
|
|
122
|
-
: `"${dimensionValue}"`
|
|
123
|
-
}`
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const analyticsDimensions = allDimensions.length
|
|
128
|
-
? `{${allDimensions.join(",")}}`
|
|
129
|
-
: null;
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
analyticsScript,
|
|
133
|
-
analyticsDimensions,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Return true if the argument is an object (not null)
|
|
139
|
-
*/
|
|
140
|
-
export function isObject(value: unknown) {
|
|
141
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
142
|
-
}
|
|
73
|
+
export { cleanCommaSeparated, formatImage };
|