rudder_analytics_sync 1.0.1 → 1.0.6

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
  SHA1:
3
- metadata.gz: e0cedeea6bd334e5d9740396e2076f2d7562acd7
4
- data.tar.gz: d4d84573ed8d38feb37addf83f2d1f63d063a9b2
3
+ metadata.gz: 157030c6f0cb2352bf8efda032c35fd760fdbf6f
4
+ data.tar.gz: 59af93b4a244d8836f766995901e16cba9a24489
5
5
  SHA512:
6
- metadata.gz: dc32266bd0dcef218ccc61d3ebb443da965c4d14e74b877aeb1e4b3a733c63c0f204968ce730138a32ffa758834081ac1aa14192d26ab3eb9960ee5328e6457d
7
- data.tar.gz: 5c1e78aa055457d7611ceecc1d59d051abe46227ae9998981084f7f429cbef8c3d04dab3a8c7e31760efdeaf8ec6f858fde5b666bfe7bf601bcf070b7924d7fa
6
+ metadata.gz: 4f66625ad1e88c3bb0c36790e606b86c207914cd35e6a6641883ddd33ab39c3bb176c81b9cd33325ac68c558f0260da42f40d0b019316d1b420eca1eb2f6afc3
7
+ data.tar.gz: 2b5ff7739615de79136ac718a89f975ffde9a7972c8aa6e48baf1034cd1aa72377c8e232fefe6c7d5271f6da108f6b557e52f0a22d68bdadbc33b58c87460d35
data/.gitignore CHANGED
@@ -1,11 +1,9 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
10
- *.gem
11
- .rbenv-gemsets
9
+ Gemfile.lock
data/README.md CHANGED
@@ -1,38 +1,25 @@
1
- # RudderAnalyticsSync
1
+ # What is Rudder?
2
2
 
3
- [![Build Status](https://travis-ci.org/whatthewhat/simple_segment.svg?branch=master)](https://travis-ci.org/whatthewhat/simple_segment)
3
+ **Short answer:**
4
+ Rudder is an open-source Segment alternative written in Go, built for the enterprise. .
4
5
 
5
- A simple synchronous Ruby API client for [segment.io](segment.io).
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
- 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.
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 'simple_segment'
16
+ gem 'rudder_analytics_sync'
30
17
  ```
31
18
 
32
19
  Or install it yourself as:
33
20
 
34
21
  ```sh
35
- $ gem install simple_segment
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: 'YOUR_WRITE_KEY', # required
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
- ### Stub API calls
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.
@@ -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.track(
20
- user_id: 'test_user_id',
21
- event: 'Created Account'
22
- )
23
- batch.page(
24
- user_id: 'test_user_id',
25
- name: 'Created Account',
26
- properties: {
27
- k1: 'v1'
28
- }
29
- )
30
- batch.track(
31
- user_id: 'test_user_id',
32
- event: 'Closed Account'
33
- )
34
- batch.identify(
35
- user_id: 'test_user_id_1',
36
- traits: {
37
- name: 'test'
38
- }
39
- )
40
- batch.group(
41
- user_id: 'test_user_id',
42
- group_id: 'group_id'
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rudder_analytics_sync./utils'
3
+ require 'rudder_analytics_sync/utils'
4
4
 
5
5
  module RudderAnalyticsSync
6
6
  module Operations
@@ -32,31 +32,41 @@ 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
- context[:traits] = (context[:traits] || {}) && {
40
- anonymousId: anonymous_id,
41
- userId: options[:user_id]
42
- }
39
+ user_id = options[:user_id]
40
+ context[:traits] = (context[:traits] || {}).merge(
41
+ {
42
+ anonymousId: anonymous_id
43
+ }
44
+ )
45
+
46
+ if (user_id)
47
+ context[:traits] = context[:traits].merge({userId: user_id})
48
+ end
43
49
 
44
- {
45
- userId: options[:user_id],
50
+ payload = {
46
51
  anonymousId: anonymous_id,
47
52
  context: context,
48
- integrations: options[:integrations] || {All: true},
53
+ integrations: options[:integrations] || { All: true },
49
54
  timestamp: maybe_datetime_in_iso8601(options[:timestamp] || Time.now.utc),
50
55
  sentAt: maybe_datetime_in_iso8601(current_time),
51
56
  messageId: uid(),
52
57
  properties: options[:properties] || {}
53
58
  }
54
- end
55
59
 
56
- def check_identity!
57
- raise ArgumentError, 'user_id or anonymous_id must be present' \
58
- unless options[:user_id] || options[:anonymous_id]
60
+ if (user_id)
61
+ payload = payload.merge({userId: user_id})
62
+ end
63
+ payload
59
64
  end
65
+
66
+ # def check_identity!
67
+ # raise ArgumentError, 'user_id or anonymous_id must be present' \
68
+ # unless options[:user_id] || options[:anonymous_id]
69
+ # end
60
70
  end
61
71
  end
62
72
  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
- properties: properties || {}
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RudderAnalyticsSync
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.6'
5
5
  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.1
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - RudderStack
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-23 00:00:00.000000000 Z
11
+ date: 2020-08-05 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