Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/backward compatibilty ecommerce methods #25

Merged
merged 13 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,10 @@ import { SiteSearch } from '@piwikpro/react-piwik-pro'
import { eCommerce } from '@piwikpro/react-piwik-pro'
```
#### Methods
* `addEcommerceItem(products: Product[])` - Tracks action of adding products to a cart.
* `removeEcommerceItem(products: Product[])` - Tracks action of removing a product from a cart.
* `getEcommerceItems()` - Returns a copy of items from a virtual shopping cart. Does not send any data to the Collecting & Processing Pipeline
* `ecommerceAddToCart(products: Product[])` - Tracks action of adding products to a cart.
* `ecommerceRemoveFromCart(products: Product[])` - Tracks action of removing a products from a cart.
* `ecommerceOrder(products: Product[], paymentInformation: PaymentInformation)` - Tracks conversion (including products and payment details).
* `updateEcommerceCart(products: Product[], grandTotal: PaymentInformation['grandTotal'])` - Tracks current state of a cart.
* `ecommerceCartUpdate(products: Product[], grandTotal: PaymentInformation['grandTotal'])` - Tracks current state of a cart.
* `ecommerceProductDetailView(products: Product[])` - Tracks product or category view. Must be followed by a page view.

### Content Tracking Service
Expand Down
16 changes: 8 additions & 8 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "example",
"private": true,
"version": "0.0.0",
"version": "1.3.3",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
43 changes: 9 additions & 34 deletions example/src/pages/ECommercePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ const ECommercePage: FunctionComponent = () => {
const { enqueueSnackbar } = useSnackbar()

const handlelAddToCart = (product: Product) => {
enqueueSnackbar(`eCommerce.addEcommerceItem()`, { variant: 'success' })
eCommerce.addEcommerceItem([
enqueueSnackbar(`eCommerce.ecommerceAddToCart()`, { variant: 'success' })
eCommerce.ecommerceAddToCart([
{
...product,
quantity: 1
Expand Down Expand Up @@ -147,15 +147,17 @@ const ECommercePage: FunctionComponent = () => {
discount
}

enqueueSnackbar(`eCommerce.trackEcommerceOrder()`, { variant: 'success' })
enqueueSnackbar(`eCommerce.ecommerceOrder()`, { variant: 'success' })
eCommerce.ecommerceOrder(cart, paymentInformation)
}

const removeProduct = (product: Product) => {
const newCart = cart.filter((item) => item.sku !== product.sku)
setCart(newCart)
enqueueSnackbar(`eCommerce.removeEcommerceItem()`, { variant: 'success' })
eCommerce.removeEcommerceItem(newCart)
enqueueSnackbar(`eCommerce.ecommerceRemoveFromCart()`, {
variant: 'success'
})
eCommerce.ecommerceRemoveFromCart(newCart)
}

const increaseProductQuantity = (product: Product) => {
Expand All @@ -181,8 +183,8 @@ const ECommercePage: FunctionComponent = () => {
const discount = 5

setCart(newCart)
enqueueSnackbar(`eCommerce.updateEcommerceCart()`, { variant: 'success' })
eCommerce.updateEcommerceCart(newCart, subTotal + tax + shipping - discount)
enqueueSnackbar(`eCommerce.ecommerceCartUpdate()`, { variant: 'success' })
eCommerce.ecommerceCartUpdate(newCart, subTotal + tax + shipping - discount)
}

const [productDetailViewOpen, setProductDetailViewOpen] = useState(false)
Expand All @@ -197,14 +199,6 @@ const ECommercePage: FunctionComponent = () => {
eCommerce.ecommerceProductDetailView([product])
}

const handleGetEcommerceItems = async () => {
const ecommerceItems = await eCommerce.getEcommerceItems()
console.log(ecommerceItems)
enqueueSnackbar(`eCommerce.getEcommerceItems()`, {
variant: 'success'
})
}

return (
<Grid container spacing={4}>
<Grid xs={12} sm={7} item>
Expand Down Expand Up @@ -317,25 +311,6 @@ const ECommercePage: FunctionComponent = () => {
</Paper>
</Grid>

<Grid item sm={12}>
<Paper
sx={{
p: 2,
display: 'flex',
flexDirection: 'column'
}}
>
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
<Button
variant='contained'
onClick={handleGetEcommerceItems}
sx={{ ml: 1 }}
>
Get eCommerceItems
</Button>
</Box>
</Paper>
</Grid>
<ProductDetailView
product={selectedProduct}
isOpen={productDetailViewOpen}
Expand Down
Loading
Loading