Coder Social home page Coder Social logo

Add a Traits type about analytics-go HOT 6 CLOSED

segmentio avatar segmentio commented on August 26, 2024
Add a Traits type

from analytics-go.

Comments (6)

f2prateek avatar f2prateek commented on August 26, 2024

I don't believe that traits are standardized like context. https://cloudup.com/c3KQOQu-Owa

Like properties, some fields are standardized, but it is definitely acceptable for customers to be able to set their own keys for traits.

from analytics-go.

achille-roussel avatar achille-roussel commented on August 26, 2024

The documentation says The following is all the reserved traits we’ve standardized:, how about taking the same approach that we have with the Context type, defining the structure with all fields from the specs and adding an Extra map for extensions?

from analytics-go.

f2prateek avatar f2prateek commented on August 26, 2024

Traits are certainly meant to be a free form dictionary and this is a very common use case - so I wouldn't like to hide custom ones behind the Extras. I think it degrades the API (didn't matter much in the context because there is a very limited number of cases when you'd use something beyond what we've sped'd).

analytics.Traits{
  Age: 21,
  Extras: map[string]interface{}{
    "plan": "developer",
  },
}

vs.

map[string]interface{}{
  "age": 21,
  "plan": "developer",
}

from analytics-go.

achille-roussel avatar achille-roussel commented on August 26, 2024

OK.

Yeah as I'm reading more in details, pretty much everything is a string except dates but it says the API is flexible and accepts different formats... It doesn't look like there's much needs to do sanity checks client side.

Thanks for the insights!

from analytics-go.

f2prateek avatar f2prateek commented on August 26, 2024

FWIW, I like what we've done in the Android library the best - we let users use a map and the traits type independently. This gives users the option to use the regular Java Map API:

new HashMap<>().put("age", 21).put("plan", developer")

Or use the specific implementation of our Map type (traits) which adds type safe setters for the spec'd fields.

new Traits().putAge(21).put("plan", developer")

And then this works great things like properties as well:

new Properties().putRevenue(21.09).putCurrency("usd").put("custom", "custom");

from analytics-go.

achille-roussel avatar achille-roussel commented on August 26, 2024

Hm interesting, I'm gonna think about it a little bit and see if we can figure something that works well in Go.

from analytics-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.