rudder_analytics_sync 1.0.2 → 1.0.7
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 +5 -5
- data/.gitignore +1 -3
- data/README.md +11 -74
- data/example/example.rb +34 -25
- data/lib/rudder_analytics_sync/batch.rb +10 -0
- data/lib/rudder_analytics_sync/operations.rb +1 -0
- data/lib/rudder_analytics_sync/operations/identify.rb +1 -1
- data/lib/rudder_analytics_sync/operations/operation.rb +13 -10
- 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 +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2b0d385201227d9e778888a6874cf6be75a09b0a74c96243d18061af24996084
|
|
4
|
+
data.tar.gz: 56eefbf2bfc77688b912fa4f52795c115645461d2d8c7535f3fca78eb9743984
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d29adcc4026b7178b02229f39a0f5f4df21b540bad1aca6bfad723d8e3899e7ed2e229ac21046200a65098e85a87a074b2329a4b7ef6a461a6931538a79f9ad
|
|
7
|
+
data.tar.gz: 861bd17aae4ca8147a49628bb6586570c832124b5193939c461fc2796f92416dee60122aeb2acb038ebf6dd7a66df47528c1415450c1b65869f08ad842377c7f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
|
@@ -1,38 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# What is RudderStack?
|
|
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
|
-
|
|
7
|
-
RudderAnalyticsSync allows for manual control of when and how the events are sent to Segment. This can be useful if you want to leverage an existing queueing system like Sidekiq or Resque for sending events or need to send events synchronously. If this is not the case you will be better off using the [official segment gem](https://github.com/segmentio/analytics-ruby) that handles queuing for you.
|
|
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.
|
|
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.
|
|
23
8
|
|
|
24
9
|
## Installation
|
|
25
10
|
|
|
26
11
|
Add this line to your application's Gemfile:
|
|
27
12
|
|
|
28
13
|
```ruby
|
|
29
|
-
gem '
|
|
14
|
+
gem 'rudder_analytics_sync'
|
|
30
15
|
```
|
|
31
16
|
|
|
32
17
|
Or install it yourself as:
|
|
33
18
|
|
|
34
19
|
```sh
|
|
35
|
-
$ gem install
|
|
20
|
+
$ gem install rudder_analytics_sync
|
|
36
21
|
```
|
|
37
22
|
|
|
38
23
|
## Usage
|
|
@@ -41,7 +26,8 @@ Create a client instance:
|
|
|
41
26
|
|
|
42
27
|
```ruby
|
|
43
28
|
analytics = RudderAnalyticsSync::Client.new(
|
|
44
|
-
write_key:
|
|
29
|
+
write_key: <YOUR_WRITE_KEY>, # required
|
|
30
|
+
data_plane_url: <DATA_PLANE_URL>
|
|
45
31
|
on_error: proc { |error_code, error_body, exception, response|
|
|
46
32
|
# defaults to an empty proc
|
|
47
33
|
}
|
|
@@ -72,54 +58,5 @@ analytics.batch do |batch|
|
|
|
72
58
|
end
|
|
73
59
|
```
|
|
74
60
|
|
|
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).
|
|
61
|
+
## Contact Us
|
|
62
|
+
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
|
|
@@ -5,6 +5,7 @@ require 'rudder_analytics_sync/operations/operation'
|
|
|
5
5
|
require 'rudder_analytics_sync/operations/identify'
|
|
6
6
|
require 'rudder_analytics_sync/operations/track'
|
|
7
7
|
require 'rudder_analytics_sync/operations/page'
|
|
8
|
+
require 'rudder_analytics_sync/operations/screen'
|
|
8
9
|
require 'rudder_analytics_sync/operations/group'
|
|
9
10
|
require 'rudder_analytics_sync/operations/alias'
|
|
10
11
|
|
|
@@ -11,7 +11,7 @@ module RudderAnalyticsSync
|
|
|
11
11
|
merged_payload = base_payload.merge(
|
|
12
12
|
traits: options[:traits] && isoify_dates!(options[:traits])
|
|
13
13
|
)
|
|
14
|
-
merged_payload[:context][:traits] = merged_payload[:context][:traits].merge(options[:traits])
|
|
14
|
+
merged_payload[:context][:traits] = merged_payload[:context][:traits].merge(options[:traits] || {})
|
|
15
15
|
merged_payload
|
|
16
16
|
end
|
|
17
17
|
end
|
|
@@ -35,22 +35,25 @@ module RudderAnalyticsSync
|
|
|
35
35
|
check_identity!
|
|
36
36
|
current_time = Time.now.utc
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
context[:traits] = (context[:traits] || {}) && {
|
|
40
|
-
anonymousId: anonymous_id,
|
|
41
|
-
userId: options[:user_id]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
userId: options[:user_id],
|
|
46
|
-
anonymousId: anonymous_id,
|
|
38
|
+
payload = {
|
|
47
39
|
context: context,
|
|
48
|
-
integrations: options[:integrations] || {All: true},
|
|
40
|
+
integrations: options[:integrations] || { All: true },
|
|
49
41
|
timestamp: maybe_datetime_in_iso8601(options[:timestamp] || Time.now.utc),
|
|
50
42
|
sentAt: maybe_datetime_in_iso8601(current_time),
|
|
51
43
|
messageId: uid(),
|
|
52
44
|
properties: options[:properties] || {}
|
|
53
45
|
}
|
|
46
|
+
|
|
47
|
+
# add the userId if present
|
|
48
|
+
if (options[:user_id])
|
|
49
|
+
payload = payload.merge({userId: options[:user_id]})
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# add the anonymousId if present
|
|
53
|
+
if (options[:anonymous_id])
|
|
54
|
+
payload = payload.merge({anonymousId: options[:anonymous_id]})
|
|
55
|
+
end
|
|
56
|
+
payload
|
|
54
57
|
end
|
|
55
58
|
|
|
56
59
|
def check_identity!
|
|
@@ -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,14 +1,14 @@
|
|
|
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.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- RudderStack
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-10-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -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
|
|
@@ -166,8 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
166
167
|
- !ruby/object:Gem::Version
|
|
167
168
|
version: '0'
|
|
168
169
|
requirements: []
|
|
169
|
-
|
|
170
|
-
rubygems_version: 2.5.2.3
|
|
170
|
+
rubygems_version: 3.0.3
|
|
171
171
|
signing_key:
|
|
172
172
|
specification_version: 4
|
|
173
173
|
summary: Privacy and Security focused Segment-alternative. Ruby SDK (sync)
|