The Context Payload is a powerful feature of Edgee, enabling precise control over the data sent to various analytics. This guide will walk you through the essentials of crafting a Context Payload to enhance your data collection strategy.

Introduction to Context Payload

A Context Payload is a structured data format used to define and send detailed information about user interactions, page characteristics, and more, directly within your HTML. By embedding a Context Payload, you can instruct Edgee on exactly what data to collect, how to process it, and where to send it.

Inserting a Context Payload in your application

The way you insert a Context Payload in your application depends on the SDK you’re using. For HTML applications you can manually insert the Context Payload within a <script> tag with type="application/json" and a specific ID, and for React applications, you can use the EdgeeContextPayload component from the react-edgee package.

You can place your Context Payload anywhere in your page, but it’s recommended to include it before the Edgee SDK for optimal performance.

Structure of a Context Payload

Here’s a breakdown of the key components within a typical Context Payload:

{
    "page": {
        "name": "With Edgee",
        "category": "demo",
        "title": "With Edgee",
        "url": "https://www.edgee.dev/demo/with-edgee.html",
        "path": "/demo/with-edgee.html",
        "search": "?ok",
        "keywords": ["demo", "tag manager", "edgee"],
        "properties": {
            "section": "political",
            "pv": 1
        }
    },
    "identify": {
        "userId": "12345",
        "anonymousId": "12345",
        "properties": {
            "email": "me@example.com",
            "name": "John Doe"
        }
    },
    "destinations": {
        "all": true,
        "google_analytics": true,
        "amplitude": true,
        "facebook_capi": true
    }
}

Context Payload fields breakdown

FieldTypeDescription
pageObjectDefines attributes related to the current page view, including metadata such as page name, category, and specific properties for enhanced data collection.
identifyObjectContains user identification information, crucial for personalizing user experience and tracking user data across sessions.
destinationsObjectSpecifies which analytics or marketing platforms should receive the data. This enables targeted data transmission based on your configuration.

- page object fields

FieldTypeDescription
nameStringThe name of the page
categoryStringThe category of the page
titleStringThe title of the page
urlStringThe full url of the page, with scheme, host, path, and search
pathStringThe path of the page
searchStringThe search query of the page
keywordsArrayThe keywords associated with the page
propertiesObjectFree-form dictionary of properties of the page

- identify object fields

FieldTypeDescription
userIdStringA unique identifier for the user, typically from your own user database.
anonymousIdStringAn alternative identifier used when a userId is not available, ensuring that user actions can still be collected anonymously.
propertiesObjectFree-form dictionary of properties of the user

- destinations object fields

FieldTypeDescription
AllBooleanEven if you don’t define this field, it will be set to true by default. But if you set it to false, no destination will receive the data.
DestinationNameBooleanIf true, the specified destination will receive the data. If false, the destination will not receive the data.

Use the destinations object to specify which analytics components should not receive the data. If you do not specify any destinations, all configured destinations will receive the data by default.

For example, let’s say you have three destinations configured: Google Analytics, Amplitude, and Facebook Conversions API. To exclude Google Analytics from receiving the data, you can set the google_analytics field to false:

{
    "destinations": {
        "google_analytics": false
    }
}

If you only want to send data to Google Analytics, you can set the All field to false and the Google Analytics field to true:

{
    "destinations": {
        "all": false,
        "google_analytics": true
    }
}

Best Practices

  • Precision and Clarity: Ensure that each field in the payload is accurately defined. Clear, descriptive values for page names, categories, and properties enhance data quality.
  • Consent and Privacy: When including any personally identifiable information (PII) in the identify section, ensure you have obtained explicit consent from the user in compliance with GDPR, CCPA, and other privacy regulations.
  • Regular Updates: Keep your Context Payload up to date with any changes in your site structure, user attributes, or analytics destinations to maintain data accuracy and relevance.