# Connecting E-commerce Platforms

Track purchases and trigger cart recovery emails

Integrating your e-commerce platform with Mailnaptic unlocks powerful email marketing capabilities: abandoned cart recovery, post-purchase follow-ups, product recommendations, and purchase-based segmentation. This guide covers how to connect your store and leverage purchase data.

## Integration methods

Depending on your platform, there are several ways to connect:

| Method | Platforms | Setup effort |
| --- | --- | --- |
| Site tracking + custom events | Any platform | Medium (requires JavaScript) |
| Webhooks from your platform | Shopify, WooCommerce, BigCommerce | Medium |
| Zapier / Make | Any platform with a Zapier integration | Low |
| Direct API integration | Custom stores | High |

## Using site tracking for e-commerce events

The most flexible approach is sending custom events via the Mailnaptic tracking snippet. Add these events to your store's pages:

```
// When a product is viewed
mailnaptic.track('product_viewed', {
  product_id: 'SKU-100',
  product_name: 'Blue T-Shirt',
  price: 29.99
});

// When an item is added to cart
mailnaptic.track('product_added_to_cart', {
  product_id: 'SKU-100',
  quantity: 1,
  cart_total: 29.99
});

// When an order is completed
mailnaptic.track('order_completed', {
  order_id: 'ORD-5678',
  total: 59.98,
  items_count: 2,
  currency: 'USD'
});
```

These events feed into contact activity feeds, segments, and automation triggers.

## Abandoned cart recovery

To set up cart recovery emails:

1. **Track the cart event:** Fire `product_added_to_cart` when items are added.
2. **Track the purchase:** Fire `order_completed` at checkout confirmation.
3. **Create an automation:** Use the pre-made *Abandoned Cart* template or build one manually:
    - Trigger: `product_added_to_cart` event.
    - Wait 2 hours.
    - Condition: check if `order_completed` has occurred since the trigger. If yes, exit. If no, send recovery email.
    - Wait 24 hours and send a follow-up if still no purchase.

## Post-purchase automations

Common post-purchase flows:

- **Order confirmation:** Trigger immediately on `order_completed` — send a thank-you email with order details.
- **Review request:** Wait 7-14 days after purchase, then ask for a product review.
- **Replenishment reminder:** For consumable products, send a reorder reminder after the typical usage period.
- **Cross-sell:** Based on purchase category, recommend complementary products.

## Purchase-based segmentation

Use web activity segment filters to build purchase-based audiences:

- **Customers:** `site_purchased` — contacts with at least one `order_completed` event.
- **Non-purchasers:** `site_not_purchased` — contacts who have never completed an order.
- **High-value customers:** Combine `site_purchased` with custom event properties or CRM data.
- **Lapsed buyers:** `site_purchased` AND `last_active_days` greater than 90.

## Platform-specific webhook setup

### Shopify

In Shopify admin, go to **Settings → Notifications → Webhooks**. Create webhooks for `orders/create` and `checkouts/create` pointing to your sync middleware, which then calls Mailnaptic's API to create events or update contacts.

### WooCommerce

In WooCommerce, go to **Settings → Advanced → Webhooks**. Add webhooks for order creation and status changes. Point them at your middleware or directly at a Mailnaptic incoming webhook trigger.

> **Tip:** Tag customers with their purchase category (e.g., `purchased:electronics`) to enable targeted product recommendation campaigns.
