@uappi/public-sdk 1.18.0 → 1.20.0

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.
@@ -133,10 +133,10 @@ function handleIframeMessage(event: MessageEvent): void {
133
133
  case 'UAPPI_PAYMENT_SUCCESS':
134
134
  if (cartSnapshot.value) {
135
135
  purchaseAction(props.option.paymentType.code, cartSnapshot.value);
136
+ facebookPurchaseAction(data.id, cartSnapshot.value);
136
137
  } else {
137
138
  console.error('[PaymentHosted] Carrinho indisponível: evento de tracking de compra (purchase) não foi disparado.');
138
139
  }
139
- facebookPurchaseAction(data.id);
140
140
  emit('payment-success', data);
141
141
  break;
142
142
 
@@ -96,7 +96,7 @@ import {
96
96
  facebookAddPaymentInfo,
97
97
  facebookSearch,
98
98
  facebookPurchase,
99
- } from './endpoints/ThirdPartyComposable';
99
+ } from '../Tracking/facebook/requests/ThirdPartyComposable';
100
100
 
101
101
  import { sendMfa, confirmMfa, loginMfa, deleteMFA, mfaSetup } from './endpoints/MFAComposable';
102
102
 
@@ -18,6 +18,7 @@ export type ProductFields =
18
18
  | 'variation'
19
19
  | 'media'
20
20
  | 'price'
21
+ | 'priceRules'
21
22
  | 'bannerGroups'
22
23
  | 'review'
23
24
  | 'status'
@@ -1,14 +1,21 @@
1
1
  import api from '../../../../Api';
2
2
  import { totalValue } from '../../../utils/cart';
3
+ import { pushFbq } from '../../../utils/pushFbq';
3
4
 
4
5
  import type { CartResponse } from '../../../../Api/types';
5
6
 
