Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tpitale/legato-ex
Google Analytics API v4 in Elixir
https://github.com/tpitale/legato-ex
analytics api google google-analytics reporting
Last synced: about 1 month ago
JSON representation
Google Analytics API v4 in Elixir
- Host: GitHub
- URL: https://github.com/tpitale/legato-ex
- Owner: tpitale
- License: mit
- Created: 2016-09-23T04:31:52.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-27T00:06:27.000Z (over 7 years ago)
- Last Synced: 2024-09-18T14:10:50.387Z (about 2 months ago)
- Topics: analytics, api, google, google-analytics, reporting
- Language: Elixir
- Size: 30.3 KB
- Stars: 16
- Watchers: 5
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Legato
Legato provides query access through the official [Google Analytics Reporting API v4](https://developers.google.com/analytics/devguides/reporting/core/v4/)
## Installation
[Available in Hex](https://hex.pm/packages/legato), the package can be installed as:
1. Add `legato` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:legato, "~> 0.2.0"}]
end
```2. Ensure `legato` is started before your application:
```elixir
def application do
[applications: [:legato]]
end
```Get an oauth access token from Google
"Authorization: Bearer token_here"
HTTPoison.post "https://analyticsreporting.googleapis.com/v4/reports:batchGet", "{}", [{"Authorization", "Bearer token_here"}]
* [x] Collect data into Query struct
* [x] Convert query into Request JSON, encode with Poison
* [x] Send request to GA
* [x] Decode response
* [x] Parse data into struct
* [x] support metric expression strings
* [x] add filters to Query
* [x] add date ranges to Query
* [x] add order by to Query
* [x] add segment_id to Query
* [x] add Sampling
* [x] put report struct into named struct
* [ ] add segments to Query (long goal)```elixir
profile = %Legato.Profile{access_token: oauth2_access_token, view_id: view_id}
``````elixir
defmodule ExitReport do
defstruct :exits, :pageviews, :country
end
``````elixir
import Legato.Queryalias Legato.Request
alias Legato.Reportprofile |>
metrics([:exits, :pageviews]) |>
dimensions([:country]) |>
filter(:exits, :gt, 10) |>
between(start_date, end_date) |> # first date range for the query
between(another_start_date, another_end_date) |> # adds subsequent date ranges
order_by(:pageviews, :descending) |>
segment(-3) |>
sampling(:small) |>
Request.all |>
Report.as(ExitReport)
```If you'd like to use relative dates, I suggest trying `timex`.
`segment` with an integer will clear any segments, cannot be mixed with dynamic segments.