@gem-sdk/core 1.0.3 → 1.0.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.
- package/dist/cjs/helpers/{fpixel.js → tracking/fpixel.js} +0 -0
- package/dist/cjs/helpers/tracking/gtag.js +94 -0
- package/dist/cjs/helpers/{tiktokpixel.js → tracking/tiktokpixel.js} +0 -0
- package/dist/cjs/index.js +3 -3
- package/dist/esm/helpers/{fpixel.js → tracking/fpixel.js} +0 -0
- package/dist/esm/helpers/tracking/gtag.js +88 -0
- package/dist/esm/helpers/{tiktokpixel.js → tracking/tiktokpixel.js} +0 -0
- package/dist/esm/index.js +3 -3
- package/dist/types/index.d.ts +22 -0
- package/package.json +1 -1
- package/dist/cjs/helpers/gtag.js +0 -48
- package/dist/esm/helpers/gtag.js +0 -45
|
File without changes
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
|
4
|
+
const pageview = (url, trackingId) => {
|
|
5
|
+
// GA 4
|
|
6
|
+
if (window.gtag && trackingId) {
|
|
7
|
+
window.gtag('config', trackingId, {
|
|
8
|
+
page_path: url,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
// GA 3
|
|
12
|
+
if (window.ga) {
|
|
13
|
+
window.ga('send', 'pageview', url);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/** Addition to cart events
|
|
17
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
|
|
18
|
+
*/
|
|
19
|
+
const addToCart = (product) => {
|
|
20
|
+
// GA 3
|
|
21
|
+
if (!window.ga || !product) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
window.ga('ec:addProduct', { ...product, id: product.sku });
|
|
25
|
+
window.ga('ec:setAction', 'add');
|
|
26
|
+
window.ga('send', 'event', {
|
|
27
|
+
eventCategory: 'EnhancedEcommerce',
|
|
28
|
+
eventAction: 'Added Product',
|
|
29
|
+
nonInteraction: true,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
/** Product clicked event
|
|
33
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-click
|
|
34
|
+
*/
|
|
35
|
+
const productClick = (product) => {
|
|
36
|
+
if (!window.ga) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
ga('ec:addProduct', {
|
|
40
|
+
id: product.id,
|
|
41
|
+
name: product.name,
|
|
42
|
+
category: product.category,
|
|
43
|
+
brand: product.brand,
|
|
44
|
+
variant: product.variant,
|
|
45
|
+
});
|
|
46
|
+
ga('ec:setAction', 'click');
|
|
47
|
+
ga('send', 'event', {
|
|
48
|
+
eventAction: 'Click',
|
|
49
|
+
eventCategory: 'Product',
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
/** Product viewed event
|
|
53
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-actvities
|
|
54
|
+
*/
|
|
55
|
+
const productDetail = (product) => {
|
|
56
|
+
if (!product || !window.ga)
|
|
57
|
+
return;
|
|
58
|
+
ga('ec:addProduct', {
|
|
59
|
+
brand: product.brand,
|
|
60
|
+
category: product.category,
|
|
61
|
+
id: product.id,
|
|
62
|
+
name: product.name,
|
|
63
|
+
variant: product.variant,
|
|
64
|
+
});
|
|
65
|
+
ga('ec:setAction', 'detail');
|
|
66
|
+
ga('send', 'event', {
|
|
67
|
+
eventAction: 'Detail',
|
|
68
|
+
eventCategory: 'Ecommerce',
|
|
69
|
+
nonInteraction: 1,
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
/** Removal from cart events
|
|
73
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
|
|
74
|
+
*/
|
|
75
|
+
const removeFromCart = (product, price) => {
|
|
76
|
+
if (!product || !window.ga)
|
|
77
|
+
return;
|
|
78
|
+
ga('ec:addProduct', {
|
|
79
|
+
id: product.id,
|
|
80
|
+
name: product.name,
|
|
81
|
+
price,
|
|
82
|
+
});
|
|
83
|
+
ga('ec:setAction', 'remove');
|
|
84
|
+
ga('send', 'event', {
|
|
85
|
+
eventAction: 'Click',
|
|
86
|
+
eventCategory: 'Remove from cart',
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
exports.addToCart = addToCart;
|
|
91
|
+
exports.pageview = pageview;
|
|
92
|
+
exports.productClick = productClick;
|
|
93
|
+
exports.productDetail = productDetail;
|
|
94
|
+
exports.removeFromCart = removeFromCart;
|
|
File without changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -43,9 +43,9 @@ var colors = require('./helpers/colors.js');
|
|
|
43
43
|
var typography = require('./helpers/typography.js');
|
|
44
44
|
var radius = require('./helpers/radius.js');
|
|
45
45
|
var product = require('./helpers/product.js');
|
|
46
|
-
var fpixel = require('./helpers/fpixel.js');
|
|
47
|
-
var gtag = require('./helpers/gtag.js');
|
|
48
|
-
var tiktokpixel = require('./helpers/tiktokpixel.js');
|
|
46
|
+
var fpixel = require('./helpers/tracking/fpixel.js');
|
|
47
|
+
var gtag = require('./helpers/tracking/gtag.js');
|
|
48
|
+
var tiktokpixel = require('./helpers/tracking/tiktokpixel.js');
|
|
49
49
|
var useAddToCart = require('./hooks/cart/use-add-to-cart.js');
|
|
50
50
|
var useCartData = require('./hooks/cart/use-cart-data.js');
|
|
51
51
|
var useCartDiscountCodesUpdate = require('./hooks/cart/use-cart-discount-codes-update.js');
|
|
File without changes
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
|
2
|
+
const pageview = (url, trackingId) => {
|
|
3
|
+
// GA 4
|
|
4
|
+
if (window.gtag && trackingId) {
|
|
5
|
+
window.gtag('config', trackingId, {
|
|
6
|
+
page_path: url,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
// GA 3
|
|
10
|
+
if (window.ga) {
|
|
11
|
+
window.ga('send', 'pageview', url);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/** Addition to cart events
|
|
15
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
|
|
16
|
+
*/
|
|
17
|
+
const addToCart = (product) => {
|
|
18
|
+
// GA 3
|
|
19
|
+
if (!window.ga || !product) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
window.ga('ec:addProduct', { ...product, id: product.sku });
|
|
23
|
+
window.ga('ec:setAction', 'add');
|
|
24
|
+
window.ga('send', 'event', {
|
|
25
|
+
eventCategory: 'EnhancedEcommerce',
|
|
26
|
+
eventAction: 'Added Product',
|
|
27
|
+
nonInteraction: true,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
/** Product clicked event
|
|
31
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-click
|
|
32
|
+
*/
|
|
33
|
+
const productClick = (product) => {
|
|
34
|
+
if (!window.ga) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
ga('ec:addProduct', {
|
|
38
|
+
id: product.id,
|
|
39
|
+
name: product.name,
|
|
40
|
+
category: product.category,
|
|
41
|
+
brand: product.brand,
|
|
42
|
+
variant: product.variant,
|
|
43
|
+
});
|
|
44
|
+
ga('ec:setAction', 'click');
|
|
45
|
+
ga('send', 'event', {
|
|
46
|
+
eventAction: 'Click',
|
|
47
|
+
eventCategory: 'Product',
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
/** Product viewed event
|
|
51
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-actvities
|
|
52
|
+
*/
|
|
53
|
+
const productDetail = (product) => {
|
|
54
|
+
if (!product || !window.ga)
|
|
55
|
+
return;
|
|
56
|
+
ga('ec:addProduct', {
|
|
57
|
+
brand: product.brand,
|
|
58
|
+
category: product.category,
|
|
59
|
+
id: product.id,
|
|
60
|
+
name: product.name,
|
|
61
|
+
variant: product.variant,
|
|
62
|
+
});
|
|
63
|
+
ga('ec:setAction', 'detail');
|
|
64
|
+
ga('send', 'event', {
|
|
65
|
+
eventAction: 'Detail',
|
|
66
|
+
eventCategory: 'Ecommerce',
|
|
67
|
+
nonInteraction: 1,
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
/** Removal from cart events
|
|
71
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
|
|
72
|
+
*/
|
|
73
|
+
const removeFromCart = (product, price) => {
|
|
74
|
+
if (!product || !window.ga)
|
|
75
|
+
return;
|
|
76
|
+
ga('ec:addProduct', {
|
|
77
|
+
id: product.id,
|
|
78
|
+
name: product.name,
|
|
79
|
+
price,
|
|
80
|
+
});
|
|
81
|
+
ga('ec:setAction', 'remove');
|
|
82
|
+
ga('send', 'event', {
|
|
83
|
+
eventAction: 'Click',
|
|
84
|
+
eventCategory: 'Remove from cart',
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export { addToCart, pageview, productClick, productDetail, removeFromCart };
|
|
File without changes
|
package/dist/esm/index.js
CHANGED
|
@@ -41,11 +41,11 @@ export { getGlobalColorCSSProp, getGlobalColorClass, getGlobalColorResponsiveCla
|
|
|
41
41
|
export { genTypoClass } from './helpers/typography.js';
|
|
42
42
|
export { composeRadius, getCustomRadius, getRadiusCSSFromGlobal, getRadiusStyleActiveState } from './helpers/radius.js';
|
|
43
43
|
export { getSelectedVariant, parseSelectedOption } from './helpers/product.js';
|
|
44
|
-
import * as fpixel from './helpers/fpixel.js';
|
|
44
|
+
import * as fpixel from './helpers/tracking/fpixel.js';
|
|
45
45
|
export { fpixel };
|
|
46
|
-
import * as gtag from './helpers/gtag.js';
|
|
46
|
+
import * as gtag from './helpers/tracking/gtag.js';
|
|
47
47
|
export { gtag };
|
|
48
|
-
import * as tiktokpixel from './helpers/tiktokpixel.js';
|
|
48
|
+
import * as tiktokpixel from './helpers/tracking/tiktokpixel.js';
|
|
49
49
|
export { tiktokpixel };
|
|
50
50
|
export { useAddToCart } from './hooks/cart/use-add-to-cart.js';
|
|
51
51
|
export { useCartData } from './hooks/cart/use-cart-data.js';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6586,6 +6586,7 @@ type GlobalSwatchesData = {
|
|
|
6586
6586
|
type ProductInputAnalytic = {
|
|
6587
6587
|
id: string;
|
|
6588
6588
|
name: string;
|
|
6589
|
+
sku?: string;
|
|
6589
6590
|
category?: string;
|
|
6590
6591
|
quantity?: number;
|
|
6591
6592
|
price?: number;
|
|
@@ -7162,13 +7163,34 @@ declare namespace fpixel {
|
|
|
7162
7163
|
}
|
|
7163
7164
|
|
|
7164
7165
|
declare const pageview: (url: string, trackingId?: string | null) => void;
|
|
7166
|
+
/** Addition to cart events
|
|
7167
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
|
|
7168
|
+
*/
|
|
7165
7169
|
declare const addToCart$1: (product: ProductInputAnalytic) => void;
|
|
7170
|
+
/** Product clicked event
|
|
7171
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-click
|
|
7172
|
+
*/
|
|
7173
|
+
declare const productClick: (product: ProductInputAnalytic) => void;
|
|
7174
|
+
/** Product viewed event
|
|
7175
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-actvities
|
|
7176
|
+
*/
|
|
7177
|
+
declare const productDetail: (product: ProductInputAnalytic) => void;
|
|
7178
|
+
/** Removal from cart events
|
|
7179
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
|
|
7180
|
+
*/
|
|
7181
|
+
declare const removeFromCart: (product: ProductInputAnalytic, price: number) => void;
|
|
7166
7182
|
|
|
7167
7183
|
declare const gtag_pageview: typeof pageview;
|
|
7184
|
+
declare const gtag_productClick: typeof productClick;
|
|
7185
|
+
declare const gtag_productDetail: typeof productDetail;
|
|
7186
|
+
declare const gtag_removeFromCart: typeof removeFromCart;
|
|
7168
7187
|
declare namespace gtag {
|
|
7169
7188
|
export {
|
|
7170
7189
|
gtag_pageview as pageview,
|
|
7171
7190
|
addToCart$1 as addToCart,
|
|
7191
|
+
gtag_productClick as productClick,
|
|
7192
|
+
gtag_productDetail as productDetail,
|
|
7193
|
+
gtag_removeFromCart as removeFromCart,
|
|
7172
7194
|
};
|
|
7173
7195
|
}
|
|
7174
7196
|
|
package/package.json
CHANGED
package/dist/cjs/helpers/gtag.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
|
4
|
-
const pageview = (url, trackingId) => {
|
|
5
|
-
// GA 4
|
|
6
|
-
if (window.gtag && trackingId) {
|
|
7
|
-
window.gtag('config', trackingId, {
|
|
8
|
-
page_path: url,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
// GA 3
|
|
12
|
-
if (window.ga) {
|
|
13
|
-
window.ga('send', 'pageview', url);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const addToCart = (product) => {
|
|
17
|
-
// GA 3
|
|
18
|
-
if (window.ga) {
|
|
19
|
-
window.ga('ec:addProduct', product);
|
|
20
|
-
window.ga('send', 'event', {
|
|
21
|
-
eventCategory: 'EnhancedEcommerce',
|
|
22
|
-
eventAction: 'Added Product',
|
|
23
|
-
eventLabel: undefined,
|
|
24
|
-
nonInteraction: true,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
// GA 4
|
|
28
|
-
if (window.gtag) {
|
|
29
|
-
window.gtag('event', 'add_to_cart', {
|
|
30
|
-
currency: product.currency,
|
|
31
|
-
value: product.price,
|
|
32
|
-
items: [
|
|
33
|
-
{
|
|
34
|
-
currency: product.currency,
|
|
35
|
-
item_brand: product.brand,
|
|
36
|
-
item_id: product.id,
|
|
37
|
-
item_name: product.name,
|
|
38
|
-
item_variant: product.variant,
|
|
39
|
-
item_category: product.category,
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
debug_mode: true,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
exports.addToCart = addToCart;
|
|
48
|
-
exports.pageview = pageview;
|
package/dist/esm/helpers/gtag.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
|
2
|
-
const pageview = (url, trackingId) => {
|
|
3
|
-
// GA 4
|
|
4
|
-
if (window.gtag && trackingId) {
|
|
5
|
-
window.gtag('config', trackingId, {
|
|
6
|
-
page_path: url,
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
// GA 3
|
|
10
|
-
if (window.ga) {
|
|
11
|
-
window.ga('send', 'pageview', url);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
const addToCart = (product) => {
|
|
15
|
-
// GA 3
|
|
16
|
-
if (window.ga) {
|
|
17
|
-
window.ga('ec:addProduct', product);
|
|
18
|
-
window.ga('send', 'event', {
|
|
19
|
-
eventCategory: 'EnhancedEcommerce',
|
|
20
|
-
eventAction: 'Added Product',
|
|
21
|
-
eventLabel: undefined,
|
|
22
|
-
nonInteraction: true,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
// GA 4
|
|
26
|
-
if (window.gtag) {
|
|
27
|
-
window.gtag('event', 'add_to_cart', {
|
|
28
|
-
currency: product.currency,
|
|
29
|
-
value: product.price,
|
|
30
|
-
items: [
|
|
31
|
-
{
|
|
32
|
-
currency: product.currency,
|
|
33
|
-
item_brand: product.brand,
|
|
34
|
-
item_id: product.id,
|
|
35
|
-
item_name: product.name,
|
|
36
|
-
item_variant: product.variant,
|
|
37
|
-
item_category: product.category,
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
debug_mode: true,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export { addToCart, pageview };
|