altertable 1.3.0 → 1.4.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/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +24 -0
- data/Gemfile.lock +1 -1
- data/README.md +18 -4
- data/lib/altertable/adapters.rb +1 -1
- data/lib/altertable/client.rb +24 -5
- data/lib/altertable/version.rb +1 -1
- data/rbi/altertable.rbi +7 -0
- data/sig/altertable/client.rbs +6 -2
- data/sig/altertable.rbs +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f0c02045e8016662d903687752f44da29671aca4d2d0eddaef0760d01592a680
|
|
4
|
+
data.tar.gz: 7c773edb0b142b0cfffdef1559c15da1984447f787c8dddec75eabf5499dae5c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eca34e9a16479ec5775c9fb3ff63cc53d351143661a078350248cb00a226817572983d35f5acc8f896f2591d2215cabae5870a77b0250363c21abcb0ba52a383
|
|
7
|
+
data.tar.gz: abc75821bf9ed8cdca3b813b46c4791318f4122bd85b572151984b8a98d26abb3e9c04a75b2c092063169872abb606f63e30d30c3f12e6a2f2c9eb1baf29f10e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.4.0](https://github.com/altertable-ai/altertable-ruby/compare/altertable/v1.3.0...altertable/v1.4.0) (2026-11-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add audience collection mode ([#55](https://github.com/altertable-ai/altertable-ruby/issues/55)) ([7ecb88c](https://github.com/altertable-ai/altertable-ruby/commit/7ecb88cd5d8951c35b811dcde3577d7233112856))
|
|
9
|
+
* deprecate analytics environment routing ([#56](https://github.com/altertable-ai/altertable-ruby/issues/56)) ([020e3bf](https://github.com/altertable-ai/altertable-ruby/commit/020e3bf406bdacd805dd33d8b5879f34120f6f5d))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* **httpx:** resolve request paths against the base URL ([#57](https://github.com/altertable-ai/altertable-ruby/issues/57)) ([f3473fb](https://github.com/altertable-ai/altertable-ruby/commit/f3473fbd4710ce79eb0092bfefbd2f48da488014))
|
|
15
|
+
|
|
16
|
+
## [Unreleased]
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* Add `mode: :audience` to collect events without identity fields. Product mode remains the default.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
* Deprecate the `environment` option: it is ignored and no longer sent. Use an environment-bound Product Analytics API key.
|
|
25
|
+
|
|
26
|
+
|
|
3
27
|
## [1.3.0](https://github.com/altertable-ai/altertable-ruby/compare/altertable/v1.2.0...altertable/v1.3.0) (2026-09-04)
|
|
4
28
|
|
|
5
29
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Initialize the client and track your first event. Call `track()` to record an ac
|
|
|
22
22
|
require 'altertable'
|
|
23
23
|
|
|
24
24
|
# Initialize the Altertable client
|
|
25
|
-
Altertable.init('pk_live_abc123'
|
|
25
|
+
Altertable.init('pk_live_abc123')
|
|
26
26
|
|
|
27
27
|
# Track an event
|
|
28
28
|
Altertable.track('button_clicked', 'user_123', properties: {
|
|
@@ -40,14 +40,14 @@ Initialize the global Altertable client instance.
|
|
|
40
40
|
`Altertable.init(api_key, options = {})`
|
|
41
41
|
|
|
42
42
|
```ruby
|
|
43
|
-
Altertable.init('pk_live_abc123',
|
|
43
|
+
Altertable.init('pk_live_abc123', debug: true)
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
### Tracking Events
|
|
47
47
|
|
|
48
48
|
Record an action performed by a user.
|
|
49
49
|
|
|
50
|
-
`Altertable.track(event, distinct_id, **options)`
|
|
50
|
+
`Altertable.track(event, distinct_id = nil, **options)`
|
|
51
51
|
`Altertable.track(event_payload, **options)`
|
|
52
52
|
`Altertable.track(event_payloads, **options)`
|
|
53
53
|
|
|
@@ -69,6 +69,19 @@ Altertable.track([
|
|
|
69
69
|
])
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
### Audience Measurement
|
|
73
|
+
|
|
74
|
+
Initialize with `mode: :audience` to collect events without identity fields:
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
Altertable.init('pk_live_abc123', mode: :audience)
|
|
78
|
+
Altertable.track('Docs Opened', properties: { section: 'installation' })
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Audience events send only `event`, `timestamp`, and `properties`; distinct, anonymous,
|
|
82
|
+
device, and session fields are dropped. `identify` and `alias` are ignored.
|
|
83
|
+
Requests come from your server, so they cannot distinguish browser visitors.
|
|
84
|
+
|
|
72
85
|
### Identifying Users
|
|
73
86
|
|
|
74
87
|
Link a user ID to their traits (like email or name).
|
|
@@ -114,7 +127,8 @@ You can configure the client by passing options during initialization.
|
|
|
114
127
|
|
|
115
128
|
| Option | Type | Default | Description |
|
|
116
129
|
|---|---|---|---|
|
|
117
|
-
| `
|
|
130
|
+
| `mode` | Symbol, String | `:product` | Collection mode: `:product` or `:audience`. Fixed for the client lifetime. |
|
|
131
|
+
| `environment` | String | — | Deprecated and ignored. It is accepted for compatibility but never sent; use an environment-bound Product Analytics API key. |
|
|
118
132
|
| `base_url` | String | `"https://api.altertable.ai"` | Base URL for API requests. |
|
|
119
133
|
| `request_timeout` | Integer | `5` | Request timeout in seconds. |
|
|
120
134
|
| `release` | String | `nil` | Application release version (e.g., commit hash). |
|
data/lib/altertable/adapters.rb
CHANGED
data/lib/altertable/client.rb
CHANGED
|
@@ -9,14 +9,21 @@ module Altertable
|
|
|
9
9
|
class Client
|
|
10
10
|
DEFAULT_BASE_URL = "https://api.altertable.ai"
|
|
11
11
|
DEFAULT_TIMEOUT = 5
|
|
12
|
+
# @deprecated Environments are selected by the Product Analytics API key.
|
|
13
|
+
# Retained so applications that reference the public constant continue to load.
|
|
12
14
|
DEFAULT_ENVIRONMENT = "production"
|
|
13
15
|
|
|
14
16
|
def initialize(api_key, options = {})
|
|
15
17
|
raise ConfigurationError, "API Key is required" if api_key.nil? || api_key.empty?
|
|
16
18
|
|
|
19
|
+
@mode = case options.fetch(:mode, :product)
|
|
20
|
+
when :product, "product" then :product
|
|
21
|
+
when :audience, "audience" then :audience
|
|
22
|
+
else
|
|
23
|
+
raise ConfigurationError, 'Invalid tracking mode. Use "product" or "audience".'
|
|
24
|
+
end
|
|
17
25
|
@api_key = api_key
|
|
18
26
|
@base_url = options[:base_url] || DEFAULT_BASE_URL
|
|
19
|
-
@environment = options[:environment] || DEFAULT_ENVIRONMENT
|
|
20
27
|
@timeout = options[:request_timeout] || DEFAULT_TIMEOUT
|
|
21
28
|
@release = options[:release]
|
|
22
29
|
@debug = options[:debug] || false
|
|
@@ -44,6 +51,8 @@ module Altertable
|
|
|
44
51
|
end
|
|
45
52
|
|
|
46
53
|
def identify(user_id, **options)
|
|
54
|
+
return if reject_identity_call?
|
|
55
|
+
|
|
47
56
|
case user_id
|
|
48
57
|
when Array
|
|
49
58
|
payloads = map_batch(user_id, "identifies") { |item| identify_payload_from_item(merge_payload(item, options)) }
|
|
@@ -56,6 +65,8 @@ module Altertable
|
|
|
56
65
|
end
|
|
57
66
|
|
|
58
67
|
def alias(distinct_id, new_user_id = nil, **options)
|
|
68
|
+
return if reject_identity_call?
|
|
69
|
+
|
|
59
70
|
case distinct_id
|
|
60
71
|
when Array
|
|
61
72
|
payloads = map_batch(distinct_id, "aliases") { |item| alias_payload_from_item(merge_payload(item, options)) }
|
|
@@ -69,6 +80,10 @@ module Altertable
|
|
|
69
80
|
|
|
70
81
|
private
|
|
71
82
|
|
|
83
|
+
def reject_identity_call?
|
|
84
|
+
@mode == :audience
|
|
85
|
+
end
|
|
86
|
+
|
|
72
87
|
def select_adapter(name, options)
|
|
73
88
|
case name
|
|
74
89
|
when :faraday
|
|
@@ -138,7 +153,7 @@ module Altertable
|
|
|
138
153
|
event = item_value(item, :event)
|
|
139
154
|
distinct_id = item_value(item, :distinct_id)
|
|
140
155
|
raise ArgumentError, "event is required" if blank?(event)
|
|
141
|
-
raise ArgumentError, "distinct_id is required" if blank?(distinct_id)
|
|
156
|
+
raise ArgumentError, "distinct_id is required" if @mode == :product && blank?(distinct_id)
|
|
142
157
|
|
|
143
158
|
track_payload(event, distinct_id, item_options(item, :properties, :anonymous_id, :device_id, :timestamp))
|
|
144
159
|
end
|
|
@@ -164,7 +179,6 @@ module Altertable
|
|
|
164
179
|
payload = {
|
|
165
180
|
timestamp: options[:timestamp] || default_timestamp,
|
|
166
181
|
event: event,
|
|
167
|
-
environment: @environment,
|
|
168
182
|
distinct_id: distinct_id,
|
|
169
183
|
properties: {
|
|
170
184
|
'$lib': "altertable-ruby",
|
|
@@ -172,15 +186,21 @@ module Altertable
|
|
|
172
186
|
}.merge(properties)
|
|
173
187
|
}
|
|
174
188
|
payload[:properties]["$release"] = @release if @release
|
|
189
|
+
return audience_payload(payload) if @mode == :audience
|
|
190
|
+
|
|
175
191
|
payload[:anonymous_id] = options[:anonymous_id] if options.key?(:anonymous_id)
|
|
176
192
|
payload[:device_id] = options[:device_id] if options.key?(:device_id)
|
|
177
193
|
payload
|
|
178
194
|
end
|
|
179
195
|
|
|
196
|
+
# Select wire fields explicitly so per-event options cannot override client policy.
|
|
197
|
+
def audience_payload(payload)
|
|
198
|
+
{ mode: "audience", event: payload[:event], timestamp: payload[:timestamp], properties: payload[:properties] }
|
|
199
|
+
end
|
|
200
|
+
|
|
180
201
|
def identify_payload(user_id, options)
|
|
181
202
|
payload = {
|
|
182
203
|
timestamp: options[:timestamp] || default_timestamp,
|
|
183
|
-
environment: @environment,
|
|
184
204
|
distinct_id: user_id,
|
|
185
205
|
traits: options[:traits] || {}
|
|
186
206
|
}
|
|
@@ -192,7 +212,6 @@ module Altertable
|
|
|
192
212
|
def alias_payload(distinct_id, new_user_id, options)
|
|
193
213
|
{
|
|
194
214
|
timestamp: options[:timestamp] || default_timestamp,
|
|
195
|
-
environment: @environment,
|
|
196
215
|
distinct_id: distinct_id,
|
|
197
216
|
new_user_id: new_user_id
|
|
198
217
|
}
|
data/lib/altertable/version.rb
CHANGED
data/rbi/altertable.rbi
CHANGED
|
@@ -29,6 +29,7 @@ module Altertable
|
|
|
29
29
|
class Client
|
|
30
30
|
DEFAULT_BASE_URL = T.let(T.unsafe(nil), String)
|
|
31
31
|
DEFAULT_TIMEOUT = T.let(T.unsafe(nil), Integer)
|
|
32
|
+
# @deprecated Environments are selected by the Product Analytics API key.
|
|
32
33
|
DEFAULT_ENVIRONMENT = T.let(T.unsafe(nil), String)
|
|
33
34
|
|
|
34
35
|
sig { params(api_key: String, options: T::Hash[Symbol, T.untyped]).void }
|
|
@@ -48,6 +49,12 @@ module Altertable
|
|
|
48
49
|
sig { params(name: T.nilable(Symbol), options: T::Hash[Symbol, T.untyped]).returns(T.untyped) }
|
|
49
50
|
def select_adapter(name, options); end
|
|
50
51
|
|
|
52
|
+
sig { returns(T::Boolean) }
|
|
53
|
+
def reject_identity_call?; end
|
|
54
|
+
|
|
55
|
+
sig { params(payload: T::Hash[Symbol, T.untyped]).returns(T::Hash[Symbol, T.untyped]) }
|
|
56
|
+
def audience_payload(payload); end
|
|
57
|
+
|
|
51
58
|
sig { params(gem_name: String).returns(T::Boolean) }
|
|
52
59
|
def try_require(gem_name); end
|
|
53
60
|
|
data/sig/altertable/client.rbs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module Altertable
|
|
2
2
|
class Client
|
|
3
|
+
@mode: :product | :audience
|
|
3
4
|
@api_key: String
|
|
4
5
|
@base_url: String
|
|
5
|
-
@environment: String
|
|
6
6
|
@timeout: Integer | Float
|
|
7
7
|
@release: String?
|
|
8
8
|
@debug: bool
|
|
@@ -11,11 +11,12 @@ module Altertable
|
|
|
11
11
|
|
|
12
12
|
DEFAULT_BASE_URL: String
|
|
13
13
|
DEFAULT_TIMEOUT: Integer
|
|
14
|
+
# @deprecated Environments are selected by the Product Analytics API key.
|
|
14
15
|
DEFAULT_ENVIRONMENT: String
|
|
15
16
|
|
|
16
17
|
def initialize: (String api_key, ?::Hash[Symbol, untyped] options) -> void
|
|
17
18
|
|
|
18
|
-
def track: (String event, String distinct_id, **untyped options) -> untyped
|
|
19
|
+
def track: (String event, ?String? distinct_id, **untyped options) -> untyped
|
|
19
20
|
| (::Hash[Symbol | String, untyped] event_payload, **untyped options) -> untyped
|
|
20
21
|
| (::Array[::Hash[Symbol | String, untyped]] event_payloads, **untyped options) -> untyped
|
|
21
22
|
|
|
@@ -29,6 +30,9 @@ module Altertable
|
|
|
29
30
|
|
|
30
31
|
private
|
|
31
32
|
|
|
33
|
+
def reject_identity_call?: () -> bool
|
|
34
|
+
def audience_payload: (::Hash[Symbol, untyped] payload) -> ::Hash[Symbol, untyped]
|
|
35
|
+
|
|
32
36
|
def select_adapter: (Symbol? name, ::Hash[Symbol, untyped] options) -> untyped
|
|
33
37
|
def try_require: (String gem_name) -> bool
|
|
34
38
|
def post: (String path, ::Hash[Symbol | String, untyped] | ::Array[::Hash[Symbol | String, untyped]] payload) -> untyped
|
data/sig/altertable.rbs
CHANGED
|
@@ -3,7 +3,7 @@ module Altertable
|
|
|
3
3
|
|
|
4
4
|
def self.init: (String api_key, ?::Hash[Symbol, untyped] options) -> Client
|
|
5
5
|
|
|
6
|
-
def self.track: (String event, String distinct_id, **untyped options) -> untyped
|
|
6
|
+
def self.track: (String event, ?String? distinct_id, **untyped options) -> untyped
|
|
7
7
|
| (::Hash[Symbol | String, untyped] event_payload, **untyped options) -> untyped
|
|
8
8
|
| (::Array[::Hash[Symbol | String, untyped]] event_payloads, **untyped options) -> untyped
|
|
9
9
|
|