Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Frederiks96 opened this issue Feb 19, 2025 · 0 comments
Open
Assignees
Labels

Comments

@Frederiks96
Copy link

Frederiks96 commented Feb 19, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants