Official Ruby SDK for Altertable Product Analytics.
Install the gem with a single command:
gem install altertableInitialize the client and track your first event. Call track() to record an action a user performed.
require 'altertable'
# Initialize the Altertable client
Altertable.init('pk_live_abc123', environment: 'production')
# Track an event
Altertable.track('button_clicked', 'user_123', properties: {
button_id: 'signup_btn',
page: 'home'
})Initialize the global Altertable client instance.
Altertable.init(api_key, options = {})
Altertable.init('pk_live_abc123', environment: 'production', debug: true)Record an action performed by a user.
Altertable.track(event, distinct_id, **options)
Altertable.track('item_purchased', 'user_123', properties: {
item_id: 'item_999',
price: 19.99
})Link a user ID to their traits (like email or name).
Altertable.identify(user_id, **options)
Altertable.identify('user_123', traits: {
email: 'user@example.com',
name: 'John Doe'
})Merge a previous anonymous ID with a newly identified user ID.
Altertable.alias(distinct_id, new_user_id, **options)
Altertable.alias('anon_session_456', 'user_123')You can configure the client by passing options during initialization.
| Option | Type | Default | Description |
|---|---|---|---|
environment |
String | "production" |
Environment name (e.g., production, development). |
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). |
debug |
Boolean | false |
Enable debug logging. |
on_error |
Proc | nil |
Callback for handling errors. |
adapter |
Symbol | auto-detect | HTTP adapter to use (:faraday, :httpx, :net_http). |
The gem is available as open source under the terms of the MIT License.