@uappi/public-sdk 1.2.9 → 1.2.10

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.
Files changed (106) hide show
  1. package/.gitlab-ci.yml +43 -0
  2. package/.vscode/extensions.json +4 -4
  3. package/.vscode/settings.json +6 -6
  4. package/README.md +67 -0
  5. package/components/Animations/ExpandTransition.ts +89 -89
  6. package/components/Animations/index.ts +1 -1
  7. package/components/ColorTheme/ColorTheme.ts +80 -80
  8. package/components/ColorTheme/index.ts +1 -1
  9. package/components/ColorTheme/types.ts +18 -18
  10. package/components/SocialAuth/FacebookAuth/types.ts +2 -2
  11. package/components/SocialAuth/GoogleAuth/types.ts +2 -2
  12. package/components/SocialAuth/index.ts +1 -1
  13. package/components/index.ts +2 -2
  14. package/main.ts +4 -4
  15. package/modules/Api/README.md +469 -469
  16. package/modules/Api/endpoints/CommonComposable.ts +24 -24
  17. package/modules/Api/endpoints/CouponComposable.ts +18 -18
  18. package/modules/Api/endpoints/LoggoutComposable.ts +8 -8
  19. package/modules/Api/endpoints/MFAComposable.ts +43 -43
  20. package/modules/Api/endpoints/PaymentComposable.ts +14 -14
  21. package/modules/Api/endpoints/PublicComposable.ts +8 -8
  22. package/modules/Api/endpoints/TemplateComposable.ts +7 -7
  23. package/modules/Api/endpoints/ThirdPartyComposable.ts +13 -13
  24. package/modules/Api/endpoints/UpsellComposable.ts +17 -17
  25. package/modules/Api/endpoints/VerifyComposable.ts +7 -7
  26. package/modules/Api/endpoints/WalletComposable.ts +36 -36
  27. package/modules/Api/paramsSerializer/encodeWafNormalizer.ts +7 -7
  28. package/modules/Api/types/endpoints/cart/cart.interfaces.ts +161 -161
  29. package/modules/Api/types/endpoints/cart/cart.types.ts +27 -27
  30. package/modules/Api/types/endpoints/common/common.interfaces.ts +21 -21
  31. package/modules/Api/types/endpoints/country/country.types.ts +7502 -7502
  32. package/modules/Api/types/endpoints/coupon/coupon.interfaces.ts +13 -13
  33. package/modules/Api/types/endpoints/discounts/discounts.interfaces.ts +9 -9
  34. package/modules/Api/types/endpoints/mfa/mfa.interfaces.ts +51 -51
  35. package/modules/Api/types/endpoints/payment/payment.interfaces.ts +103 -103
  36. package/modules/Api/types/endpoints/payment/payment.types.ts +27 -27
  37. package/modules/Api/types/endpoints/price/price.interfaces.ts +21 -21
  38. package/modules/Api/types/endpoints/template/template.interfaces.ts +29 -29
  39. package/modules/Api/types/endpoints/third-party/oauth.interfaces.ts +5 -5
  40. package/modules/Api/types/endpoints/upsell/upsell.interfaces.ts +12 -12
  41. package/modules/Api/types/endpoints/wallet/wallet-obsearch.ts +8 -8
  42. package/modules/Api/types/endpoints/wallet/wallet.interfaces.ts +57 -57
  43. package/modules/Api/types/endpoints/zipcode/zipcode.interfaces.ts +23 -23
  44. package/modules/Api/types/index.ts +504 -504
  45. package/modules/Tracking/endpoints/CartComposable.ts +75 -75
  46. package/modules/Tracking/endpoints/CustomerComposable.ts +71 -71
  47. package/modules/Tracking/endpoints/types.ts +11 -11
  48. package/modules/Tracking/events/actions/addPaymentInfo.ts +31 -31
  49. package/modules/Tracking/events/actions/addShippingInfo.ts +27 -27
  50. package/modules/Tracking/events/actions/addToCart.ts +35 -35
  51. package/modules/Tracking/events/actions/beginCheckout.ts +28 -28
  52. package/modules/Tracking/events/actions/customerProfile.ts +36 -36
  53. package/modules/Tracking/events/actions/generateLead.ts +12 -12
  54. package/modules/Tracking/events/actions/login.ts +8 -8
  55. package/modules/Tracking/events/actions/purchase.ts +42 -42
  56. package/modules/Tracking/events/actions/removeFromCart.ts +52 -52
  57. package/modules/Tracking/events/actions/search.ts +8 -8
  58. package/modules/Tracking/events/actions/selectItem.ts +64 -64
  59. package/modules/Tracking/events/actions/selectPromotion.ts +24 -24
  60. package/modules/Tracking/events/actions/shippingCalculation.ts +7 -7
  61. package/modules/Tracking/events/actions/signup.ts +8 -8
  62. package/modules/Tracking/events/actions/upsertToCart.ts +62 -62
  63. package/modules/Tracking/events/views/viewCart.ts +28 -28
  64. package/modules/Tracking/events/views/viewHome.ts +5 -5
  65. package/modules/Tracking/events/views/viewItem.ts +31 -31
  66. package/modules/Tracking/events/views/viewItemList.ts +65 -65
  67. package/modules/Tracking/events/views/viewNotFound.ts +5 -5
  68. package/modules/Tracking/events/views/viewOther.ts +5 -5
  69. package/modules/Tracking/events/views/viewPayment.ts +7 -7
  70. package/modules/Tracking/events/views/viewPromotion.ts +28 -28
  71. package/modules/Tracking/events/views/viewShipping.ts +7 -7
  72. package/modules/Tracking/index.ts +84 -84
  73. package/modules/Tracking/publicApiTracking.ts +35 -35
  74. package/modules/Tracking/types/actions/add-payment-info.interfaces.ts +12 -12
  75. package/modules/Tracking/types/actions/add-shipping-info.interfaces.ts +11 -11
  76. package/modules/Tracking/types/actions/add-to-cart.interfaces.ts +10 -10
  77. package/modules/Tracking/types/actions/begin-checkout.interfaces.ts +12 -12
  78. package/modules/Tracking/types/actions/customer-profile.interfaces.ts +19 -19
  79. package/modules/Tracking/types/actions/file-download.interfaces.ts +4 -4
  80. package/modules/Tracking/types/actions/generate-lead.interfaces.ts +12 -12
  81. package/modules/Tracking/types/actions/login.interfaces.ts +4 -4
  82. package/modules/Tracking/types/actions/purchase.interfaces.ts +18 -18
  83. package/modules/Tracking/types/actions/remove-from-cart.interfaces.ts +10 -10
  84. package/modules/Tracking/types/actions/search.interfaces.ts +4 -4
  85. package/modules/Tracking/types/actions/select-item.interfaces.ts +16 -16
  86. package/modules/Tracking/types/actions/select-promotion.interfaces.ts +8 -8
  87. package/modules/Tracking/types/actions/share.interfaces.ts +4 -4
  88. package/modules/Tracking/types/actions/shipping-calculation.interfaces.ts +3 -3
  89. package/modules/Tracking/types/actions/signup.interfaces.ts +4 -4
  90. package/modules/Tracking/types/event.types.ts +54 -54
  91. package/modules/Tracking/types/index.ts +37 -37
  92. package/modules/Tracking/types/item.interfaces.ts +30 -30
  93. package/modules/Tracking/types/views/view-cart.interfaces.ts +11 -11
  94. package/modules/Tracking/types/views/view-home.interfaces.ts +3 -3
  95. package/modules/Tracking/types/views/view-item-list.interfaces.ts +11 -11
  96. package/modules/Tracking/types/views/view-item.interfaces.ts +15 -15
  97. package/modules/Tracking/types/views/view-not-found.interfaces.ts +3 -3
  98. package/modules/Tracking/types/views/view-other.interfaces.ts +3 -3
  99. package/modules/Tracking/types/views/view-payment.interfaces.ts +3 -3
  100. package/modules/Tracking/types/views/view-promotion.interfaces.ts +8 -8
  101. package/modules/Tracking/types/views/view-shipping.interfaces.ts +3 -3
  102. package/modules/Tracking/utils/cart.ts +100 -100
  103. package/modules/Tracking/utils/pushDatalayer.ts +7 -7
  104. package/modules/index.ts +1 -1
  105. package/package.json +1 -1
  106. package/scripts/release.sh +34 -0
