Giter Club home page Giter Club logo

legato-ex's Introduction

Legato

Legato provides query access through the official Google Analytics Reporting API v4

Installation

Available in Hex, 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
```
  1. 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"}]

  • Collect data into Query struct
  • Convert query into Request JSON, encode with Poison
  • Send request to GA
  • Decode response
  • Parse data into struct
  • support metric expression strings
  • add filters to Query
  • add date ranges to Query
  • add order by to Query
  • add segment_id to Query
  • add Sampling
  • put report struct into named struct
  • add segments to Query (long goal)
profile = %Legato.Profile{access_token: oauth2_access_token, view_id: view_id}
defmodule ExitReport do
  defstruct :exits, :pageviews, :country
end
import Legato.Query

alias Legato.Request
alias Legato.Report

profile |>
  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.

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.