diff --git a/content/docs/campaigns/analytics/examples/rudderstack.md b/content/docs/campaigns/analytics/examples/rudderstack.md index 379c7a1..5e80d3a 100644 --- a/content/docs/campaigns/analytics/examples/rudderstack.md +++ b/content/docs/campaigns/analytics/examples/rudderstack.md @@ -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: diff --git a/content/docs/campaigns/analytics/index.mdx b/content/docs/campaigns/analytics/index.mdx index a261670..54f99b9 100644 --- a/content/docs/campaigns/analytics/index.mdx +++ b/content/docs/campaigns/analytics/index.mdx @@ -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', @@ -111,7 +117,7 @@ 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' @@ -119,6 +125,30 @@ All events follow GA4-compliant format: } ``` +`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 @@ -276,4 +306,3 @@ window.NextDataLayer; // Enable debug window.NextAnalytics.setDebugMode(true); ``` -