# E-commerce DataLayer Schema Reference

## GA4 E-commerce Structure

### Items Array Schema
Every e-commerce event requires an `items` array:

```javascript
items: [{
  // Required
  item_id: "SKU_12345",
  item_name: "Blue T-Shirt",
  
  // Recommended
  affiliation: "Store Name",
  coupon: "SUMMER_SALE",
  discount: 5.00,
  index: 0,
  item_brand: "Brand Name",
  item_category: "Apparel",
  item_category2: "Men",
  item_category3: "Shirts",
  item_category4: "T-Shirts",
  item_category5: "Short Sleeve",
  item_list_id: "related_products",
  item_list_name: "Related Products",
  item_variant: "Blue/Large",
  location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
  price: 29.99,
  quantity: 1
}]
```

### Clear Previous E-commerce Data
Always clear before new e-commerce event:

```javascript
dataLayer.push({ ecommerce: null });
dataLayer.push({
  event: "view_item",
  ecommerce: {
    // new data
  }
});
```

## Complete Purchase Flow

### 1. Product List View
```javascript
dataLayer.push({ ecommerce: null });
dataLayer.push({
  event: "view_item_list",
  ecommerce: {
    item_list_id: "category_results",
    item_list_name: "Category Results",
    items: [
      { item_id: "SKU_001", item_name: "Product 1", index: 0, price: 29.99 },
      { item_id: "SKU_002", item_name: "Product 2", index: 1, price: 39.99 }
    ]
  }
});
```

### 2. Product Click
```javascript
dataLayer.push({ ecommerce: null });
dataLayer.push({
  event: "select_item",
  ecommerce: {
    item_list_id: "category_results",
    item_list_name: "Category Results",
    items: [{
      item_id: "SKU_001",
      item_name: "Product 1",
      price: 29.99
    }]
  }
});
```

### 3. Product Detail View
```javascript
dataLayer.push({ ecommerce: null });
dataLayer.push({
  event: "view_item",
  ecommerce: {
    currency: "USD",
    value: 29.99,
    items: [{
      item_id: "SKU_001",
      item_name: "Product 1",
      item_brand: "Brand",
      item_category: "Category",
      price: 29.99,
      quantity: 1
    }]
  }
});
```

### 4. Add to Cart
```javascript
dataLayer.push({ ecommerce: null });
dataLayer.push({
  event: "add_to_cart",
  ecommerce: {
    currency: "USD",
    value: 29.99,
    items: [{
      item_id: "SKU_001",
      item_name: "Product 1",
      price: 29.99,
      quantity: 1
    }]
  }
});
```

### 5. View Cart
```javascript
dataLayer.push({ ecommerce: null });
dataLayer.push({
  event: "view_cart",
  ecommerce: {
    currency: "USD",
    value: 59.98,
    items: [
      { item_id: "SKU_001", item_name: "Product 1", price: 29.99, quantity: 1 },
      { item_id: "SKU_002", item_name: "Product 2", price: 29.99, quantity: 1 }
    ]
  }
});
```

### 6. Begin Checkout
```javascript
dataLayer.push({ ecommerce: null });
dataLayer.push({
  event: "begin_checkout",
  ecommerce: {
    currency: "USD",
    value: 59.98,
    coupon: "DISCOUNT10",
    items: [...]
  }
});
```

### 7. Add Shipping Info
```javascript
dataLayer.push({ ecommerce: null });
dataLayer.push({
  event: "add_shipping_info",
  ecommerce: {
    currency: "USD",
    value: 59.98,
    shipping_tier: "Standard",
    items: [...]
  }
});
```

### 8. Add Payment Info
```javascript
dataLayer.push({ ecommerce: null });
dataLayer.push({
  event: "add_payment_info",
  ecommerce: {
    currency: "USD",
    value: 59.98,
    payment_type: "Credit Card",
    items: [...]
  }
});
```

### 9. Purchase
```javascript
dataLayer.push({ ecommerce: null });
dataLayer.push({
  event: "purchase",
  ecommerce: {
    transaction_id: "T_12345",
    value: 65.97,
    tax: 4.99,
    shipping: 5.99,
    currency: "USD",
    coupon: "DISCOUNT10",
    items: [{
      item_id: "SKU_001",
      item_name: "Product 1",
      affiliation: "Online Store",
      coupon: "DISCOUNT10",
      discount: 3.00,
      item_brand: "Brand",
      item_category: "Category",
      price: 29.99,
      quantity: 1
    }]
  }
});
```

## Korean E-commerce Considerations

### Currency
```javascript
currency: "KRW",
value: 35000  // No decimals for KRW
```

### Common Korean Platform Integrations
- Cafe24: Uses custom dataLayer structure
- Shopify Korea: Standard GA4 format
- Naver SmartStore: Custom pixel implementation
