#convert #data #json-response #analytics #reports #google #api

ga-v4-flattener

Converts Google Analytics API v4 reports to flat/delimited data

4 releases (2 breaking)

0.4.0 Feb 8, 2021
0.3.0 Nov 4, 2018
0.2.1 Nov 4, 2018
0.1.1 Oct 15, 2018
0.1.0 Sep 29, 2018

#15 in #reports

29 downloads per month

MIT license

25KB
611 lines

This library exposes two public functions that accept a Google Analytics Core Reporting v4 response string (string of the JSON data) and transform the data into something easier to use.

Report to delimited (e.g. TSV, CSV)

to_delimited(raw_report_response: &str, delimiter: &str) -> Result<Vec<String>, serde_json::Error>

Converts a report response to a collection of delimited reports. You can specify any delimiter string you'd like.

["\"ga:deviceCategory\",\"ga:sessions\"\n\"desktop\",43\n\"mobile\",1\n"]

Report to flat JSON (flat array of row data)

to_flat_json(raw_report: &str) -> Result<serde_json::value::Value, serde_json::Error>

Converts a report response to an array of "flat JSON" responses.

[
  [{
    "ga:deviceCategory": "desktop",
    "ga:sessions": 21
  }, {
    "ga:deviceCategory": "mobile",
    "ga:sessions": 84
  }],
  [{
    "ga:country": "Mexico",
    "ga:bounces": 9213
  }, {
    "ga:country": "Canada",
    "ga:bounces": 407
  }]
]

Limitations

Contributing

Issues and pull requests welcome. Please be nice.

  • Run tests with cargo test
  • Run benchmarks with cargo bench
  • Format with rustfmt

License

MIT

Dependencies

~1.1–2MB
~42K SLoC