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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f221a740b8c7c09dca3d7610864ec4d7593eb14ee85a7f263d76576880d5ee1c
4
- data.tar.gz: 40473825da12f440658e5f140ab0f06cd4eb70632a7247f7fec06e65a7fdf58c
3
+ metadata.gz: fa9e0716b143f6bcd77b14b370d0be17a9cbb342b003112c1f751b3f62a77c28
4
+ data.tar.gz: 9365ff9c38abdd3843b655eed514561c2cc8b0f4d2023b2677d876cf0a9f3c54
5
5
  SHA512:
6
- metadata.gz: 5fa0a15cde2dc0ee6df4b6f763a99bc4197c8315833398f079cee538cfd3ffdafe5aaf170299de50df2195dd81c0019980416c47eef463c2172d7d1c1673ddc2
7
- data.tar.gz: a3029692fb6e0ebf7a2a7fbbef3d27318d1dfb82d7bdf9f7d15a2e57dda6530d821c4907ce4fa5a87eabe6fa98796884ed88ab1103e71fcb2ad57d6443143fa5
6
+ metadata.gz: 6c15749c7b62e206da384a60038efc2e68a4f7af05e3124b075c59c9db7dcfa63fa9343eba76bc9f95fbad299f95b28213b904dc22182f703832fa2675237cb9
7
+ data.tar.gz: 759044dc38c099c886fe41b8cc8f845e880fa5e5ab067651b878fdc3585761a6d19cadeae5d239ffb5f4b61ef25b69b525d93a786b6808298ff1737d51579a53
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
File without changes
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, `simple-ga-reporting`.
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 simple-ga-reporting
23
+ $ gem install simple_ga_reporting
24
24
  ```
25
25
 
26
- ## 2. Create API configuration file
27
- - You must create `./config/key_and_email.yml`
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
- - How to get above two Key-Value sets is written later
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, also use `SimpleGaReports.raw_results`
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
- # Configuration files
71
+ # Detail of configuration
63
72
 
64
- ## API configuration file
65
- - You must create Google Analytics API configuration file
66
- - Default filepath is `./config/key_and_email.yml`
67
- - You can change filepath by argument with `create_ga_user` method
68
- - Sample is below
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 file
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 with `configure` method
79
- - Sample is below
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 configuration Key-Value sets
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 that documents show many Key-Value sets, you can config only several sets as below
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
- ## Key-Value detail
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
- - take one argument
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. `yaml_file`
265
+ 1. `report_config`
240
266
  - first argument
267
+ - YAML file
241
268
  - default is `./config/ga_reporting_config.yml`
242
269
 
243
- 1. `filters_file`
270
+ 2. `filters`
244
271
  - second argument
272
+ - filter file
245
273
  - default is `./config/filters.rb`
246
274
 
247
- 1. `**options`
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
- - `segment` is the same as conbination of filters, so you can use 'filters' as alternative way
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
File without changes
data/bin/setup CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
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
- signing_key = OpenSSL::PKey::RSA.new(private_key(key_and_email))
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: client_email(key_and_email),
23
+ issuer: ga_user_client_email,
21
24
  signing_key: signing_key,
22
- sub: client_email(key_and_email),
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
@@ -1,3 +1,3 @@
1
1
  module SimpleGaReporting
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
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.2.0
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-04-19 00:00:00.000000000 Z
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.3
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