Skip to content
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
20 changes: 20 additions & 0 deletions content/docs/campaigns/analytics/examples/rudderstack.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ RudderStack events follow the Segment specification. The SDK automatically maps
| `dl_add_payment_info` | `Payment Info Entered` | Fired when payment information is provided |
| `dl_purchase` | `Order Completed` | Fired when an order is successfully completed |

## Campaign and Journey Context

RudderStack events include campaign and page context using the original snake_case field names:

| Field | Description |
| --- | --- |
| `campaign_id` | Campaign ID returned by the Campaigns API |
| `campaign_name` | Campaign name |
| `campaign_currency` | Campaign currency |
| `campaign_language` | Campaign language |
| `campaign_session_id` | Session ID created by Campaigns session tracking |
| `page_type` | Current funnel page type |
| `page_name` | Current funnel page name |

The adapter also uses the SDK's internal analytics session ID as a correlation value on selected events:

- `Product Added`, `Product Removed`, and `Cart Viewed` use it as `cart_id`.
- Checkout step, payment, and completed-order events use it as `checkout_id`.
- Checkout and completed-order events include `coupon` and `discount` when those values are present.

## Product Format

Products are automatically converted to the Segment specification format. Each product in your events will be transformed to include these standardized properties:
Expand Down
33 changes: 31 additions & 2 deletions content/docs/campaigns/analytics/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ All events follow GA4-compliant format:
event_id: 'sess_123_2_1234567890',
event_time: '2025-01-12T10:30:00Z',

campaign_id: '42',
campaign_name: 'Summer Campaign',
campaign_currency: 'USD',
campaign_language: 'en',
campaign_session_id: 'ncsid_abc123', // Campaigns session-tracking ID

user_properties: {
visitor_type: 'guest',
customer_email: 'user@example.com',
Expand All @@ -111,14 +117,38 @@ All events follow GA4-compliant format:
},

_metadata: {
session_id: 'sess_abc123',
session_id: 'session_abc123', // SDK analytics session ID
sequence_number: 2,
source: 'next-campaign-cart',
version: '0.2.0'
}
}
```

`campaign_session_id` comes from Campaigns session tracking and connects activity to Campaigns App reporting. `_metadata.session_id` is generated by the SDK for event ordering and browser-session correlation. They are separate identifiers; the RudderStack adapter uses the SDK identifier for its `cart_id` and `checkout_id` values.

### Campaign Context

The SDK adds campaign context to every analytics event when that data is available. This makes it possible to segment events by campaign and join provider data back to Campaigns App sessions and order attribution.

| Field | Description |
| --- | --- |
| `campaign_id` | Campaign ID returned by the Campaigns API |
| `campaign_name` | Campaign name |
| `campaign_currency` | Campaign currency |
| `campaign_language` | Campaign language |
| `campaign_session_id` | Session ID from the `ncsid` cookie created by [Campaigns session tracking](/docs/campaigns/api#add-session-tracking) |

Set the campaign API key before the SDK loads so it can retrieve the campaign record and populate these fields:

```javascript
window.nextConfig = {
apiKey: 'your-api-key'
};
```

See [Campaigns configuration](/docs/campaigns/configuration) for the complete setup. If the key is missing, analytics logs a console warning and emits events without the campaign ID, name, currency, or language. The session-tracking ID remains available when the `ncsid` cookie is present.

## Testing & Verification

### Enable Debug Mode
Expand Down Expand Up @@ -276,4 +306,3 @@ window.NextDataLayer;
// Enable debug
window.NextAnalytics.setDebugMode(true);
```