logstash-input-google-analytics-daily 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/logstash/inputs/google_analytics_daily.rb +34 -31
- data/logstash-input-google-analytics-daily.gemspec +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4be2dcf54047afbe18aee1ceac9f2992b8044a1b88cb5d8be5a5fa40ea978ed5
|
4
|
+
data.tar.gz: d5355c716a8c5ee2bfa3b8dd6f5694c8a8151f58f8f6d16fab184b5c09cb3ba6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b6c4ee7ee1f40e13980d2b0f7b551dbcddc46afd4ed3f234077dedcfbc32bb8819a65db1afdf272811bee25b9869612f690b69616df5e5e0116a33497c2971c
|
7
|
+
data.tar.gz: d10be71488dbb1a07c49da9f0b7cf33530bc27b8b228339201e53e29dd4b8afa21486afc313e4633aa8c8f24022ed889886f4fac06045b1de7038d0fff4124f6
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Forked from https://github.com/russorat/logstash-input-googleanalytics.git.
|
|
6
6
|
|
7
7
|
## Documentation
|
8
8
|
|
9
|
-
Documentation can be seen in [the docs folder](https://github.com/DeimosCloud/logstash-input-google-analytics-daily/blob/master/docs/index.asciidoc).
|
9
|
+
Documentation can be seen in [the docs folder](https://github.com/DeimosCloud/logstash-input-google-analytics-daily/blob/master/docs/index.asciidoc) (for now). Hopefully, this moves to logstash-plugins repo soon, so it can be rendered properly on elastic.co,
|
10
10
|
|
11
11
|
## Developing
|
12
12
|
|
@@ -4,6 +4,7 @@ require "logstash/namespace"
|
|
4
4
|
require "stud/interval"
|
5
5
|
require 'google/apis/analytics_v3'
|
6
6
|
require 'googleauth'
|
7
|
+
require 'json'
|
7
8
|
|
8
9
|
# Pull daily reports from Google Analytics using the v3 Core Reporting API.
|
9
10
|
# This plugin will generate one Logstash event per date, with each event containing all the data for that date
|
@@ -26,9 +27,11 @@ class LogStash::Inputs::GoogleAnalyticsDaily < LogStash::Inputs::Base
|
|
26
27
|
# https://developers.google.com/analytics/devguides/reporting/core/v3/reference#ids
|
27
28
|
config :view_id, :validate => :string, :required => true
|
28
29
|
|
29
|
-
# This plugin will
|
30
|
-
# In the format YYYY-MM-DD
|
31
|
-
config :
|
30
|
+
# This plugin will fetch daily reports for dates in the specified range
|
31
|
+
# In the format YYYY-MM-DD
|
32
|
+
config :start_date, :validate => :string, :required => true
|
33
|
+
|
34
|
+
config :end_date, :validate => :string, :required => true
|
32
35
|
|
33
36
|
# The aggregated statistics for user activity to your site, such as clicks or pageviews.
|
34
37
|
# Maximum of 10 metrics for any query
|
@@ -95,7 +98,10 @@ class LogStash::Inputs::GoogleAnalyticsDaily < LogStash::Inputs::Base
|
|
95
98
|
|
96
99
|
analytics = get_service
|
97
100
|
|
101
|
+
@dates = (Date.parse(@start_date)..Date.parse(@end_date))
|
102
|
+
|
98
103
|
@dates.each do |date|
|
104
|
+
date = date.to_s
|
99
105
|
options = get_request_parameters(date)
|
100
106
|
|
101
107
|
results = analytics.get_ga_data(
|
@@ -155,42 +161,39 @@ class LogStash::Inputs::GoogleAnalyticsDaily < LogStash::Inputs::Base
|
|
155
161
|
query = results.query.to_h
|
156
162
|
profile_info = results.profile_info.to_h
|
157
163
|
|
158
|
-
#
|
164
|
+
# Transform into proper format for one event per metric
|
159
165
|
@metrics.each do |metric|
|
160
166
|
rows_for_this_metric = rows.clone.map do |row|
|
161
|
-
|
162
|
-
new_row = row.clone
|
167
|
+
new_row = {}
|
163
168
|
new_row[:metric] = row[:metrics].find { |m| m[:name] == metric }
|
164
|
-
new_row
|
169
|
+
new_row[:dimensions] = row[:dimensions]
|
165
170
|
new_row
|
166
171
|
end
|
167
172
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
event.set('ga.query.end_date', query["end_date"].to_s) if @store_query
|
176
|
-
|
177
|
-
event.set('ga.profile_info', profile_info) if @store_profile
|
178
|
-
|
179
|
-
if date == 'today'
|
180
|
-
event.set('ga.date', Time.now.strftime("%F"))
|
181
|
-
elsif date == 'yesterday'
|
182
|
-
event.set('ga.date', Time.at(Time.now.to_i - 86400).strftime("%F"))
|
183
|
-
elsif date.include?('daysAgo')
|
184
|
-
days_ago = date.sub('daysAgo', '').to_i
|
185
|
-
event.set('ga.date', Time.at(Time.now.to_i - (days_ago * 86400)).strftime("%F"))
|
186
|
-
else
|
173
|
+
rows_for_this_metric.each do |row|
|
174
|
+
event = LogStash::Event.new
|
175
|
+
decorate(event)
|
176
|
+
# Populate Logstash event fields
|
177
|
+
event.set('ga.contains_sampled_data', results.contains_sampled_data?)
|
178
|
+
event.set('ga.query', query.to_json) if @store_query
|
179
|
+
event.set('ga.profile_info', profile_info) if @store_profile
|
187
180
|
event.set('ga.date', date)
|
188
|
-
end
|
189
181
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
182
|
+
event.set("ga.metric.name", metric)
|
183
|
+
event.set("ga.metric.value", row[:metric][:value])
|
184
|
+
|
185
|
+
|
186
|
+
# Remap dimensions into key: value
|
187
|
+
# Might lead to "mapping explosion", but otherwise aggregations are tough
|
188
|
+
joined_dimension_name = ''
|
189
|
+
row[:dimensions].each do |d|
|
190
|
+
dimension_name = d[:name].sub("ga:", '')
|
191
|
+
joined_dimension_name += dimension_name
|
192
|
+
event.set("ga.dimensions.#{dimension_name}", d[:value])
|
193
|
+
end
|
194
|
+
|
195
|
+
queue << event
|
196
|
+
end
|
194
197
|
end
|
195
198
|
end
|
196
199
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-input-google-analytics-daily'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.3.0'
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = "Logstash plugin to pull daily reports from Google Analytics."
|
6
6
|
s.description = "Logstash plugin to pull daily reports from the Google Analytics v3 Core Reporting API. Install into Logstash using $LS_HOME/bin/logstash-plugin install logstash-input-google-analytics-daily."
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_runtime_dependency 'stud', '>= 0.0.22'
|
23
23
|
s.add_runtime_dependency 'google-api-client', "~> 0.37"
|
24
24
|
s.add_runtime_dependency 'googleauth', ">= 0.10.0"
|
25
|
+
s.add_runtime_dependency 'json'
|
25
26
|
s.add_development_dependency 'vcr'
|
26
27
|
s.add_development_dependency 'webmock'
|
27
|
-
s.add_development_dependency 'json'
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-google-analytics-daily
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shalvah
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,8 +78,8 @@ dependencies:
|
|
78
78
|
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
|
-
name:
|
82
|
-
type: :
|
81
|
+
name: json
|
82
|
+
type: :runtime
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
@@ -92,7 +92,7 @@ dependencies:
|
|
92
92
|
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
|
-
name:
|
95
|
+
name: vcr
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
|
-
name:
|
109
|
+
name: webmock
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|