View Source Plausible.Google.UA.API (Plausible v0.0.1)

API for Universal Analytics

Summary

Functions

Returns a single Google Analytics view if the user has access to it.

Imports stats from a Google Analytics UA view to a Plausible site.

Lists Google Analytics views grouped by hostname.

Types

Link to this type

google_analytics_view()

View Source
@type google_analytics_view() :: {view_name :: String.t(), view_id :: String.t()}
@type import_auth() ::
  {access_token :: String.t(), refresh_token :: String.t(),
   expires_at :: String.t()}

Functions

Link to this function

fetch_and_persist(report_request, opts \\ [])

View Source
@spec fetch_and_persist(Plausible.Google.UA.ReportRequest.t(), Keyword.t()) ::
  :ok | {:error, term()}
Link to this function

get_analytics_end_date(access_token, view_id)

View Source
Link to this function

get_analytics_start_date(access_token, view_id)

View Source
Link to this function

get_view(access_token, lookup_id)

View Source
@spec get_view(access_token :: String.t(), lookup_id :: String.t()) ::
  {:ok, google_analytics_view()} | {:ok, nil} | {:error, term()}

Returns a single Google Analytics view if the user has access to it.

Link to this function

import_analytics(date_range, view_id, auth, persist_fn)

View Source
@spec import_analytics(Date.Range.t(), String.t(), import_auth(), (String.t(),
                                                             [map()] ->
                                                               :ok)) ::
  :ok | {:error, term()}

Imports stats from a Google Analytics UA view to a Plausible site.

This function fetches Google Analytics reports in batches of 100000 per request. The batches are then passed to persist callback.

Requests to Google Analytics can fail, and are retried at most 5 times with an exponential backoff. Returns :ok when importing has finished or {:error, term()} when a request to GA failed too many times.

Useful links:

Link to this function

list_views(access_token)

View Source
@spec list_views(access_token :: String.t()) ::
  {:ok, %{required(hostname :: String.t()) => [google_analytics_view()]}}
  | {:error, term()}

Lists Google Analytics views grouped by hostname.