6
- export function addPaymentInfoAction(
7
- cartPayload: CartResponse
8
- ) {
7
+ export function addPaymentInfoAction(cartPayload: CartResponse) {
8
+ const value = totalValue(cartPayload);
9
+
9
10
  api.thirdParty
10
- .facebookAddPaymentInfo({
11
- totalValue: totalValue(cartPayload),
12
- })
11
+ .facebookAddPaymentInfo({ totalValue: value })
12
+ .then(eventId =>
13
+ pushFbq(
14
+ 'track',
15
+ 'AddPaymentInfo',
16
+ { value, currency: 'BRL' },
17
+ { eventID: eventId },
18
+ ),
19
+ )
13
20
  .catch(() => {});
14
21
  }
@@ -1,22 +1,38 @@
1
1
  import api from '../../../../Api';
2
2
  import { getAddedCartItems } from '../../../utils/cart';
3
+ import { pushFbq } from '../../../utils/pushFbq';
3
4
 
4
5
  import type { UpsertTrackingCartRequest } from '../../../types';
5
6
  import type { CartResponse } from '../../../../Api/types';
6
7
 
7
8
  export function addToCartAction(
8
9
  cartPayload: CartResponse,
9
- upsertPayload?: UpsertTrackingCartRequest
10
+ upsertPayload?: UpsertTrackingCartRequest,
10
11
  ) {
11
12
  getAddedCartItems(cartPayload, upsertPayload).forEach(item => {
13
+ const quantity = item.oldQuantity
14
+ ? item.quantity - item.oldQuantity
15
+ : item.quantity;
16
+
12
17
  api.thirdParty
13
18
  .facebookAddToCart({
14
19
  sku: item.product.sku,
15
- quantity: item.oldQuantity
16
- ? item.quantity - item.oldQuantity
17
- : item.quantity,
20
+ quantity,
18
21
  price: item.unitValue,
19
22
  })
23
+ .then(eventId =>
24
+ pushFbq(
25
+ 'track',
26
+ 'AddToCart',
27
+ {
28
+ content_ids: [item.product.sku],
29
+ content_type: 'product',
30
+ value: item.unitValue * quantity,
31
+ currency: 'BRL',
32
+ },
33
+ { eventID: eventId },
34
+ ),
35
+ )
20
36
  .catch(() => {});
21
37
  });
22
38
  }
@@ -1,7 +1,21 @@
1
1
  import api from '../../../../Api';
2
+ import { totalValue } from '../../../utils/cart';
3
+ import { pushFbq } from '../../../utils/pushFbq';
4
+
5
+ import type { CartResponse } from '../../../../Api/types';
6
+
7
+ export function initiateCheckoutAction(cartPayload: CartResponse) {
8
+ const value = totalValue(cartPayload);
2
9
 
3
- export function initiateCheckoutAction() {
4
10
  api.thirdParty
5
11
  .facebookInitiateCheckout()
12
+ .then(eventId =>
13
+ pushFbq(
14
+ 'track',
15
+ 'InitiateCheckout',
16
+ { value, currency: 'BRL' },
17
+ { eventID: eventId },
18
+ ),
19
+ )
6
20
  .catch(() => {});
7
21
  }
@@ -1,5 +1,21 @@
1
1
  import api from '../../../../Api';
2
+ import { totalValue } from '../../../utils/cart';
3
+ import { pushFbq } from '../../../utils/pushFbq';
2
4
 
3
- export function purchaseAction(orderGroupId: number) {
4
- api.thirdParty.facebookPurchase({ orderGroupId }).catch(() => {});
5
+ import type { CartResponse } from '../../../../Api/types';
6
+
7
+ export function purchaseAction(orderGroupId: number, cartPayload: CartResponse) {
8
+ const value = totalValue(cartPayload);
9
+
10
+ api.thirdParty
11
+ .facebookPurchase({ orderGroupId })
12
+ .then(eventId =>
13
+ pushFbq(
14
+ 'track',
15
+ 'Purchase',
16
+ { value, currency: 'BRL' },
17
+ { eventID: eventId },
18
+ ),
19
+ )
20
+ .catch(() => {});
5
21
  }
@@ -1,10 +1,16 @@
1
1
  import api from '../../../../Api';
2
+ import { pushFbq } from '../../../utils/pushFbq';
2
3
 
3
- export function searchAction(
4
- searchTerm: string,
5
- contentIds: Array<string>
6
- ) {
4
+ export function searchAction(searchTerm: string, contentIds: Array<string>) {
7
5
  api.thirdParty
8
- .facebookSearch({searchTerm, contentIds })
6
+ .facebookSearch({ searchTerm, contentIds })
7
+ .then(eventId =>
8
+ pushFbq(
9
+ 'track',
10
+ 'Search',
11
+ { search_string: searchTerm, content_ids: contentIds },
12
+ { eventID: eventId },
13
+ ),
14
+ )
9
15
  .catch(() => {});
10
16
  }
@@ -1,5 +1,9 @@
1
1
  import api from '../../../../Api';
2
+ import { pushFbq } from '../../../utils/pushFbq';
2
3
 
3
4
  export function pageView() {
4
- api.thirdParty.facebookPageView().catch(() => {});
5
+ api.thirdParty
6
+ .facebookPageView()
7
+ .then(eventId => pushFbq('track', 'PageView', {}, { eventID: eventId }))
8
+ .catch(() => {});
5
9
  }
@@ -1,9 +1,18 @@
1
1
  import api from '../../../../Api';
2
+ import { pushFbq } from '../../../utils/pushFbq';
2
3
 
3
4
  import type { Product } from '../../../../Api/types';
4
5
 
5
6
  export function viewContent(product: Product) {
6
7
  api.thirdParty
7
8
  .facebookViewContent({ productId: product.id })
9
+ .then(eventId =>
10
+ pushFbq(
11
+ 'track',
12
+ 'ViewContent',
13
+ { content_ids: [`${product.id}`], content_type: 'product' },
14
+ { eventID: eventId },
15
+ ),
16
+ )
8
17
  .catch(() => {});
9
18
  }
@@ -1,4 +1,4 @@
1
- import { usePublicApi } from '..';
1
+ import { usePublicApi } from '../../../Api';
2
2
 
3
3
  import type {
4
4
  RedirectRequest,
@@ -8,7 +8,7 @@ import type {
8
8
  FacebookAddPaymentInfoRequest,
9
9
  FacebookSearchRequest,
10
10
  FacebookPurchaseRequest,
11
- } from '../types';
11
+ } from '../../../Api/types';
12
12
 
13
13
  export function oauthRedirect(type: OauthType, payload: RedirectRequest) {
14
14
  return usePublicApi<string, RedirectRequest>({
@@ -19,14 +19,14 @@ export function oauthRedirect(type: OauthType, payload: RedirectRequest) {
19
19
  }
20
20
 
21
21
  export function facebookPageView() {
22
- return usePublicApi<void>({
22
+ return usePublicApi<string>({
23
23
  endpoint: '/third-party/facebook/event/page-view',
24
24
  method: 'POST'
25
25
  });
26
26
  }
27
27
 
28
28
  export function facebookViewContent(payload: FacebookViewContentRequest) {
29
- return usePublicApi<void, FacebookViewContentRequest>({
29
+ return usePublicApi<string, FacebookViewContentRequest>({
30
30
  endpoint: '/third-party/facebook/event/view-content',
31
31
  method: 'POST',
32
32
  payload,
@@ -34,7 +34,7 @@ export function facebookViewContent(payload: FacebookViewContentRequest) {
34
34
  }
35
35
 
36
36
  export function facebookAddToCart(payload: FacebookAddToCartRequest) {
37
- return usePublicApi<void, FacebookAddToCartRequest>({
37
+ return usePublicApi<string, FacebookAddToCartRequest>({
38
38
  endpoint: '/third-party/facebook/event/add-to-cart',
39
39
  method: 'POST',
40
40
  payload,
@@ -42,14 +42,14 @@ export function facebookAddToCart(payload: FacebookAddToCartRequest) {
42
42
  }
43
43
 
44
44
  export function facebookInitiateCheckout() {
45
- return usePublicApi<void>({
45
+ return usePublicApi<string>({
46
46
  endpoint: '/third-party/facebook/event/initiate-checkout',
47
47
  method: 'POST'
48
48
  });
49
49
  }
50
50
 
51
51
  export function facebookAddPaymentInfo(payload: FacebookAddPaymentInfoRequest) {
52
- return usePublicApi<void, FacebookAddPaymentInfoRequest>({
52
+ return usePublicApi<string, FacebookAddPaymentInfoRequest>({
53
53
  endpoint: '/third-party/facebook/event/add-payment-info',
54
54
  method: 'POST',
55
55
  payload,
@@ -57,7 +57,7 @@ export function facebookAddPaymentInfo(payload: FacebookAddPaymentInfoRequest) {
57
57
  }
58
58
 
59
59
  export function facebookPurchase(payload: FacebookPurchaseRequest) {
60
- return usePublicApi<void, FacebookPurchaseRequest>({
60
+ return usePublicApi<string, FacebookPurchaseRequest>({
61
61
  endpoint: '/third-party/facebook/event/purchase',
62
62
  method: 'POST',
63
63
  payload,
@@ -65,7 +65,7 @@ export function facebookPurchase(payload: FacebookPurchaseRequest) {
65
65
  }
66
66
 
67
67
  export function facebookSearch(payload: FacebookSearchRequest) {
68
- return usePublicApi<void, FacebookSearchRequest>({
68
+ return usePublicApi<string, FacebookSearchRequest>({
69
69
  endpoint: '/third-party/facebook/event/search',
70
70
  method: 'POST',
71
71
  payload,
@@ -63,7 +63,7 @@ function viewNotFound() {
63
63
 
64
64
  function beginCheckout(cartPayload: CartResponse) {
65
65
  beginCheckoutAction(cartPayload);
66
- facebookInitiateCheckoutAction();
66
+ facebookInitiateCheckoutAction(cartPayload);
67
67
  }
68
68
 
69
69
  function addPaymentInfo(
@@ -3,6 +3,7 @@ import usePublicApi from '../Api';
3
3
  declare global {
4
4
  interface Window {
5
5
  dataLayer: Array<Record<string, any>>;
6
+ fbq?: (...args: unknown[]) => void;
6
7
  }
7
8
  }
8
9
 
@@ -0,0 +1,5 @@
1
+ export function pushFbq(...args: unknown[]) {
2
+ if (!window.fbq) return;
3
+
4
+ window.fbq(...args);
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uappi/public-sdk",
3
- "version": "1.18.0",
3
+ "version": "1.20.0",
4
4
  "description": "Pacotes públicos para desenvolvimento do ecossistema Uappi",
5
5
  "main": "main.ts",
6
6
  "scripts": {