Detailed Edgee Data Layer guide
The Data Layer is a powerful feature, providing you with fine-grained control over the data sent to various analytics. This guide will walk you through the essentials of crafting a Data Layer to enhance your data collection strategy.
A Data Layer is a structured data format used to define and send detailed information about user interactions, page characteristics, and more, directly within your HTML page. By including a Data Layer, you can instruct Edgee on exactly what data to collect, how to process it, and where to send it.
The way you insert a Data Layer in your application depends on the Edgee SDK you’re using.
For HTML applications you can manually insert the Data Layer within a <script>
tag with type="application/json"
and a specific ID.
For React applications, you can use the EdgeeDataLayer
component from the react-edgee
package.
Please note that the typical Data Layer object is very small and only includes one or two events. You can find a few examples of valid objects at the end of this page.
The following code represents the full schema of everything you can define in your Data Layer:
The following fields are defined under data_collection
:
Field | Type | Description | |
---|---|---|---|
events | optional | Array | Contains a list of events (see below for the event structure). |
context | optional | Object | Contains general information that can be used for all events. |
components | optional | Object | Specifies which components should receive the data. This enables targeted data transmission based on your configuration. |
Let’s have a look at each field individually.
events
listIt contains objects with the following structure.
Field | Type | Description | |
---|---|---|---|
type | required | String | The type of event: page , track , or user . |
data | optional | Object | The data structure depends on the event type (see detailed pages). This is required for track events. |
components | optional | Object | Specifies which components should receive the data. |
Learn more about the page, track, and user event types and their structure.
context
objectIt can contain the following fields.
Field | Type | Description | |
---|---|---|---|
page | optional | Object | General info about this page that can be used across events. |
user | optional | Object | General info about the user that can be used across events. |
Note: when you define context data about the current page
or user
, it’s going to be used automatically
for all compatible events, so you don’t need to provide the same information multiple times.
For example, data_collection.context.user
is used to define the data
fields for user
events.
components
objectIt can contain the following fields.
Field | Type | Description | |
---|---|---|---|
all | optional | Boolean | Even if you don’t define this field, it will be set to true by default. But if you set it to false , no component will receive the data. |
<component_name> | optional | Boolean | If true , the specified component will receive the data. If false , the component will not receive the data. |
Use the components
object to specify which analytics components should and should not receive the data. If you do not specify any component,
all configured components will receive the data by default.
You can find a few examples in the next section.
Remember: the components
object can be set globally for all data collection or for individual events.
This gives you full control and the ability to be very granular about what data is sent to which components.
Please also note that the components
object defined for an individual event will
override the global configuration for that event.
identify
section, ensure you have obtained explicit consent from the user in compliance with GDPR, CCPA, and other privacy regulations.