simple_ga_reporting 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/README.md +65 -27
- data/Rakefile +0 -0
- data/bin/console +0 -0
- data/bin/setup +0 -0
- data/images/config_filter_by_gui.png +0 -0
- data/images/dimensions_and_metrics_explorer.png +0 -0
- data/images/ga_profile(view).png +0 -0
- data/images/gcp_api_auth_info.png +0 -0
- data/images/gcp_api_menu.png +0 -0
- data/images/gcp_download_json_key.png +0 -0
- data/images/gcp_private_key_and_client_email.png +0 -0
- data/lib/simple_ga_reporting.rb +0 -0
- data/lib/simple_ga_reporting/legato_ga_model.rb +0 -0
- data/lib/simple_ga_reporting/legato_ga_user.rb +7 -4
- data/lib/simple_ga_reporting/simple_ga_reports.rb +6 -6
- data/lib/simple_ga_reporting/version.rb +1 -1
- data/simple_ga_reporting.gemspec +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa9e0716b143f6bcd77b14b370d0be17a9cbb342b003112c1f751b3f62a77c28
|
4
|
+
data.tar.gz: 9365ff9c38abdd3843b655eed514561c2cc8b0f4d2023b2677d876cf0a9f3c54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c15749c7b62e206da384a60038efc2e68a4f7af05e3124b075c59c9db7dcfa63fa9343eba76bc9f95fbad299f95b28213b904dc22182f703832fa2675237cb9
|
7
|
+
data.tar.gz: 759044dc38c099c886fe41b8cc8f845e880fa5e5ab067651b878fdc3585761a6d19cadeae5d239ffb5f4b61ef25b69b525d93a786b6808298ff1737d51579a53
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/CHANGELOG.md
CHANGED
File without changes
|
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -14,21 +14,30 @@ Yeah, very simple :)
|
|
14
14
|
## Wrapper gem of Legato
|
15
15
|
This gem is a wrapper of [Legato gem](https://github.com/tpitale/legato). `Legato` is very coooooooool and full-stack gem, so complicated as a beginner (me!).
|
16
16
|
|
17
|
-
Therefore I developed this wrapper gem, `
|
17
|
+
Therefore I developed this wrapper gem, `simple_ga_reporting`.
|
18
18
|
|
19
19
|
# Get Started
|
20
20
|
|
21
21
|
## 1. Installation
|
22
22
|
```bash
|
23
|
-
$ gem install
|
23
|
+
$ gem install simple_ga_reporting
|
24
24
|
```
|
25
25
|
|
26
|
-
## 2.
|
27
|
-
-
|
26
|
+
## 2. Set `private_key` and `client_email`
|
27
|
+
- There are two ways to set `private_key` and `client_email`
|
28
|
+
- How to get above two Key-Value sets is written later
|
29
|
+
|
30
|
+
### 2-1. The first way: Create API configuration file
|
31
|
+
- Create `./config/key_and_email.yml`
|
28
32
|
- This YAML file must contain two Key-Value sets
|
29
33
|
- `private_key` and its value
|
30
34
|
- `client_email` and its value
|
31
|
-
|
35
|
+
|
36
|
+
### 2-2. The second way: Set values as arguments
|
37
|
+
- Set arguments of `SimpleGaReports.filtered_results` method
|
38
|
+
- For example:
|
39
|
+
- `SimpleGaReports.filtered_results(private_key: 'FOO', client_email: 'BAR')`
|
40
|
+
- Convenient when you set by environment variables
|
32
41
|
|
33
42
|
## 3. Create Google Analytics reporting configuration file
|
34
43
|
- You must create the YAML file which contains Google Analytics reporting configuration such as `start-date`, `end-date`, `metrics`, `demensions`, `filters` and etc.
|
@@ -49,7 +58,7 @@ $ gem install simple-ga-reporting
|
|
49
58
|
- `SimpleGaReports.filtered_results`
|
50
59
|
- Only three lines :-)
|
51
60
|
- Note
|
52
|
-
- If you don't use filters,
|
61
|
+
- If you don't use filters, use `SimpleGaReports.raw_results` too
|
53
62
|
- when no filter is in configure file, `SimpleGaReports.raw_results` is the same as `SimpleGaReports.filtered_results`
|
54
63
|
|
55
64
|
```ruby
|
@@ -59,24 +68,28 @@ SimpleGaReports.configure
|
|
59
68
|
SimpleGaReports.filtered_results #=> Legato::Query
|
60
69
|
```
|
61
70
|
|
62
|
-
#
|
71
|
+
# Detail of configuration
|
63
72
|
|
64
|
-
## API
|
65
|
-
- You must
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
73
|
+
## 1. Configuration of API account
|
74
|
+
- You must set Google Analytics API configuration, `private_key` and `client_email`
|
75
|
+
- There are two ways to set it
|
76
|
+
- The one is by arguments
|
77
|
+
- Set arguments of `SimpleGaReports.filtered_results` method
|
78
|
+
- The other is by YAML file
|
79
|
+
- Default filepath is `./config/key_and_email.yml`
|
80
|
+
- You can change filepath by argument
|
81
|
+
- The sample of YAML file is below
|
69
82
|
|
70
83
|
```yaml
|
71
84
|
private_key: "-----BEGIN PRIVATE KEY-----\nMIIE..........Eqw==\n-----END PRIVATE KEY-----\n"
|
72
85
|
client_email: "your_account_name@foobar.iam.gserviceaccount.com"
|
73
86
|
```
|
74
87
|
|
75
|
-
## Google Analytics reporting configuration
|
88
|
+
## 2. Google Analytics reporting configuration
|
76
89
|
- You must create the YAML file which contains Google Analytics reporting configuration
|
77
90
|
- Default filepath is `./config/ga_reporting_config.yml`
|
78
|
-
- You can change filepath by argument
|
79
|
-
-
|
91
|
+
- You can change filepath by argument in `SimpleGaReports.configure` method
|
92
|
+
- The sample of YAML file is below
|
80
93
|
|
81
94
|
```yaml
|
82
95
|
profile_name: my_profile_name
|
@@ -98,12 +111,12 @@ filters:
|
|
98
111
|
limit: 20
|
99
112
|
```
|
100
113
|
|
101
|
-
- Please refer the official documents as
|
114
|
+
- Please refer the official documents as Key-Value sets
|
102
115
|
- https://developers.google.com/analytics/devguides/reporting/core/v3/reference
|
103
116
|
|
104
117
|
![ga_query_parametes_summary.png](images/ga_query_parametes_summary.png)
|
105
118
|
|
106
|
-
- Though
|
119
|
+
- Though above official documents show many Key-Value sets, you can config only several sets as below
|
107
120
|
- start-date
|
108
121
|
- end-date
|
109
122
|
- metrics
|
@@ -120,7 +133,7 @@ limit: 20
|
|
120
133
|
- The type of `metrics`, `dimensions`, `sort` and `filters` is `Array`
|
121
134
|
- The order of elements doesn't matter
|
122
135
|
|
123
|
-
|
136
|
+
### 2-1. Key-Value detail
|
124
137
|
|
125
138
|
#### profile_name
|
126
139
|
- REQUIRED
|
@@ -154,7 +167,6 @@ limit: 20
|
|
154
167
|
|
155
168
|
![Dimensions & Metrics Explorer](images/dimensions_and_metrics_explorer.png)
|
156
169
|
|
157
|
-
|
158
170
|
#### dimensions
|
159
171
|
- optional
|
160
172
|
- Official documents are below (very useful!)
|
@@ -188,7 +200,7 @@ limit: 20
|
|
188
200
|
- Original Key name is `samplingLevel`
|
189
201
|
- Default value is `HIGHER_PRECISION`
|
190
202
|
|
191
|
-
## filters file
|
203
|
+
## 3. filters file
|
192
204
|
- You use filters function using `filters.rb` file
|
193
205
|
- the filename `filters.rb` is determined
|
194
206
|
- only filepath is optional
|
@@ -225,26 +237,42 @@ end
|
|
225
237
|
## Note
|
226
238
|
**YOU MUST SPECIFY ARGUMENTS AS RELATIVE FILEPATH SO YOU MUST ADD './' (dot slash) AT BEGINNING**
|
227
239
|
|
240
|
+
- Set arguments of `SimpleGaReports.filtered_results` method
|
241
|
+
- For example:
|
242
|
+
- `SimpleGaReports.filtered_results(private_key: 'FOO', client_email: 'BAR')
|
243
|
+
- Convenient when you set by environment variables
|
244
|
+
|
228
245
|
## `SimpleGaReports.filtered_results` method
|
229
|
-
-
|
230
|
-
- If you don't use filters, use `SimpleGaReports.raw_results` method
|
246
|
+
- If you don't use filters, use `SimpleGaReports.raw_results` method instead of `SimpleGaReports.filtered_results` method
|
231
247
|
- when no filter is in configure file, `SimpleGaReports.raw_results` is the same as `SimpleGaReports.filtered_results`
|
248
|
+
- take three arguments
|
249
|
+
- All arguments are keyword ones
|
250
|
+
- You must set (`key_and_email_file`) or (`private_key` and `client_email`)
|
232
251
|
|
233
252
|
1. `key_and_email_file`
|
234
253
|
- default is `./config/key_and_email.yml`
|
235
254
|
|
255
|
+
1. `private_key`
|
256
|
+
- default is `nil`
|
257
|
+
|
258
|
+
1. `client_email`
|
259
|
+
- default is `nil`
|
260
|
+
|
236
261
|
## `SimpleGaReports.configure` method
|
237
262
|
- take three arguments
|
263
|
+
- All arguments are keyword ones
|
238
264
|
|
239
|
-
1. `
|
265
|
+
1. `report_config`
|
240
266
|
- first argument
|
267
|
+
- YAML file
|
241
268
|
- default is `./config/ga_reporting_config.yml`
|
242
269
|
|
243
|
-
|
270
|
+
2. `filters`
|
244
271
|
- second argument
|
272
|
+
- filter file
|
245
273
|
- default is `./config/filters.rb`
|
246
274
|
|
247
|
-
|
275
|
+
3. `**options`
|
248
276
|
- third argument
|
249
277
|
- default is nil
|
250
278
|
- if you set this argument, you can overwrite values in Google Analytics reporting configuration file
|
@@ -313,7 +341,7 @@ end
|
|
313
341
|
require 'simple_ga_reporting'
|
314
342
|
|
315
343
|
SimpleGaReports.configure(report_config: './bar/my_ga_reporting_config.yml', filters: './foobar/filters.rb', start_date: '2daysAgo', limit: 100)
|
316
|
-
results = SimpleGaReports.filtered_results(key_and_email: './foo/my_key_and_email.yml')
|
344
|
+
results = SimpleGaReports.filtered_results(key_and_email: './foo/my_key_and_email.yml') # or use arguments of 'private_key:' and 'client_email:'
|
317
345
|
|
318
346
|
results.each do |result|
|
319
347
|
puts '==================================='
|
@@ -330,6 +358,8 @@ private_key: "-----BEGIN PRIVATE KEY-----\nMIIE..........Eqw==\n-----END PRIVATE
|
|
330
358
|
client_email: "your_account_name@foobar.iam.gserviceaccount.com"
|
331
359
|
```
|
332
360
|
|
361
|
+
- You can set two key and value by not only YAML file but also arguments of `SimpleGaReports.filtered_results` method
|
362
|
+
|
333
363
|
#### 3. `./bar/my_ga_reporting_config.yml`
|
334
364
|
```yaml
|
335
365
|
profile_name: my_profile_name
|
@@ -390,6 +420,13 @@ HAPPY CHECK!
|
|
390
420
|
......
|
391
421
|
```
|
392
422
|
|
423
|
+
# Rails
|
424
|
+
When you use this gem on Rails, it's simple :)
|
425
|
+
|
426
|
+
1. add this gem to `Gemfile`
|
427
|
+
2. `$ bundle install`
|
428
|
+
3. after it, the same way above
|
429
|
+
|
393
430
|
# Very Awesome Reference Book (Recommended)
|
394
431
|
- [わかばちゃんと学ぶ Googleアナリティクス (Let's study Google Analytics with Wakaba-Chan)](http://www.c-r.com/book/detail/1217)
|
395
432
|
|
@@ -419,7 +456,8 @@ HAPPY CHECK!
|
|
419
456
|
- offset
|
420
457
|
- quota_user
|
421
458
|
- segment_id
|
422
|
-
-
|
459
|
+
- ~~`segment` is the same as conbination of filters, so you can use 'filters' as alternative way~~
|
460
|
+
- `segment` is the first filter for initial population and it can't substitute
|
423
461
|
|
424
462
|
# Development
|
425
463
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
File without changes
|
data/bin/console
CHANGED
File without changes
|
data/bin/setup
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/images/ga_profile(view).png
CHANGED
File without changes
|
File without changes
|
data/images/gcp_api_menu.png
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/lib/simple_ga_reporting.rb
CHANGED
File without changes
|
File without changes
|
@@ -11,15 +11,18 @@ module LegatoGaUser
|
|
11
11
|
TOKEN_URL = 'https://accounts.google.com/o/oauth2/token'.freeze
|
12
12
|
|
13
13
|
# private
|
14
|
-
def create_ga_user(key_and_email)
|
15
|
-
|
14
|
+
def create_ga_user(key_and_email, private_key: nil, client_email: nil)
|
15
|
+
ga_user_private_key = private_key.nil? ? private_key(key_and_email) : private_key
|
16
|
+
ga_user_client_email = client_email.nil? ? client_email(key_and_email) : client_email
|
17
|
+
|
18
|
+
signing_key = OpenSSL::PKey::RSA.new(ga_user_private_key)
|
16
19
|
auth_client = Signet::OAuth2::Client.new(
|
17
20
|
token_credential_uri: TOKEN_CREDENTIAL_URI,
|
18
21
|
audience: AUDIENCE,
|
19
22
|
scope: SCOPE,
|
20
|
-
issuer:
|
23
|
+
issuer: ga_user_client_email,
|
21
24
|
signing_key: signing_key,
|
22
|
-
sub:
|
25
|
+
sub: ga_user_client_email,
|
23
26
|
)
|
24
27
|
access_token = auth_client.fetch_access_token!
|
25
28
|
|
@@ -20,14 +20,14 @@ class << SimpleGaReports
|
|
20
20
|
query_parameters($model_config, options)
|
21
21
|
end
|
22
22
|
|
23
|
-
def filtered_results(key_and_email: 'config/key_and_email.yml')
|
24
|
-
raw_results = raw_results(key_and_email)
|
23
|
+
def filtered_results(key_and_email: 'config/key_and_email.yml', private_key: nil, client_email: nil)
|
24
|
+
raw_results = raw_results(key_and_email, private_key: private_key, client_email: client_email)
|
25
25
|
filtering(raw_results)
|
26
26
|
end
|
27
27
|
|
28
|
-
def raw_results(key_and_email)
|
28
|
+
def raw_results(key_and_email, private_key:, client_email:)
|
29
29
|
# 'legato_ga_model' method is generated by Model class automatically
|
30
|
-
query = ga_profile(key_and_email).legato_ga_model
|
30
|
+
query = ga_profile(key_and_email, private_key: private_key, client_email: client_email).legato_ga_model
|
31
31
|
|
32
32
|
query.results(
|
33
33
|
start_date: @start_date,
|
@@ -52,8 +52,8 @@ class << SimpleGaReports
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# TODO: should specify by profile id, too
|
55
|
-
def ga_profile(key_and_email)
|
56
|
-
ga_user = create_ga_user(key_and_email)
|
55
|
+
def ga_profile(key_and_email, private_key:, client_email:)
|
56
|
+
ga_user = create_ga_user(key_and_email, private_key: private_key, client_email: client_email)
|
57
57
|
|
58
58
|
ga_user.profiles.each do |profile|
|
59
59
|
return profile if profile.name === @profile_name
|
data/simple_ga_reporting.gemspec
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_ga_reporting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Osamu Takiya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
183
|
version: '0'
|
184
184
|
requirements: []
|
185
185
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.7.
|
186
|
+
rubygems_version: 2.7.6
|
187
187
|
signing_key:
|
188
188
|
specification_version: 4
|
189
189
|
summary: With simple configuration (YAML), you can obtain Google Analytics reporting
|