embulk-output-google_analytics 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +3 -0
- data/embulk-output-google_analytics.gemspec +21 -0
- data/example/costdata.yml +26 -0
- data/lib/embulk/output/google_analytics.rb +8 -0
- data/lib/embulk/output/google_analytics/client.rb +49 -0
- data/lib/embulk/output/google_analytics/plugin.rb +79 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 44c03abf705ee490d970a063cc0bb698957b7132dd06ce04d203064ea91d43fd
|
4
|
+
data.tar.gz: 447a46028d705c218892269170e775be1e2801989d438e4ef0b0b7a489e62c47
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8824a183a607745e0ad48f6c61c01d3ff9cd40060e71e0955de20c57da4879a3cf69ec70bf10340dab866f0fa28dba37bb67b6a3bca32ad48e3f2f3c84d83be
|
7
|
+
data.tar.gz: 52295050295aabdbb728ed0abf9da32c6b96e2cebe168ef6ce0b8a97ca2682955357fdd10e5b4dafc346486f93cddbc9e9f4e244a77965fdcecdaa7eba609dd3
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-9.1.13.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Google Analytics output plugin for Embulk
|
2
|
+
This plugin performs the data import and measurement protocol into Google Analytis.
|
3
|
+
However, Measurement Protocol feature is not implemented.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
* **Plugin type**: output
|
7
|
+
* **Load all or nothing**: no
|
8
|
+
* **Resume supported**: no
|
9
|
+
* **Cleanup supported**: no
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
- **action**: "dataimport" or "measurement_protocol" (string, default: `"dataimport"`)
|
13
|
+
- **client_id**: authentication (string, required)
|
14
|
+
- **client_secret**: authentication (string, required)
|
15
|
+
- **refresh_token**: authentication (string, required)
|
16
|
+
- **account_id**: Your google analytics account id (string, required)
|
17
|
+
- **webproperty_id**: Your google analytics Web Property id (string, required)
|
18
|
+
- **datasource_id**: Your google analytics Data Source id (string, default: `nil`)
|
19
|
+
- **filename**: Your upload filename (string, default: `nil`)
|
20
|
+
|
21
|
+
## Example
|
22
|
+
|
23
|
+
```yaml
|
24
|
+
out:
|
25
|
+
type: google_analytics
|
26
|
+
action: dataimport
|
27
|
+
client_id: xxxxxxxxx.apps.googleusercontent.com
|
28
|
+
client_secret: yyyyyyyyyyyyyyy
|
29
|
+
refresh_token: 1/zzzzzzzzzzzzzzzzzzzzz
|
30
|
+
account_id: xyz
|
31
|
+
webproperty_id: UA-xyz-a
|
32
|
+
datasource_id: xxxxxxxxxxxxx
|
33
|
+
filename: "Sample Cost Data.csv"
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
## Build
|
38
|
+
|
39
|
+
```
|
40
|
+
$ rake
|
41
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-output-google_analytics"
|
4
|
+
spec.version = "0.1.0"
|
5
|
+
spec.authors = ["ryota.yamada"]
|
6
|
+
spec.summary = "Google Analytics output plugin for Embulk"
|
7
|
+
spec.description = "This plugin performs the data import and measurement protocol into Google Analytics."
|
8
|
+
spec.email = ["1987yama3@gmail.com"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.homepage = "https://github.com/sem-technology/embulk-output-google_analytics"
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_dependency "signet"
|
17
|
+
spec.add_dependency "google-api-client", "~> 0.9.11"
|
18
|
+
spec.add_development_dependency 'embulk', ['>= 0.8.38']
|
19
|
+
spec.add_development_dependency 'bundler', ['>= 1.10.6']
|
20
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
in:
|
2
|
+
type:
|
3
|
+
name: config
|
4
|
+
columns:
|
5
|
+
- {name: "ga:date", type: string}
|
6
|
+
- {name: "ga:source", type: string}
|
7
|
+
- {name: "ga:medium", type: string}
|
8
|
+
- {name: "ga:adClicks", type: long}
|
9
|
+
- {name: "ga:impressions", type: long}
|
10
|
+
- {name: "ga:adCost", type: long}
|
11
|
+
values:
|
12
|
+
- - ["20171201", "yahoo", "cpc", 23, 540, 1200]
|
13
|
+
- ["20171202", "yahoo", "cpc", 23, 540, 1200]
|
14
|
+
- ["20171203", "yahoo", "cpc", 23, 540, 1200]
|
15
|
+
- ["20171204", "yahoo", "cpc", 23, 540, 1200]
|
16
|
+
out:
|
17
|
+
type: google_analytics
|
18
|
+
action: dataimport
|
19
|
+
client_id: xxxxxxxxx.apps.googleusercontent.com
|
20
|
+
client_secret: yyyyyyyyyyyyyyy
|
21
|
+
refresh_token: 1/zzzzzzzzzzzzzzzzzzzzz
|
22
|
+
account_id: xyz
|
23
|
+
webproperty_id: UA-xyz-a
|
24
|
+
datasource_id: xxxxxxxxxxxxx
|
25
|
+
filename: "Sample Cost Data.csv"
|
26
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'google/apis/analytics_v3'
|
2
|
+
require 'stringio'
|
3
|
+
module Embulk
|
4
|
+
module Output
|
5
|
+
module GoogleAnalytics
|
6
|
+
class Client
|
7
|
+
def initialize(task)
|
8
|
+
@task = task
|
9
|
+
end
|
10
|
+
|
11
|
+
def upload(rows)
|
12
|
+
self.service.upload_data(@task['account_id'], @task['webproperty_id'], @task['datasource_id'], {
|
13
|
+
upload_source: make_upload_content(rows),
|
14
|
+
content_type: 'application/octet-stream',
|
15
|
+
options: {
|
16
|
+
header: {
|
17
|
+
'x-goog-upload-file-name' => @task['filename'],
|
18
|
+
}
|
19
|
+
}
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
def service
|
24
|
+
analytics_service = ::Google::Apis::AnalyticsV3::AnalyticsService.new
|
25
|
+
analytics_service.authorization = Signet::OAuth2::Client.new({
|
26
|
+
:token_credential_uri => @task["token_credential_uri"],
|
27
|
+
:audience => @task["audience"],
|
28
|
+
:client_id => @task["client_id"],
|
29
|
+
:client_secret => @task["client_secret"],
|
30
|
+
:refresh_token => @task["refresh_token"],
|
31
|
+
:scope => @task["scope"],
|
32
|
+
})
|
33
|
+
analytics_service.authorization.fetch_access_token!
|
34
|
+
analytics_service
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def make_upload_content(rows)
|
39
|
+
io = StringIO.new
|
40
|
+
io.puts(rows.first.collect{|k,v| k }.join(","))
|
41
|
+
rows.each do |row|
|
42
|
+
io.puts(row.collect{|k, v| v}.join(","))
|
43
|
+
end
|
44
|
+
io
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Embulk
|
2
|
+
module Output
|
3
|
+
module GoogleAnalytics
|
4
|
+
class Plugin < OutputPlugin
|
5
|
+
::Embulk::Plugin.register_output("google_analytics", self)
|
6
|
+
|
7
|
+
def self.transaction(config, schema, count, &control)
|
8
|
+
# configuration code:
|
9
|
+
task = {
|
10
|
+
"token_credential_uri" => "https://accounts.google.com/o/oauth2/token",
|
11
|
+
"audience" => "https://accounts.google.com/o/oauth2/token",
|
12
|
+
"client_id" => config.param("client_id", :string),
|
13
|
+
"client_secret" => config.param("client_secret", :string),
|
14
|
+
"refresh_token" => config.param("refresh_token", :string),
|
15
|
+
"scope" => "https://www.googleapis.com/auth/analytics.edit",
|
16
|
+
|
17
|
+
"action" => config.param("action", :string, default: 'dataimport'),
|
18
|
+
"account_id" => config.param("account_id", :string),
|
19
|
+
"webproperty_id" => config.param("webproperty_id", :string),
|
20
|
+
"datasource_id" => config.param("datasource_id", :string, default: nil),
|
21
|
+
"filename" => config.param("filename", :string, default: nil),
|
22
|
+
}
|
23
|
+
task_check(task)
|
24
|
+
|
25
|
+
# resumable output:
|
26
|
+
# resume(task, schema, count, &control)
|
27
|
+
|
28
|
+
# non-resumable output:
|
29
|
+
task_reports = yield(task)
|
30
|
+
next_config_diff = {}
|
31
|
+
return next_config_diff
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.task_check(task)
|
35
|
+
if task['action'] == 'dataimport'
|
36
|
+
if task['datasource_id'].nil?
|
37
|
+
Embulk.logger.error 'datasource_id is required'
|
38
|
+
raise 'datasource_id is required'
|
39
|
+
elsif task['filename'].nil?
|
40
|
+
Embulk.logger.error 'filename is required'
|
41
|
+
raise 'filenam is required'
|
42
|
+
end
|
43
|
+
elsif task['action'] == 'measurement_protocol'
|
44
|
+
Embulk.logger.error 'Sorry, Measurement Protocol feature is not implemented'
|
45
|
+
raise 'Measurement Protocol feature is not implemented'
|
46
|
+
else
|
47
|
+
Embulk.logger.error 'ACTION_ERROR'
|
48
|
+
raise 'ACTION_ERROR'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def init
|
53
|
+
@client = Client.new(@task)
|
54
|
+
end
|
55
|
+
|
56
|
+
def close
|
57
|
+
end
|
58
|
+
|
59
|
+
def add(page)
|
60
|
+
if task['action'] == 'dataimport'
|
61
|
+
rows = page.collect{|record| Hash[schema.names.zip(record)] }
|
62
|
+
@client.upload(rows)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def finish
|
67
|
+
end
|
68
|
+
|
69
|
+
def abort
|
70
|
+
end
|
71
|
+
|
72
|
+
def commit
|
73
|
+
task_report = {}
|
74
|
+
return task_report
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-output-google_analytics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ryota.yamada
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
name: signet
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.11
|
33
|
+
name: google-api-client
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.11
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.8.38
|
47
|
+
name: embulk
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.38
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.10.6
|
61
|
+
name: bundler
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.10.6
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
name: rake
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: This plugin performs the data import and measurement protocol into Google
|
84
|
+
Analytics.
|
85
|
+
email:
|
86
|
+
- 1987yama3@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".ruby-version"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- embulk-output-google_analytics.gemspec
|
98
|
+
- example/costdata.yml
|
99
|
+
- lib/embulk/output/google_analytics.rb
|
100
|
+
- lib/embulk/output/google_analytics/client.rb
|
101
|
+
- lib/embulk/output/google_analytics/plugin.rb
|
102
|
+
homepage: https://github.com/sem-technology/embulk-output-google_analytics
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.6.13
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Google Analytics output plugin for Embulk
|
126
|
+
test_files: []
|