> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mavera.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Multi-Channel Performance → Content Strategy

> Generate channel-specific content strategies from BigCommerce multi-channel order performance data

### Scenario

BigCommerce supports multi-channel selling — your own storefront, Amazon, Facebook Shop, eBay, and more. Each channel has different audience expectations and content norms. You pull order data grouped by channel, analyze which product categories perform best where, then use Mave Agent to generate channel-specific content strategies backed by real sales data.

**Flow:** BigCommerce `GET /v3/orders` (filter by `channel_id`) → Aggregate revenue per channel per category → Mavera `POST /mave/chat` → Channel-optimized content strategies

### Architecture

```mermaid theme={"dark"}
flowchart LR
A["GET /v3/orders by channel_id"] --> B["GET order products"] --> C["Aggregate revenue + categories"] --> D["POST /api/v1/mave/chat"] --> E["Channel content strategies"]
```

### Code

<CodeGroup>
  ```python Python theme={"dark"}
  import os, requests, time
  from collections import defaultdict

  STORE = os.environ["BIGCOMMERCE_STORE_HASH"]
  BC_TOKEN = os.environ["BIGCOMMERCE_ACCESS_TOKEN"]
  MV = os.environ["MAVERA_API_KEY"]
  BC = f"https://api.bigcommerce.com/stores/{STORE}/v3"
  BC_HEADERS = {"X-Auth-Token": BC_TOKEN, "Content-Type": "application/json", "Accept": "application/json"}

  CHANNELS = {1: "Storefront", 2: "Amazon", 3: "Facebook Shop", 4: "eBay"}
  channel_data = defaultdict(lambda: {"revenue": 0, "orders": 0, "categories": defaultdict(lambda: {"revenue": 0, "units": 0})})

  for ch_id, ch_name in CHANNELS.items():
      page = 1
      while True:
          r = requests.get(f"{BC}/orders",
              headers=BC_HEADERS,
              params={"channel_id": ch_id, "page": page, "limit": 50, "sort": "date_created:desc"})
          if r.status_code == 429:
              time.sleep(2); continue
          if r.status_code == 204: break
          r.raise_for_status()
          orders = r.json().get("data", [])
          if not orders: break

          for order in orders:
              total = float(order.get("total_inc_tax", 0))
              channel_data[ch_name]["revenue"] += total
              channel_data[ch_name]["orders"] += 1

              prods = requests.get(f"{BC}/orders/{order['id']}/products",
                  headers=BC_HEADERS).json().get("data", [])
              for p in prods:
                  cat = p.get("product_options", [{}])[0].get("display_name", "General")
                  channel_data[ch_name]["categories"][cat]["revenue"] += float(p.get("total_inc_tax", 0))
                  channel_data[ch_name]["categories"][cat]["units"] += int(p.get("quantity", 0))
              time.sleep(0.15)

          if len(orders) < 50: break
          page += 1
          time.sleep(0.2)

  summary_lines = []
  for ch, data in channel_data.items():
      aov = data["revenue"] / max(data["orders"], 1)
      top_cats = sorted(data["categories"].items(), key=lambda x: -x[1]["revenue"])[:3]
      cats_str = ", ".join(f"{c}(${d['revenue']:.0f})" for c, d in top_cats)
      summary_lines.append(f"{ch}: ${data['revenue']:.0f} revenue, {data['orders']} orders, AOV ${aov:.0f}. Top: {cats_str}")

  summary = "\n".join(summary_lines)

  strategy = requests.post("https://app.mavera.io/api/v1/mave/chat",
      headers={"Authorization": f"Bearer {MV}", "Content-Type": "application/json"},
      json={"message": f"""Analyze this multi-channel e-commerce performance data and generate
  channel-specific content strategies.

  For each channel: what content formats work best, recommended messaging angles,
  budget allocation suggestion, and one specific campaign idea.

  {summary}"""}).json()

  print("--- Multi-Channel Content Strategy ---")
  print(strategy.get("content", "")[:2000])
  ```

  ```javascript JavaScript theme={"dark"}
  const STORE = process.env.BIGCOMMERCE_STORE_HASH;
  const BC_TOKEN = process.env.BIGCOMMERCE_ACCESS_TOKEN;
  const MV = process.env.MAVERA_API_KEY;
  const BC = `https://api.bigcommerce.com/stores/${STORE}/v3`;
  const bcHeaders = { "X-Auth-Token": BC_TOKEN, "Content-Type": "application/json", Accept: "application/json" };

  const CHANNELS = { 1: "Storefront", 2: "Amazon", 3: "Facebook Shop", 4: "eBay" };
  const channelData = {};
  for (const name of Object.values(CHANNELS)) {
    channelData[name] = { revenue: 0, orders: 0, categories: {} };
  }

  for (const [chId, chName] of Object.entries(CHANNELS)) {
    let page = 1;
    while (true) {
      const res = await fetch(`${BC}/orders?channel_id=${chId}&page=${page}&limit=50&sort=date_created:desc`,
        { headers: bcHeaders });
      if (res.status === 429) { await new Promise(r => setTimeout(r, 2000)); continue; }
      if (res.status === 204) break;
      const orders = (await res.json()).data || [];
      if (!orders.length) break;

      for (const order of orders) {
        channelData[chName].revenue += parseFloat(order.total_inc_tax || 0);
        channelData[chName].orders += 1;

        const prods = await fetch(`${BC}/orders/${order.id}/products`,
          { headers: bcHeaders }).then(r => r.json()).then(d => d.data || []);
        for (const p of prods) {
          const cat = p.product_options?.[0]?.display_name || "General";
          channelData[chName].categories[cat] ||= { revenue: 0, units: 0 };
          channelData[chName].categories[cat].revenue += parseFloat(p.total_inc_tax || 0);
          channelData[chName].categories[cat].units += parseInt(p.quantity || 0);
        }
        await new Promise(r => setTimeout(r, 150));
      }
      if (orders.length < 50) break;
      page++;
      await new Promise(r => setTimeout(r, 200));
    }
  }

  const summaryLines = Object.entries(channelData).map(([ch, data]) => {
    const aov = data.revenue / Math.max(data.orders, 1);
    const topCats = Object.entries(data.categories)
      .sort(([,a],[,b]) => b.revenue - a.revenue).slice(0, 3)
      .map(([c, d]) => `${c}($${d.revenue.toFixed(0)})`).join(", ");
    return `${ch}: $${data.revenue.toFixed(0)} revenue, ${data.orders} orders, AOV $${aov.toFixed(0)}. Top: ${topCats}`;
  });

  const strategy = await fetch("https://app.mavera.io/api/v1/mave/chat", {
    method: "POST",
    headers: { Authorization: `Bearer ${MV}`, "Content-Type": "application/json" },
    body: JSON.stringify({
      message: `Analyze this multi-channel e-commerce performance and generate channel-specific content strategies.\n\nFor each channel: content formats, messaging angles, budget allocation, one campaign idea.\n\n${summaryLines.join("\n")}`,
    }),
  }).then(r => r.json());

  console.log("--- Multi-Channel Content Strategy ---");
  console.log((strategy.content || "").slice(0, 2000));
  ```
</CodeGroup>

### Example Output

```text theme={"dark"}
--- Multi-Channel Content Strategy
```
