Skip to content

Commit

Permalink
Get cart items from graphql definition (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
indykoning authored Jun 11, 2024
1 parent c0f9550 commit 4eaa8f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
40 changes: 20 additions & 20 deletions resources/js/datalayer/ga4.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ export const viewCart = async () => {
event: 'view_cart',
ecommerce: {
currency: window.config.currency,
value: removeTrailingZeros(window.app.cart.total),
value: removeTrailingZeros(window.app.cart?.prices?.grand_total?.value),
items: Object.values(window.app.cart.items).map(function (item) {
return {
item_name: item.name,
item_id: item.sku,
price: item.price,
quantity: item.qty,
item_name: item?.product?.name,
item_id: item?.product?.sku,
price: item?.prices?.price_including_tax?.value,
quantity: item?.quantity,
}
}),
}
Expand All @@ -164,13 +164,13 @@ export const beginCheckout = async (step) => {
event: 'begin_checkout',
ecommerce: {
currency: window.config.currency,
value: removeTrailingZeros(window.app.cart.total),
value: removeTrailingZeros(window.app.cart?.prices?.grand_total?.value),
items: Object.values(window.app.cart.items).map(function (item) {
return {
item_name: item.name,
item_id: item.sku,
price: item.price,
quantity: item.qty,
item_name: item?.product?.name,
item_id: item?.product?.sku,
price: item?.prices?.price_including_tax?.value,
quantity: item?.quantity,
}
}),
}
Expand All @@ -184,14 +184,14 @@ export const addShippingInfo = async () => {
event: 'add_shipping_info',
ecommerce: {
currency: window.config.currency,
value: removeTrailingZeros(window.app.cart.total),
value: removeTrailingZeros(window.app.cart?.prices?.grand_total?.value),
shipping_tier: window.app.checkout.shipping_method,
items: Object.values(window.app.cart.items).map(function (item) {
return {
item_name: item.name,
item_id: item.sku,
price: item.price,
quantity: item.qty,
item_name: item?.product?.name,
item_id: item?.product?.sku,
price: item?.prices?.price_including_tax?.value,
quantity: item?.quantity,
}
}),
}
Expand All @@ -205,14 +205,14 @@ export const addPaymentInfo = async () => {
event: 'add_payment_info',
ecommerce: {
currency: window.config.currency,
value: removeTrailingZeros(window.app.cart.total),
value: removeTrailingZeros(window.app.cart?.prices?.grand_total?.value),
payment_type: window.app.checkout.payment_method,
items: Object.values(window.app.cart.items).map(function (item) {
return {
item_name: item.name,
item_id: item.sku,
price: item.price,
quantity: item.qty,
item_name: item?.product?.name,
item_id: item?.product?.sku,
price: item?.prices?.price_including_tax?.value,
quantity: item?.quantity,
}
}),
}
Expand Down
8 changes: 4 additions & 4 deletions resources/js/datalayer/ua.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export const checkoutStep = async (step) => {
'actionField': {'step': step},
'products': Object.values(window.app.cart.items).map(function (item) {
return {
name: item.name,
id: item.product_id,
price: item.price,
quantity: item.qty,
name: item?.product?.name,
id: item?.product?.sku,
price: item?.prices?.price_including_tax?.value,
quantity: item?.quantity,
}
}),
}
Expand Down

0 comments on commit 4eaa8f9

Please sign in to comment.