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

Callback to format custom variables #30

Open
Victorma opened this issue Mar 7, 2017 · 0 comments
Open

Callback to format custom variables #30

Victorma opened this issue Mar 7, 2017 · 0 comments
Labels

Comments

@Victorma
Copy link
Member

Victorma commented Mar 7, 2017

In order to not have to modify the tracker for each extension variable, and not be limited by the format of string, int and float, it would be interesting to be able to set callbacks for the variable/extension name.

For example, I'm using geopoints and I need to send them in the json object format, so I had to modify the tracker so, when it deserialized the data from the csv, it transforms it into a json object like this:

// [ Other extensions formatting... ] 
if (key.Equals(Tracker.Extension.Geopoint.ToString().ToLower()))
{
var location = new JSONClass();
var geoPoint = new JSONClass();
var latlon = new List<string>(value.Split(',')).ConvertAll(e => float.Parse(e));
location.Add("lat", new JSONData(latlon[0]));
location.Add("lon", new JSONData(latlon[1]));
geoPoint.Add("location", location);
extensionsChild.Add("location", location);
}
// [ Other extensions formatting... ] 

So being able to manage this in a callback from the tracker could be the perfect solution to not have to modify the internals of the tracker. With this approach I could do something like:

Tracker.T.AddVariableFormatCallback(Tracker.Extension.Geopoint.ToString().ToLower(), (value, extensions) => {
    var location = new JSONClass();
    var geoPoint = new JSONClass();
    var latlon = new List<string>(value.Split(',')).ConvertAll(e => float.Parse(e));
    location.Add("lat", new JSONData(latlon[0]));
    location.Add("lon", new JSONData(latlon[1]));
    geoPoint.Add("location", location);
    extensions.Add("location", location);
});

This is just an example that could be used to implement custom extensions such as the GeoJSON one (as it has been described here that it should go in GeoJSON format, not string).

Thanks ahead,
Víctor

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

1 participant