-
Notifications
You must be signed in to change notification settings - Fork 63
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
Track Self-describing event in a Object Orientated manner. #419
Comments
Thanks @rvp-diconium for raising this proposal. We are not planning to change the behaviour of SelfDescribingJson shortly but the idea of a custom event generator tool is something we have experimented recently but not yet ready. If you are interested to work on this as open source tool, we would be really happy to collaborate. Meanwhile, as you suggest, the cleanest solution is to create proper custom events. If you are interested to an alternative to the SelfDescribingJson approach I would suggest to directly extend the abstract class
An example (in Java):
It can be used in this way:
This is just a basic example, you can decorate the class with more constructors and utility methods. It's important that the map generated by `getDataPayload is json serializable. If so, the tracker will take care of your custom event exactly like a SelfDescribingJson. |
Hi @AlexBenny thanks for the full detailed response. From a library perspective, I understand you shouldn't be favoring any json serialization library over another, so this solution usually goes around doing adapters interface so that any one can be plugged-in. The On my current project I'll give a shot (whenever the ticket gets prioritized) to create a And if from there I have something I can contribute back I'll report back here. Thanks! |
I'm fairly new to snowplow so maybe that's just a question and not feature request, but I'll write as feature request.
Preface the data team on my project will use snowplow 100% on self-describing events
Is your feature request related to a problem? Please describe.
It's general bad idea to have scattered strings around the code to track items (those strings are usually the same for big parts of the project and making it so is error prone). Having a schema to conform to opens the possibility to using an object instead.
But unfortunately, from what I understood reading the documentation and the code the only way to track self-describing events is by adding to a Map like:
Describe the solution you'd like
Taking heavy inspiration in libraries like Retrofit or Room I would rather use objects. Meaning, I would copy/paste the Json schema, to a data generator website, have a Kotlin data class auto-generated and pasted back into our code repository.
Then to track we would:
Describe alternatives you've considered
I see the in
SelfDescribingJson
it uses thetoString
calling Util.mapToJSONObject(payload).toString(); and thatUtil
uses theJSONObject(map)
constructor fromorg.json
.That makes it seems I could use any Json library I want to get the String, and build the object with
JsonObject(jsonString)
, but that option is not officially documented and seems kind of hacky. At the end it would be something like:Is that how others do it? If yes, it should be documented and guaranteed to be not a breaking behavior.
Hope it was clear.
The text was updated successfully, but these errors were encountered: