@gem-sdk/core 1.0.0 → 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.
@@ -20,10 +20,10 @@ const createShopStoreProvider = (data) => create.createStore((set) => ({
20
20
  set({ swatches });
21
21
  },
22
22
  changeStorefrontInfo: ({ url, token }) => {
23
- set((prev) => ({
24
- storefrontUrl: url ?? prev.storefrontUrl,
25
- storefrontToken: token ?? prev.storefrontToken,
26
- }));
23
+ set({
24
+ storefrontUrl: url,
25
+ storefrontToken: token,
26
+ });
27
27
  },
28
28
  }));
29
29
  const ShopProvider = ({ children, addons, storeOption, queryOption, ...passProps }) => {
@@ -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;
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');
@@ -18,10 +18,10 @@ const createShopStoreProvider = (data) => createStore((set) => ({
18
18
  set({ swatches });
19
19
  },
20
20
  changeStorefrontInfo: ({ url, token }) => {
21
- set((prev) => ({
22
- storefrontUrl: url ?? prev.storefrontUrl,
23
- storefrontToken: token ?? prev.storefrontToken,
24
- }));
21
+ set({
22
+ storefrontUrl: url,
23
+ storefrontToken: token,
24
+ });
25
25
  },
26
26
  }));
27
27
  const ShopProvider = ({ children, addons, storeOption, queryOption, ...passProps }) => {
@@ -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 };
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';