Class: SnowplowTracker::SelfDescribingJson
- Inherits:
-
Object
- Object
- SnowplowTracker::SelfDescribingJson
- Defined in:
- lib/snowplow-tracker/self_describing_json.rb
Overview
Creates the self-describing JSONs necessary for sending context or self-describing events. These are a specific kind of JSON schema.
A unique schema can be designed for each type of event or entity (for event context) that you want to track. This allows you to track the specific things that are important to you, in a way that is defined by you.
A self-describing JSON has two keys, schema
and data
. The schema
value
should point to a valid self-describing JSON schema. They are called
self-describing because the schema will specify the fields allowed in the
data
value. After events have been collected by the event collector, they
are validated to ensure that the self-describing JSONs are correct. Mistakes
(e.g. extra fields, or incorrect types) will result in events being
processed as Bad Events.
A SelfDescribingJson is initialized with schema
and data
as separate
arguments. These parameters are combined into a complete self-describing
JSON during the event creation, which is stringified and sent as part of the
event. By default, they will be sent base64-encoded. This can be changed on
Tracker initialization.
The data
argument must be a flat hash of key-value pairs. Either strings
or symbols are accepted as keys. The schema
argument must be a correctly
formatted schema ID.
When used to send event context data, stringified self-describing JSONs will
be sent in the raw event as cx
, or co
if not encoded. Whether encoded or
not, these strings will be converted back to JSON within the contexts
parameter of the processed event. All the event context is contained within
this one parameter, even if multiple context entities were sent.
Self-describing JSONs in self-describing events are sent in a similar
manner. They are sent as ue_px
in the raw event, or ue_pr
if not
encoded. This is processed into the unstruct_event
parameter of the
finished event.
Instance Method Summary collapse
-
#initialize(schema, data) ⇒ SelfDescribingJson
constructor
A new instance of SelfDescribingJson.
Constructor Details
#initialize(schema, data) ⇒ SelfDescribingJson
Returns a new instance of SelfDescribingJson.
103 104 105 106 |
# File 'lib/snowplow-tracker/self_describing_json.rb', line 103 def initialize(schema, data) @schema = schema @data = data end |