rudder_analytics_sync 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -3
- data/README.md +12 -73
- data/example/example.rb +34 -25
- data/lib/rudder_analytics_sync/batch.rb +10 -0
- data/lib/rudder_analytics_sync/operations/identify.rb +4 -1
- data/lib/rudder_analytics_sync/operations/operation.rb +17 -9
- data/lib/rudder_analytics_sync/operations/page.rb +3 -2
- data/lib/rudder_analytics_sync/operations/screen.rb +21 -0
- data/lib/rudder_analytics_sync/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c6c66facc1d6ffdce7cf7f8e4e53988fb8ffa19
|
4
|
+
data.tar.gz: e6c5773b8adfa4a776baaa2022bb251ae22c1c7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 071df6c5a1c30d11960bbfb05da4a58d1eb804349f7eecf61450caaea2ff4ca562e1eb88ecaa1a49f14c6a8e312349c16ef4d02e10de29c2a72bc0cb7802fd10
|
7
|
+
data.tar.gz: 40cdc7f1990658b6b601ebcdecf4e77ab238e1394cdaa525747f5847c115e7b871c553c77fe668ed71db89be1ed14f2e7c2fc88386d3fa751e08982f4fa19aa3
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,38 +1,25 @@
|
|
1
|
-
#
|
1
|
+
# What is Rudder?
|
2
2
|
|
3
|
-
|
3
|
+
**Short answer:**
|
4
|
+
Rudder is an open-source Segment alternative written in Go, built for the enterprise. .
|
4
5
|
|
5
|
-
|
6
|
+
**Long answer:**
|
7
|
+
Rudder is a platform for collecting, storing and routing customer event data to dozens of tools. Rudder is open-source, can run in your cloud environment (AWS, GCP, Azure or even your data-centre) and provides a powerful transformation framework to process your event data on the fly.
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
## Status
|
10
|
-
|
11
|
-
The gem supports all existing functionality of analytics-ruby:
|
12
|
-
|
13
|
-
- `analytics.track(...)`
|
14
|
-
- `analytics.identify(...)`
|
15
|
-
- `analytics.group(...)`
|
16
|
-
- `analytics.page(...)`
|
17
|
-
- `analytics.alias(...)`
|
18
|
-
- `analytics.flush` (no op for backwards compatibility with the official gem)
|
19
|
-
|
20
|
-
In addition it offers the ability to manually batch events with [analytics.batch](#batching).
|
21
|
-
|
22
|
-
The plan is to be an drop in replacement for the official gem, so if you find inconsistencies with `analytics-ruby` feel free to file an issue.
|
9
|
+
Released under [MIT License 2.0](https://opensource.org/licenses/MIT)
|
23
10
|
|
24
11
|
## Installation
|
25
12
|
|
26
13
|
Add this line to your application's Gemfile:
|
27
14
|
|
28
15
|
```ruby
|
29
|
-
gem '
|
16
|
+
gem 'rudder_analytics_sync'
|
30
17
|
```
|
31
18
|
|
32
19
|
Or install it yourself as:
|
33
20
|
|
34
21
|
```sh
|
35
|
-
$ gem install
|
22
|
+
$ gem install rudder_analytics_sync
|
36
23
|
```
|
37
24
|
|
38
25
|
## Usage
|
@@ -41,7 +28,8 @@ Create a client instance:
|
|
41
28
|
|
42
29
|
```ruby
|
43
30
|
analytics = RudderAnalyticsSync::Client.new(
|
44
|
-
write_key:
|
31
|
+
write_key: <YOUR_WRITE_KEY>, # required
|
32
|
+
data_plane_url: <DATA_PLANE_URL>
|
45
33
|
on_error: proc { |error_code, error_body, exception, response|
|
46
34
|
# defaults to an empty proc
|
47
35
|
}
|
@@ -72,54 +60,5 @@ analytics.batch do |batch|
|
|
72
60
|
end
|
73
61
|
```
|
74
62
|
|
75
|
-
|
76
|
-
|
77
|
-
You can stub your API calls avoiding unecessary requests in development and automated test environments (backwards compatible with the official gem):
|
78
|
-
|
79
|
-
```ruby
|
80
|
-
analytics = RudderAnalyticsSync::Client.new(
|
81
|
-
write_key: 'YOUR_WRITE_KEY',
|
82
|
-
stub: true
|
83
|
-
)
|
84
|
-
```
|
85
|
-
|
86
|
-
### Configurable Logger
|
87
|
-
|
88
|
-
When used in stubbed mode all calls are logged to STDOUT, this can be changed by providing a custom logger object:
|
89
|
-
|
90
|
-
```ruby
|
91
|
-
analytics = RudderAnalyticsSync::Client.new(
|
92
|
-
write_key: 'YOUR_WRITE_KEY',
|
93
|
-
logger: Rails.logger
|
94
|
-
)
|
95
|
-
```
|
96
|
-
|
97
|
-
### Set HTTP Options
|
98
|
-
|
99
|
-
You can set [options](https://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html#method-c-start) that are passed to `Net::HTTP.start`.
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
analytics = RudderAnalyticsSync::Client.new(
|
103
|
-
write_key: 'YOUR_WRITE_KEY',
|
104
|
-
http_options: {
|
105
|
-
open_timeout: 42,
|
106
|
-
read_timeout: 42,
|
107
|
-
close_on_empty_response: true,
|
108
|
-
# ...
|
109
|
-
}
|
110
|
-
)
|
111
|
-
```
|
112
|
-
|
113
|
-
## Development
|
114
|
-
|
115
|
-
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.
|
116
|
-
|
117
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
118
|
-
|
119
|
-
## Contributing
|
120
|
-
|
121
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/whatthewhat/simple_segment.
|
122
|
-
|
123
|
-
## License
|
124
|
-
|
125
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
63
|
+
## Contact Us
|
64
|
+
If you come across any issues while configuring or using RudderStack, please feel free to [contact us](https://rudderstack.com/contact/) or start a conversation on our [Discord](https://discordapp.com/invite/xNEdEGw) channel. We will be happy to help you.
|
data/example/example.rb
CHANGED
@@ -5,6 +5,7 @@ include RudderAnalyticsSync
|
|
5
5
|
analytics = RudderAnalyticsSync::Client.new(
|
6
6
|
write_key: '1aJDXU7xlQpUp6qW1ppTJTvkgSi', # required
|
7
7
|
data_plane_url: 'https://86143ed0.ngrok.io',
|
8
|
+
stub: true,
|
8
9
|
on_error: proc { |error_code, error_body, exception, response|
|
9
10
|
# defaults to an empty proc
|
10
11
|
}
|
@@ -16,29 +17,37 @@ analytics = RudderAnalyticsSync::Client.new(
|
|
16
17
|
# )
|
17
18
|
|
18
19
|
analytics.batch do |batch|
|
19
|
-
batch.
|
20
|
-
|
21
|
-
|
22
|
-
)
|
23
|
-
batch.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
20
|
+
batch.context = { source: "test"}
|
21
|
+
batch.integrations = { All: false, S3: true }
|
22
|
+
batch.track({ event: "test" })
|
23
|
+
batch.identify({ user_id: "test" })
|
24
|
+
batch.screen({ user_id: "test", name: 'test'})
|
25
|
+
batch.page({ user_id: "test", name: 'test'})
|
26
|
+
batch.alias({ user_id: "test", previous_id: 'test'})
|
27
|
+
batch.group({ group_id: "test" })
|
28
|
+
# batch.track(
|
29
|
+
# user_id: 'test_user_id',
|
30
|
+
# event: 'Created Account'
|
31
|
+
# )
|
32
|
+
# batch.page(
|
33
|
+
# user_id: 'test_user_id',
|
34
|
+
# name: 'Created Account',
|
35
|
+
# properties: {
|
36
|
+
# k1: 'v1'
|
37
|
+
# }
|
38
|
+
# )
|
39
|
+
# batch.track(
|
40
|
+
# user_id: 'test_user_id',
|
41
|
+
# event: 'Closed Account'
|
42
|
+
# )
|
43
|
+
# batch.identify(
|
44
|
+
# user_id: 'test_user_id_1',
|
45
|
+
# traits: {
|
46
|
+
# name: 'test'
|
47
|
+
# }
|
48
|
+
# )
|
49
|
+
# batch.group(
|
50
|
+
# user_id: 'test_user_id',
|
51
|
+
# group_id: 'group_id'
|
52
|
+
# )
|
44
53
|
end
|
@@ -27,10 +27,18 @@ module RudderAnalyticsSync
|
|
27
27
|
add(Operations::Page, options, __method__)
|
28
28
|
end
|
29
29
|
|
30
|
+
def screen(options)
|
31
|
+
add(Operations::Screen, options, __method__)
|
32
|
+
end
|
33
|
+
|
30
34
|
def group(options)
|
31
35
|
add(Operations::Group, options, __method__)
|
32
36
|
end
|
33
37
|
|
38
|
+
def alias(options)
|
39
|
+
add(Operations::Alias, options, __method__)
|
40
|
+
end
|
41
|
+
|
34
42
|
def context=(context)
|
35
43
|
payload[:context] = context
|
36
44
|
end
|
@@ -56,6 +64,8 @@ module RudderAnalyticsSync
|
|
56
64
|
def add(operation_class, options, action)
|
57
65
|
operation = operation_class.new(client, symbolize_keys(options))
|
58
66
|
operation_payload = operation.build_payload
|
67
|
+
operation_payload[:context] = operation_payload[:context].merge(payload[:context] || {})
|
68
|
+
operation_payload[:integrations] = payload[:integrations] || operation_payload[:integrations]
|
59
69
|
operation_payload[:type] = action
|
60
70
|
payload[:batch] << operation_payload
|
61
71
|
end
|
@@ -8,10 +8,13 @@ module RudderAnalyticsSync
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def build_payload
|
11
|
+
raise ArgumentError, 'user_id must be present' \
|
12
|
+
unless options[:user_id]
|
13
|
+
|
11
14
|
merged_payload = base_payload.merge(
|
12
15
|
traits: options[:traits] && isoify_dates!(options[:traits])
|
13
16
|
)
|
14
|
-
merged_payload[:context][:traits] = merged_payload[:context][:traits].merge(options[:traits])
|
17
|
+
merged_payload[:context][:traits] = merged_payload[:context][:traits].merge(options[:traits] || {})
|
15
18
|
merged_payload
|
16
19
|
end
|
17
20
|
end
|
@@ -32,31 +32,39 @@ module RudderAnalyticsSync
|
|
32
32
|
attr_reader :options, :request, :context
|
33
33
|
|
34
34
|
def base_payload
|
35
|
-
check_identity!
|
35
|
+
# check_identity!
|
36
36
|
current_time = Time.now.utc
|
37
37
|
|
38
38
|
anonymous_id = options[:anonymous_id] || uid()
|
39
|
+
user_id = options[:user_id]
|
39
40
|
context[:traits] = (context[:traits] || {}) && {
|
40
41
|
anonymousId: anonymous_id,
|
41
|
-
userId: options[:user_id]
|
42
42
|
}
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
if (user_id)
|
45
|
+
context[:traits] = context[:traits].merge({userId: user_id})
|
46
|
+
end
|
47
|
+
|
48
|
+
payload = {
|
46
49
|
anonymousId: anonymous_id,
|
47
50
|
context: context,
|
48
|
-
integrations: options[:integrations] || {All: true},
|
51
|
+
integrations: options[:integrations] || { All: true },
|
49
52
|
timestamp: maybe_datetime_in_iso8601(options[:timestamp] || Time.now.utc),
|
50
53
|
sentAt: maybe_datetime_in_iso8601(current_time),
|
51
54
|
messageId: uid(),
|
52
55
|
properties: options[:properties] || {}
|
53
56
|
}
|
54
|
-
end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
if (user_id)
|
59
|
+
payload = payload.merge({userId: user_id})
|
60
|
+
end
|
61
|
+
payload
|
59
62
|
end
|
63
|
+
|
64
|
+
# def check_identity!
|
65
|
+
# raise ArgumentError, 'user_id or anonymous_id must be present' \
|
66
|
+
# unless options[:user_id] || options[:anonymous_id]
|
67
|
+
# end
|
60
68
|
end
|
61
69
|
end
|
62
70
|
end
|
@@ -8,11 +8,12 @@ module RudderAnalyticsSync
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def build_payload
|
11
|
-
properties = options[:properties] && isoify_dates!(options[:properties])
|
11
|
+
properties = (options[:properties] && isoify_dates!(options[:properties])) || {}
|
12
12
|
|
13
13
|
base_payload.merge(
|
14
14
|
name: options[:name],
|
15
|
-
|
15
|
+
event: options[:name],
|
16
|
+
properties: properties.merge({ name: options[:name] })
|
16
17
|
)
|
17
18
|
end
|
18
19
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RudderAnalyticsSync
|
4
|
+
module Operations
|
5
|
+
class Screen < Operation
|
6
|
+
def call
|
7
|
+
request.post('/v1/screen', build_payload)
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_payload
|
11
|
+
properties = (options[:properties] && isoify_dates!(options[:properties])) || {}
|
12
|
+
|
13
|
+
base_payload.merge(
|
14
|
+
name: options[:name],
|
15
|
+
event: options[:name],
|
16
|
+
properties: properties.merge({name: options[:name]})
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rudder_analytics_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RudderStack
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/rudder_analytics_sync/operations/identify.rb
|
143
143
|
- lib/rudder_analytics_sync/operations/operation.rb
|
144
144
|
- lib/rudder_analytics_sync/operations/page.rb
|
145
|
+
- lib/rudder_analytics_sync/operations/screen.rb
|
145
146
|
- lib/rudder_analytics_sync/operations/track.rb
|
146
147
|
- lib/rudder_analytics_sync/request.rb
|
147
148
|
- lib/rudder_analytics_sync/utils.rb
|