@uappi/public-sdk 2.1.0 → 2.1.1
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/components/PaymentHosted/PaymentHosted.vue +1 -1
- package/modules/Api/types/endpoints/third-party/facebook.interfaces.ts +1 -0
- package/modules/Tracking/facebook/events/actions/addToCart.ts +4 -1
- package/modules/Tracking/facebook/events/actions/purchase.ts +28 -6
- package/modules/Tracking/facebook/events/actions/purchaseOrder.ts +16 -3
- package/package.json +1 -1
|
@@ -143,7 +143,7 @@ function handleIframeMessage(event: MessageEvent): void {
|
|
|
143
143
|
case 'UAPPI_PAYMENT_SUCCESS':
|
|
144
144
|
if (props.orderGroup) {
|
|
145
145
|
purchaseOrderAction(props.option.paymentType.code, props.orderGroup);
|
|
146
|
-
facebookPurchaseOrderAction(props.orderGroup
|
|
146
|
+
facebookPurchaseOrderAction(props.orderGroup);
|
|
147
147
|
} else if (cartSnapshot.value) {
|
|
148
148
|
purchaseAction(props.option.paymentType.code, cartSnapshot.value, data.code);
|
|
149
149
|
facebookPurchaseAction(data.id, cartSnapshot.value);
|
|
@@ -16,8 +16,11 @@ export function addToCartAction(
|
|
|
16
16
|
? item.quantity - item.oldQuantity
|
|
17
17
|
: item.quantity;
|
|
18
18
|
|
|
19
|
+
if (quantity <= 0) return;
|
|
20
|
+
|
|
19
21
|
api.thirdParty
|
|
20
22
|
.facebookAddToCart({
|
|
23
|
+
productId: item.product.productId,
|
|
21
24
|
sku: item.product.sku,
|
|
22
25
|
quantity,
|
|
23
26
|
price: item.unitValue,
|
|
@@ -27,7 +30,7 @@ export function addToCartAction(
|
|
|
27
30
|
'track',
|
|
28
31
|
'AddToCart',
|
|
29
32
|
{
|
|
30
|
-
content_ids: [item.product.
|
|
33
|
+
content_ids: [`${item.product.productId}`],
|
|
31
34
|
content_type: 'product',
|
|
32
35
|
value: item.unitValue * quantity,
|
|
33
36
|
currency: 'BRL',
|
|
@@ -1,21 +1,43 @@
|
|
|
1
1
|
import api from '../../../../Api';
|
|
2
|
-
import {
|
|
2
|
+
import { getAllOrderItems } from '../../../utils/cart';
|
|
3
3
|
import { pushFbq } from '../../../utils/pushFbq';
|
|
4
4
|
|
|
5
5
|
import type { CartResponse } from '../../../../Api/types';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* O valor sai do pedido criado: o desconto à vista (ex: Pix) só é aplicado na
|
|
9
|
+
* criação do pedido e não aparece no carrinho
|
|
10
|
+
*/
|
|
11
|
+
function orderTotalValue(orderGroupId: number, cartPayload: CartResponse) {
|
|
12
|
+
return api.customer
|
|
13
|
+
.detailOrderGroup(orderGroupId, { fields: ['values'] })
|
|
14
|
+
.then(order => order.values?.totalValue ?? cartPayload.totalValue)
|
|
15
|
+
.catch(() => cartPayload.totalValue);
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
export function purchaseAction(orderGroupId: number, cartPayload: CartResponse) {
|
|
8
19
|
if (!window.fbq) return;
|
|
9
20
|
|
|
10
|
-
const
|
|
21
|
+
const contentIds = [
|
|
22
|
+
...new Set(
|
|
23
|
+
getAllOrderItems(cartPayload.orders).map(item => `${item.product.productId}`),
|
|
24
|
+
),
|
|
25
|
+
];
|
|
11
26
|
|
|
12
|
-
|
|
13
|
-
.facebookPurchase({ orderGroupId })
|
|
14
|
-
|
|
27
|
+
Promise.all([
|
|
28
|
+
api.thirdParty.facebookPurchase({ orderGroupId }),
|
|
29
|
+
orderTotalValue(orderGroupId, cartPayload),
|
|
30
|
+
])
|
|
31
|
+
.then(([eventId, value]) =>
|
|
15
32
|
pushFbq(
|
|
16
33
|
'track',
|
|
17
34
|
'Purchase',
|
|
18
|
-
{
|
|
35
|
+
{
|
|
36
|
+
value,
|
|
37
|
+
currency: 'BRL',
|
|
38
|
+
content_ids: contentIds,
|
|
39
|
+
content_type: 'product',
|
|
40
|
+
},
|
|
19
41
|
{ eventID: eventId },
|
|
20
42
|
),
|
|
21
43
|
)
|
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
import api from '../../../../Api';
|
|
2
2
|
import { pushFbq } from '../../../utils/pushFbq';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import type { CustomerOrderResponse } from '../../../../Api/types';
|
|
5
|
+
|
|
6
|
+
export function purchaseOrderAction(orderGroup: CustomerOrderResponse) {
|
|
5
7
|
if (!window.fbq) return;
|
|
6
8
|
|
|
9
|
+
const contentIds = [
|
|
10
|
+
...new Set(
|
|
11
|
+
orderGroup.orders.flatMap(order => order.items).map(item => `${item.productId}`),
|
|
12
|
+
),
|
|
13
|
+
];
|
|
14
|
+
|
|
7
15
|
api.thirdParty
|
|
8
|
-
.facebookPurchase({ orderGroupId })
|
|
16
|
+
.facebookPurchase({ orderGroupId: orderGroup.id })
|
|
9
17
|
.then(eventId =>
|
|
10
18
|
pushFbq(
|
|
11
19
|
'track',
|
|
12
20
|
'Purchase',
|
|
13
|
-
{
|
|
21
|
+
{
|
|
22
|
+
value: orderGroup.values?.totalValue ?? 0,
|
|
23
|
+
currency: 'BRL',
|
|
24
|
+
content_ids: contentIds,
|
|
25
|
+
content_type: 'product',
|
|
26
|
+
},
|
|
14
27
|
{ eventID: eventId },
|
|
15
28
|
),
|
|
16
29
|
)
|