diff --git a/CHANGELOG.md b/CHANGELOG.md index 20c5aee..d2f68a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ * Add `mode: :audience` to collect events without identity fields. Product mode remains the default. +### Changed + +* Deprecate the `environment` option: it is ignored and no longer sent. Use an environment-bound Product Analytics API key. + ## [1.3.0](https://github.com/altertable-ai/altertable-ruby/compare/altertable/v1.2.0...altertable/v1.3.0) (2026-09-04) diff --git a/README.md b/README.md index 1505793..c647d1b 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Initialize the client and track your first event. Call `track()` to record an ac require 'altertable' # Initialize the Altertable client -Altertable.init('pk_live_abc123', environment: 'production') +Altertable.init('pk_live_abc123') # Track an event Altertable.track('button_clicked', 'user_123', properties: { @@ -40,7 +40,7 @@ Initialize the global Altertable client instance. `Altertable.init(api_key, options = {})` ```ruby -Altertable.init('pk_live_abc123', environment: 'production', debug: true) +Altertable.init('pk_live_abc123', debug: true) ``` ### Tracking Events @@ -79,7 +79,7 @@ Altertable.track('Docs Opened', properties: { section: 'installation' }) ``` Audience events send only `event`, `timestamp`, and `properties`; distinct, anonymous, -device, session, and environment fields are dropped. `identify` and `alias` are ignored. +device, and session fields are dropped. `identify` and `alias` are ignored. Requests come from your server, so they cannot distinguish browser visitors. ### Identifying Users @@ -128,7 +128,7 @@ You can configure the client by passing options during initialization. | Option | Type | Default | Description | |---|---|---|---| | `mode` | Symbol, String | `:product` | Collection mode: `:product` or `:audience`. Fixed for the client lifetime. | -| `environment` | String | `"production"` | Product environment name (e.g., `production`, `development`). Omitted in audience mode; the API key selects its environment. | +| `environment` | String | — | Deprecated and ignored. It is accepted for compatibility but never sent; use an environment-bound Product Analytics API key. | | `base_url` | String | `"https://api.altertable.ai"` | Base URL for API requests. | | `request_timeout` | Integer | `5` | Request timeout in seconds. | | `release` | String | `nil` | Application release version (e.g., commit hash). | diff --git a/lib/altertable/client.rb b/lib/altertable/client.rb index 8e822e7..bbda2d1 100644 --- a/lib/altertable/client.rb +++ b/lib/altertable/client.rb @@ -9,6 +9,8 @@ module Altertable class Client DEFAULT_BASE_URL = "https://api.altertable.ai" DEFAULT_TIMEOUT = 5 + # @deprecated Environments are selected by the Product Analytics API key. + # Retained so applications that reference the public constant continue to load. DEFAULT_ENVIRONMENT = "production" def initialize(api_key, options = {}) @@ -22,7 +24,6 @@ def initialize(api_key, options = {}) end @api_key = api_key @base_url = options[:base_url] || DEFAULT_BASE_URL - @environment = options[:environment] || DEFAULT_ENVIRONMENT @timeout = options[:request_timeout] || DEFAULT_TIMEOUT @release = options[:release] @debug = options[:debug] || false @@ -178,7 +179,6 @@ def track_payload(event, distinct_id, options) payload = { timestamp: options[:timestamp] || default_timestamp, event: event, - environment: @environment, distinct_id: distinct_id, properties: { '$lib': "altertable-ruby", @@ -201,7 +201,6 @@ def audience_payload(payload) def identify_payload(user_id, options) payload = { timestamp: options[:timestamp] || default_timestamp, - environment: @environment, distinct_id: user_id, traits: options[:traits] || {} } @@ -213,7 +212,6 @@ def identify_payload(user_id, options) def alias_payload(distinct_id, new_user_id, options) { timestamp: options[:timestamp] || default_timestamp, - environment: @environment, distinct_id: distinct_id, new_user_id: new_user_id } diff --git a/rbi/altertable.rbi b/rbi/altertable.rbi index c4b2415..0807d17 100644 --- a/rbi/altertable.rbi +++ b/rbi/altertable.rbi @@ -29,6 +29,7 @@ module Altertable class Client DEFAULT_BASE_URL = T.let(T.unsafe(nil), String) DEFAULT_TIMEOUT = T.let(T.unsafe(nil), Integer) + # @deprecated Environments are selected by the Product Analytics API key. DEFAULT_ENVIRONMENT = T.let(T.unsafe(nil), String) sig { params(api_key: String, options: T::Hash[Symbol, T.untyped]).void } diff --git a/sig/altertable/client.rbs b/sig/altertable/client.rbs index 5b96428..72aaa72 100644 --- a/sig/altertable/client.rbs +++ b/sig/altertable/client.rbs @@ -3,7 +3,6 @@ module Altertable @mode: :product | :audience @api_key: String @base_url: String - @environment: String @timeout: Integer | Float @release: String? @debug: bool @@ -12,6 +11,7 @@ module Altertable DEFAULT_BASE_URL: String DEFAULT_TIMEOUT: Integer + # @deprecated Environments are selected by the Product Analytics API key. DEFAULT_ENVIRONMENT: String def initialize: (String api_key, ?::Hash[Symbol, untyped] options) -> void diff --git a/spec/altertable/client_audience_spec.rb b/spec/altertable/client_audience_spec.rb index 8bcd2ad..e337f53 100644 --- a/spec/altertable/client_audience_spec.rb +++ b/spec/altertable/client_audience_spec.rb @@ -88,7 +88,8 @@ def expect_audience(payload) product = build_client(mode: mode, environment: "staging") product.track("Opened", "user", anonymous_id: "anon", device_id: "device", mode: :audience, properties: { "$url" => "https://site.example/?private=yes", "$viewport" => "100x100" }) - expect(calls.last[:body]).to include("distinct_id" => "user", "anonymous_id" => "anon", "device_id" => "device", "environment" => "staging") + expect(calls.last[:body]).to include("distinct_id" => "user", "anonymous_id" => "anon", "device_id" => "device") + expect(calls.last[:body]).not_to have_key("environment") expect(calls.last[:body]).not_to have_key("mode") expect(calls.last[:body]["properties"]).to include("$url" => "https://site.example/?private=yes", "$viewport" => "100x100") expect { product.track({ event: "No ID" }) }.to raise_error(ArgumentError, /distinct_id/) @@ -102,7 +103,8 @@ def expect_audience(payload) it "defaults to product mode" do build_client.track("Opened", "user") - expect(calls.last[:body]).to include("distinct_id" => "user", "environment" => "production") + expect(calls.last[:body]).to include("distinct_id" => "user") + expect(calls.last[:body]).not_to have_key("environment") expect(calls.last[:body]).not_to have_key("mode") end diff --git a/spec/altertable/client_batch_spec.rb b/spec/altertable/client_batch_spec.rb index 44311b8..66c7620 100644 --- a/spec/altertable/client_batch_spec.rb +++ b/spec/altertable/client_batch_spec.rb @@ -41,7 +41,6 @@ def post(path, body: nil, params: {}) expect(payload).to include( "event" => "signup", "distinct_id" => "u1", - "environment" => "production", "timestamp" => "2025-06-15T14:30:00.000Z" ) expect(payload["properties"]).to include("plan" => "pro", "$lib" => "altertable-ruby") @@ -75,7 +74,6 @@ def post(path, body: nil, params: {}) expect(payloads[0]).to include( "event" => "signup", "distinct_id" => "u1", - "environment" => "production", "timestamp" => "2025-06-15T14:30:00.000Z" ) expect(payloads[0]["properties"]).to include("plan" => "pro", "$lib" => "altertable-ruby", "$lib_version" => Altertable::VERSION, "$release" => "1.2.3") @@ -161,7 +159,6 @@ def post(path, body: nil, params: {}) payloads = adapter.calls.first[:body] expect(payloads[0]).to include( "distinct_id" => "u1", - "environment" => "production", "timestamp" => "2025-06-15T14:30:00.000Z" ) expect(payloads[0]["traits"]).to include("email" => "a@example.com") @@ -210,7 +207,6 @@ def post(path, body: nil, params: {}) expect(payloads[0]).to include( "distinct_id" => "anon-1", "new_user_id" => "u1", - "environment" => "production", "timestamp" => "2025-06-15T14:30:00.000Z" ) expect(payloads[1]).to include("distinct_id" => "anon-2", "new_user_id" => "u2") @@ -232,4 +228,22 @@ def post(path, body: nil, params: {}) expect(adapter.calls.first[:body].first).to include("distinct_id" => "anon-1", "new_user_id" => "u1") end end + + it "accepts deprecated environments without sending them for scalar, hash, and batch calls" do + deprecated = nil + expect { deprecated = described_class.new(api_key, environment: "staging", debug: true) }.not_to output.to_stderr + deprecated.instance_variable_set(:@adapter, adapter) + + deprecated.track("Scalar", "u1", environment: "event") + deprecated.track({ event: "Hash", distinct_id: "u2", environment: "hash", properties: { environment: "business" } }) + deprecated.track([{ event: "Batch", distinct_id: "u3", "environment" => "batch" }]) + deprecated.identify([{ user_id: "u1", environment: "identify" }]) + deprecated.alias([{ distinct_id: "old", new_user_id: "new", environment: "alias" }]) + + adapter.calls.each do |call| + payloads = call[:body].is_a?(Array) ? call[:body] : [call[:body]] + payloads.each { |payload| expect(payload).not_to have_key("environment") } + end + expect(adapter.calls[1][:body]["properties"]).to include("environment" => "business") + end end