Skip to content

Add a way to specify event version to support tracking plan versioning #380

Open
@Frederiks96

Description

@Frederiks96

Is your feature request related to a problem? Please describe.
For tracking plan versioning, clients must

"[...] instrument your events to include a context.protocols.event_version key and version value."

from this link: https://segment.com/docs/protocols/tracking-plan/create/#dynamically-validate-track-events-against-an-event-version

However, since this has semantic meaning for Segment, it feels uncomfortable to dig in to the body of the payload to add a key-value pair that changes the way an event is handled on the server. To me, how the payload is structured is internal information and modifying the payload may break between versions.

I've searched the analytics-swift and analytics-kotlin SDKs and found no mentions of protocols or event_version.

Describe the solution you'd like
A public API in the SDKs to add a version to an event, or maybe even to the configuration or analytics instance for global application.

Describe alternatives you've considered
Defining a version plugin, that adds a version to an event:

class VersionPlugin: Plugin {
	let type: PluginType = .before
	var analytics: Analytics?

	func execute<T>(event: T?) -> T? where T: RawEvent {
		var event = event
		event?.context?.setValue(
			["event_version": 2],
			forKeyPath: KeyPath("protocols")
		)
		return event
	}
}

However, this will override any values set by the Segment SDK today or anytime in the future. The JSON value has limited ways to extract an existing dictionary/map for a specific key. It contains functions for arrays and other types, but none that return a dictionary for a key. You then need to access the dictionaryValue and subscript and cast the return value to a dictionary and handle any errors when converting back to a JSON object.

Additional context

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions