-
Notifications
You must be signed in to change notification settings - Fork 4
/
data.clj
85 lines (76 loc) · 2.64 KB
/
data.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(ns happygapi.analytics.data
"Google Analytics API: data.
Views and manages your Google Analytics data.
See: https://developers.google.com/analytics/api/reference/rest/v3/data"
(:require [cheshire.core :as json]
[clj-http.client :as http]
[happy.util :as util]))
(defn ga-get$
"https://developers.google.com/analytics/api/reference/rest/v3/data/ga/get
Required parameters: end-date, ids, start-date, metrics
Optional parameters: start-index, include-empty-rows, filters, max-results, output, dimensions, segment, samplingLevel, sort
Returns Analytics data for a view (profile)."
{:scopes ["https://www.googleapis.com/auth/analytics"
"https://www.googleapis.com/auth/analytics.readonly"]}
[auth args]
{:pre [(util/has-keys? args #{:end-date :ids :start-date :metrics})]}
(util/get-response
(http/get
(util/get-url
"https://www.googleapis.com/analytics/v3/"
"data/ga"
#{:end-date :ids :start-date :metrics}
args)
(merge-with
merge
{:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn mcf-get$
"https://developers.google.com/analytics/api/reference/rest/v3/data/mcf/get
Required parameters: end-date, ids, start-date, metrics
Optional parameters: start-index, filters, max-results, dimensions, samplingLevel, sort
Returns Analytics Multi-Channel Funnels data for a view (profile)."
{:scopes ["https://www.googleapis.com/auth/analytics"
"https://www.googleapis.com/auth/analytics.readonly"]}
[auth args]
{:pre [(util/has-keys? args #{:end-date :ids :start-date :metrics})]}
(util/get-response
(http/get
(util/get-url
"https://www.googleapis.com/analytics/v3/"
"data/mcf"
#{:end-date :ids :start-date :metrics}
args)
(merge-with
merge
{:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn realtime-get$
"https://developers.google.com/analytics/api/reference/rest/v3/data/realtime/get
Required parameters: ids, metrics
Optional parameters: dimensions, filters, max-results, sort
Returns real time data for a view (profile)."
{:scopes ["https://www.googleapis.com/auth/analytics"
"https://www.googleapis.com/auth/analytics.readonly"]}
[auth args]
{:pre [(util/has-keys? args #{:ids :metrics})]}
(util/get-response
(http/get
(util/get-url
"https://www.googleapis.com/analytics/v3/"
"data/realtime"
#{:ids :metrics}
args)
(merge-with
merge
{:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))