@@ -1,31 +1,31 @@
1
- import { getVariant } from '../../utils/cart';
2
- import { pushDatalayer } from '../../utils/pushDatalayer';
3
-
4
- import type { Product } from '../../../Api/types';
5
-
6
- export function viewItem(product: Product) {
7
- pushDatalayer({
8
- event: 'view_item',
9
- google_tag_params: {
10
- ecomm_category: '',
11
- ecomm_prodid: product.id,
12
- ecomm_pagetype: 'product',
13
- ecomm_totalvalue: product.price?.salePrice || 0,
14
- },
15
- ecommerce: {
16
- currency: 'BRL',
17
- items: [
18
- {
19
- coupon: '',
20
- item_brand: product.brand?.name || '',
21
- item_category: product.mainCategory?.name || '',
22
- item_id: product.id,
23
- item_name: product.name,
24
- item_variant: getVariant(product),
25
- price: product.price?.salePrice || 0,
26
- quantity: 1,
27
- },
28
- ],
29
- },
30
- });
31
- }
1
+ import { getVariant } from '../../utils/cart';
2
+ import { pushDatalayer } from '../../utils/pushDatalayer';
3
+
4
+ import type { Product } from '../../../Api/types';
5
+
6
+ export function viewItem(product: Product) {
7
+ pushDatalayer({
8
+ event: 'view_item',
9
+ google_tag_params: {
10
+ ecomm_category: '',
11
+ ecomm_prodid: product.id,
12
+ ecomm_pagetype: 'product',
13
+ ecomm_totalvalue: product.price?.salePrice || 0,
14
+ },
15
+ ecommerce: {
16
+ currency: 'BRL',
17
+ items: [
18
+ {
19
+ coupon: '',
20
+ item_brand: product.brand?.name || '',
21
+ item_category: product.mainCategory?.name || '',
22
+ item_id: product.id,
23
+ item_name: product.name,
24
+ item_variant: getVariant(product),
25
+ price: product.price?.salePrice || 0,
26
+ quantity: 1,
27
+ },
28
+ ],
29
+ },
30
+ });
31
+ }
@@ -1,65 +1,65 @@
1
- import { getVariant } from '../../utils/cart';
2
- import { pushDatalayer } from '../../utils/pushDatalayer';
3
-
4
- import type {
5
- Showcase,
6
- UrlBrand,
7
- UrlListing,
8
- Search,
9
- } from '../../../Api/types';
10
-
11
- export function viewItemList(page: UrlBrand | UrlListing | Search): void;
12
- export function viewItemList(page: Array<Showcase>): void;
13
-
14
- export function viewItemList(
15
- page: UrlBrand | UrlListing | Array<Showcase> | Search,
16
- ) {
17
- if (Array.isArray(page)) {
18
- page.map(showcase => {
19
- pushDatalayer({
20
- event: 'view_item_list',
21
- ecommerce: {
22
- currency: 'BRL',
23
- item_list_id: showcase.name,
24
- item_list_name: showcase.name,
25
- items: showcase.products.map(showcaseProduct => {
26
- return {
27
- coupon: '',
28
- item_brand: showcaseProduct.brand?.name || '',
29
- item_category: showcaseProduct.mainCategory?.name || '',
30
- item_id: showcaseProduct.id,
31
- item_name: showcaseProduct.name,
32
- item_variant: getVariant(showcaseProduct),
33
- price: showcaseProduct.price?.salePrice || 0,
34
- quantity: 1,
35
- };
36
- }),
37
- },
38
- });
39
- });
40
- return;
41
- }
42
-
43
- pushDatalayer({
44
- event: 'view_item_list',
45
- ecommerce: {
46
- currency: 'BRL',
47
- item_list_id:
48
- page.type === 'search' ? 'Search Results' : page.entity.name,
49
- item_list_name:
50
- page.type === 'search' ? 'Search Results' : page.entity.name,
51
- items: page.content.registers.map(pageItem => {
52
- return {
53
- coupon: '',
54
- item_brand: pageItem.brand?.name || '',
55
- item_category: pageItem.mainCategory?.name || '',
56
- item_id: pageItem.id,
57
- item_name: pageItem.name,
58
- item_variant: getVariant(pageItem),
59
- price: pageItem.price?.salePrice || 0,
60
- quantity: 1,
61
- };
62
- }),
63
- },
64
- });
65
- }
1
+ import { getVariant } from '../../utils/cart';
2
+ import { pushDatalayer } from '../../utils/pushDatalayer';
3
+
4
+ import type {
5
+ Showcase,
6
+ UrlBrand,
7
+ UrlListing,
8
+ Search,
9
+ } from '../../../Api/types';
10
+
11
+ export function viewItemList(page: UrlBrand | UrlListing | Search): void;
12
+ export function viewItemList(page: Array<Showcase>): void;
13
+
14
+ export function viewItemList(
15
+ page: UrlBrand | UrlListing | Array<Showcase> | Search,
16
+ ) {
17
+ if (Array.isArray(page)) {
18
+ page.map(showcase => {
19
+ pushDatalayer({
20
+ event: 'view_item_list',
21
+ ecommerce: {
22
+ currency: 'BRL',
23
+ item_list_id: showcase.name,
24
+ item_list_name: showcase.name,
25
+ items: showcase.products.map(showcaseProduct => {
26
+ return {
27
+ coupon: '',
28
+ item_brand: showcaseProduct.brand?.name || '',
29
+ item_category: showcaseProduct.mainCategory?.name || '',
30
+ item_id: showcaseProduct.id,
31
+ item_name: showcaseProduct.name,
32
+ item_variant: getVariant(showcaseProduct),
33
+ price: showcaseProduct.price?.salePrice || 0,
34
+ quantity: 1,
35
+ };
36
+ }),
37
+ },
38
+ });
39
+ });
40
+ return;
41
+ }
42
+
43
+ pushDatalayer({
44
+ event: 'view_item_list',
45
+ ecommerce: {
46
+ currency: 'BRL',
47
+ item_list_id:
48
+ page.type === 'search' ? 'Search Results' : page.entity.name,
49
+ item_list_name:
50
+ page.type === 'search' ? 'Search Results' : page.entity.name,
51
+ items: page.content.registers.map(pageItem => {
52
+ return {
53
+ coupon: '',
54
+ item_brand: pageItem.brand?.name || '',
55
+ item_category: pageItem.mainCategory?.name || '',
56
+ item_id: pageItem.id,
57
+ item_name: pageItem.name,
58
+ item_variant: getVariant(pageItem),
59
+ price: pageItem.price?.salePrice || 0,
60
+ quantity: 1,
61
+ };
62
+ }),
63
+ },
64
+ });
65
+ }
@@ -1,5 +1,5 @@
1
- import { pushDatalayer } from '../../utils/pushDatalayer';
2
-
3
- export function viewNotFound() {
4
- pushDatalayer({ event: 'view_not_found' });
5
- }
1
+ import { pushDatalayer } from '../../utils/pushDatalayer';
2
+
3
+ export function viewNotFound() {
4
+ pushDatalayer({ event: 'view_not_found' });
5
+ }
@@ -1,5 +1,5 @@
1
- import { pushDatalayer } from '../../utils/pushDatalayer';
2
-
3
- export function viewOther() {
4
- pushDatalayer({ event: 'view_other' });
5
- }
1
+ import { pushDatalayer } from '../../utils/pushDatalayer';
2
+
3
+ export function viewOther() {
4
+ pushDatalayer({ event: 'view_other' });
5
+ }
@@ -1,7 +1,7 @@
1
- import { pushDatalayer } from '../../utils/pushDatalayer';
2
-
3
- export function viewPayment() {
4
- pushDatalayer({
5
- event: 'view_payment',
6
- });
7
- }
1
+ import { pushDatalayer } from '../../utils/pushDatalayer';
2
+
3
+ export function viewPayment() {
4
+ pushDatalayer({
5
+ event: 'view_payment',
6
+ });
7
+ }
@@ -1,28 +1,28 @@
1
- import { pushDatalayer } from '../../utils/pushDatalayer';
2
-
3
- import type { ViewPromotion } from '../../types';
4
- import type { Banners } from '../../../Api/types';
5
-
6
- export function viewPromotion<AdditionalParameters>(
7
- bannerGroups: Array<Banners<AdditionalParameters>>,
8
- ) {
9
- bannerGroups.forEach(bannerGroup => {
10
- pushDatalayer({
11
- event: 'view_promotion',
12
- ecommerce: {
13
- items: [
14
- ...bannerGroup.banners.map((banner, bannerIndex) => {
15
- return {
16
- promotion_id: banner.id,
17
- promotion_name:
18
- 'Banners' as ViewPromotion['ecommerce']['items'][0]['promotion_name'],
19
- creative_name: `${banner.scheduling?.startDate.slice(0, 10)}-${banner.name.replaceAll(' ', '-')}`,
20
- creative_slot: bannerIndex + 1,
21
- index: bannerIndex + 1,
22
- };
23
- }),
24
- ],
25
- },
26
- });
27
- });
28
- }
1
+ import { pushDatalayer } from '../../utils/pushDatalayer';
2
+
3
+ import type { ViewPromotion } from '../../types';
4
+ import type { Banners } from '../../../Api/types';
5
+
6
+ export function viewPromotion<AdditionalParameters>(
7
+ bannerGroups: Array<Banners<AdditionalParameters>>,
8
+ ) {
9
+ bannerGroups.forEach(bannerGroup => {
10
+ pushDatalayer({
11
+ event: 'view_promotion',
12
+ ecommerce: {
13
+ items: [
14
+ ...bannerGroup.banners.map((banner, bannerIndex) => {
15
+ return {
16
+ promotion_id: banner.id,
17
+ promotion_name:
18
+ 'Banners' as ViewPromotion['ecommerce']['items'][0]['promotion_name'],
19
+ creative_name: `${banner.scheduling?.startDate.slice(0, 10)}-${banner.name.replaceAll(' ', '-')}`,
20
+ creative_slot: bannerIndex + 1,
21
+ index: bannerIndex + 1,
22
+ };
23
+ }),
24
+ ],
25
+ },
26
+ });
27
+ });
28
+ }
@@ -1,7 +1,7 @@
1
- import { pushDatalayer } from '../../utils/pushDatalayer';
2
-
3
- export function viewShipping() {
4
- pushDatalayer({
5
- event: 'view_shipping',
6
- });
7
- }
1
+ import { pushDatalayer } from '../../utils/pushDatalayer';
2
+
3
+ export function viewShipping() {
4
+ pushDatalayer({
5
+ event: 'view_shipping',
6
+ });
7
+ }
@@ -1,84 +1,84 @@
1
- import { listBanners } from './endpoints/BannerComposable';
2
- import {
3
- addProduct,
4
- deleteProduct,
5
- selectShipment,
6
- shipmentQuote,
7
- upsertProduct,
8
- buy,
9
- listDetail,
10
- } from './endpoints/CartComposable';
11
- import {
12
- detail,
13
- signinByDocument,
14
- signinByEmail,
15
- signup,
16
- addNewsletter,
17
- } from './endpoints/CustomerComposable';
18
- import { listShipmentQuoteProduct } from './endpoints/ProductQuoteShipment';
19
- import { getSearch } from './endpoints/SearchComposable';
20
- import { listShowcase } from './endpoints/ShowcaseComposable';
21
- import { getUrl } from './endpoints/UrlComposable';
22
- import { addPaymentInfoAction as addPaymentInfo } from './events/actions/addPaymentInfo';
23
- import { beginCheckoutAction as beginCheckout } from './events/actions/beginCheckout';
24
- import { searchAction as search } from './events/actions/search';
25
- import { selectItemAction as selectItem } from './events/actions/selectItem';
26
- import { selectPromotionAction as selectPromotion } from './events/actions/selectPromotion';
27
- import { viewHome } from './events/views/viewHome';
28
- import { viewNotFound } from './events/views/viewNotFound';
29
- import { viewOther } from './events/views/viewOther';
30
- import { viewPayment } from './events/views/viewPayment';
31
- import { viewShipping } from './events/views/viewShipping';
32
- import publicApiTracking from './publicApiTracking';
33
-
34
- const view = {
35
- viewHome,
36
- viewShipping,
37
- viewPayment,
38
- viewOther,
39
- viewNotFound,
40
- };
41
-
42
- const cart = {
43
- listDetail,
44
- addProduct,
45
- deleteProduct,
46
- selectShipment,
47
- shipmentQuote,
48
- upsertProduct,
49
- beginCheckout,
50
- addPaymentInfo,
51
- buy,
52
- };
53
-
54
- const customer = {
55
- detail,
56
- signinByDocument,
57
- signinByEmail,
58
- signup,
59
- addNewsletter,
60
- };
61
-
62
- const product = {
63
- listShipmentQuoteProduct,
64
- getUrl,
65
- search,
66
- selectItem,
67
- getSearch,
68
- };
69
-
70
- const customization = {
71
- listShowcase,
72
- listBanners,
73
- selectPromotion,
74
- };
75
-
76
- export { publicApiTracking, cart, customer, product, view, customization };
77
- export default {
78
- publicApiTracking,
79
- view,
80
- cart,
81
- customer,
82
- product,
83
- customization,
84
- };
1
+ import { listBanners } from './endpoints/BannerComposable';
2
+ import {
3
+ addProduct,
4
+ deleteProduct,
5
+ selectShipment,
6
+ shipmentQuote,
7
+ upsertProduct,
8
+ buy,
9
+ listDetail,
10
+ } from './endpoints/CartComposable';
11
+ import {
12
+ detail,
13
+ signinByDocument,
14
+ signinByEmail,
15
+ signup,
16
+ addNewsletter,
17
+ } from './endpoints/CustomerComposable';
18
+ import { listShipmentQuoteProduct } from './endpoints/ProductQuoteShipment';
19
+ import { getSearch } from './endpoints/SearchComposable';
20
+ import { listShowcase } from './endpoints/ShowcaseComposable';
21
+ import { getUrl } from './endpoints/UrlComposable';
22
+ import { addPaymentInfoAction as addPaymentInfo } from './events/actions/addPaymentInfo';
23
+ import { beginCheckoutAction as beginCheckout } from './events/actions/beginCheckout';
24
+ import { searchAction as search } from './events/actions/search';
25
+ import { selectItemAction as selectItem } from './events/actions/selectItem';
26
+ import { selectPromotionAction as selectPromotion } from './events/actions/selectPromotion';
27
+ import { viewHome } from './events/views/viewHome';
28
+ import { viewNotFound } from './events/views/viewNotFound';
29
+ import { viewOther } from './events/views/viewOther';
30
+ import { viewPayment } from './events/views/viewPayment';
31
+ import { viewShipping } from './events/views/viewShipping';
32
+ import publicApiTracking from './publicApiTracking';
33
+
34
+ const view = {
35
+ viewHome,
36
+ viewShipping,
37
+ viewPayment,
38
+ viewOther,
39
+ viewNotFound,
40
+ };
41
+
42
+ const cart = {
43
+ listDetail,
44
+ addProduct,
45
+ deleteProduct,
46
+ selectShipment,
47
+ shipmentQuote,
48
+ upsertProduct,
49
+ beginCheckout,
50
+ addPaymentInfo,
51
+ buy,
52
+ };
53
+
54
+ const customer = {
55
+ detail,
56
+ signinByDocument,
57
+ signinByEmail,
58
+ signup,
59
+ addNewsletter,
60
+ };
61
+
62
+ const product = {
63
+ listShipmentQuoteProduct,
64
+ getUrl,
65
+ search,
66
+ selectItem,
67
+ getSearch,
68
+ };
69
+
70
+ const customization = {
71
+ listShowcase,
72
+ listBanners,
73
+ selectPromotion,
74
+ };
75
+
76
+ export { publicApiTracking, cart, customer, product, view, customization };
77
+ export default {
78
+ publicApiTracking,
79
+ view,
80
+ cart,
81
+ customer,
82
+ product,
83
+ customization,
84
+ };
@@ -1,35 +1,35 @@
1
- import usePublicApi from '../Api';
2
-
3
- declare global {
4
- interface Window {
5
- dataLayer: Array<Record<string, any>>;
6
- }
7
- }
8
-
9
- export default {
10
- async install() {
11
- if (import.meta.env.PROD) return;
12
-
13
- await usePublicApi.customization
14
- .listTemplateSettings(import.meta.env.VITE_BASE)
15
- .then(data => {
16
- const gtmApp = data.apps.find(app => app.code === 'google-tag-manager');
17
- if (!gtmApp) return;
18
-
19
- this.createGtm(gtmApp.settings['google-tag-manager-id']);
20
- });
21
- },
22
-
23
- createGtm(tagId: string) {
24
- const gtmTag = document.createElement('script');
25
- gtmTag.innerHTML = `
26
- (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
27
- new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
28
- j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
29
- 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
30
- })(window,document,'script','dataLayer','${tagId}');
31
- `;
32
-
33
- document.head.appendChild(gtmTag);
34
- },
35
- };
1
+ import usePublicApi from '../Api';
2
+
3
+ declare global {
4
+ interface Window {
5
+ dataLayer: Array<Record<string, any>>;
6
+ }
7
+ }
8
+
9
+ export default {
10
+ async install() {
11
+ if (import.meta.env.PROD) return;
12
+
13
+ await usePublicApi.customization
14
+ .listTemplateSettings(import.meta.env.VITE_BASE)
15
+ .then(data => {
16
+ const gtmApp = data.apps.find(app => app.code === 'google-tag-manager');
17
+ if (!gtmApp) return;
18
+
19
+ this.createGtm(gtmApp.settings['google-tag-manager-id']);
20
+ });
21
+ },
22
+
23
+ createGtm(tagId: string) {
24
+ const gtmTag = document.createElement('script');
25
+ gtmTag.innerHTML = `
26
+ (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
27
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
28
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
29
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
30
+ })(window,document,'script','dataLayer','${tagId}');
31
+ `;
32
+
33
+ document.head.appendChild(gtmTag);
34
+ },
35
+ };
@@ -1,12 +1,12 @@
1
- import type { Item } from '..';
2
-
3
- export interface AddPaymentInfo {
4
- event: 'add_payment_info';
5
- ecommerce: {
6
- currency: 'BRL';
7
- value: number;
8
- coupon: string;
9
- payment_type: string;
10
- items: Array<Item>;
11
- };
12
- }
1
+ import type { Item } from '..';
2
+
3
+ export interface AddPaymentInfo {
4
+ event: 'add_payment_info';
5
+ ecommerce: {
6
+ currency: 'BRL';
7
+ value: number;
8
+ coupon: string;
9
+ payment_type: string;
10
+ items: Array<Item>;
11
+ };
12
+ }
@@ -1,11 +1,11 @@
1
- import type { Item } from '..';
2
-
3
- export interface AddShippingInfo {
4
- event: 'add_shipping_info';
5
- ecommerce: {
6
- currency: 'BRL';
7
- value: number;
8
- coupon: string;
9
- items: Array<Item>;
10
- };
11
- }
1
+ import type { Item } from '..';
2
+
3
+ export interface AddShippingInfo {
4
+ event: 'add_shipping_info';
5
+ ecommerce: {
6
+ currency: 'BRL';
7
+ value: number;
8
+ coupon: string;
9
+ items: Array<Item>;
10
+ };
11
+ }
@@ -1,10 +1,10 @@
1
- import type { Item } from '..';
2
-
3
- export interface AddToCart {
4
- event: 'add_to_cart';
5
- ecommerce: {
6
- currency: 'BRL';
7
- value: number;
8
- items: Array<Item>;
9
- };
10
- }
1
+ import type { Item } from '..';
2
+
3
+ export interface AddToCart {
4
+ event: 'add_to_cart';
5
+ ecommerce: {
6
+ currency: 'BRL';
7
+ value: number;
8
+ items: Array<Item>;
9
+ };
10
+ }
@@ -1,12 +1,12 @@
1
- import type { Item } from '..';
2
-
3
- export interface BeginCheckout {
4
- event: 'begin_checkout';
5
- ecommerce: {
6
- shipping_tier: 'Ground';
7
- currency: 'BRL';
8
- value: number;
9
- coupon: string;
10
- items: Array<Item>;
11
- };
12
- }
1
+ import type { Item } from '..';
2
+
3
+ export interface BeginCheckout {
4
+ event: 'begin_checkout';
5
+ ecommerce: {
6
+ shipping_tier: 'Ground';
7
+ currency: 'BRL';
8
+ value: number;
9
+ coupon: string;
10
+ items: Array<Item>;
11
+ };
12
+ }