> For the complete documentation index, see [llms.txt](https://evntaly.gitbook.io/evntaly/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://evntaly.gitbook.io/evntaly/sdks/ruby.md).

# Ruby

Ruby SDK

Ruby client for interacting with the Evntaly event tracking platform. provides developers with a straightforward interface to initialize the SDK, track events, identify users, manage tracking states.

{% embed url="<https://github.com/Evntaly/evntaly-ruby>" %}

## Installation

To install the SDK using `bundler`:

```bash
 gem 'evntaly', '~> 1.0'
```

and then run:

```bash
bundle install
```

or install directly using:

```bash
gem install evntaly
```

## Initialization

Initialize the SDK with your developer secret and project token:

```ruby
sdk = Evntaly::SDK.new(
    developer_secret: 'YOUR_DEVELOPER_SECRET',
    project_token: 'YOUR_PROJECT_TOKEN'
)
```

## Tracking Events

To track an event, use the `track` method with an associative array containing the event details.

```ruby
 event = Evntaly::Event.new(
  title: 'User Signed Up',
  description: 'A new user signed up to the platform.',
  message: 'Welcome email sent to the user.',
  data: { plan: 'pro', referrer: 'campaign_xyz' },
  tags: ['signup', 'email', 'marketing'],
  notify: true,
  icon: "💰",
  apply_rule_only: false,
  user: { id: '12345' },
  type: 'user_event',
  session_id: 'session_abc',
  feature: 'onboarding',
  topic: 'user_activity'
)

begin
  sdk.track(event)
rescue => e
  # error handling logic
end
```

## Identifying Users

To identify user details, use the `identifyUser` method. This helps link events to specific users and enriches your analytics.

```ruby
user = Evntaly::User.new(
  id: 'u123',
  email: 'user@example.com',
  full_name: 'John Doe',
  organization: 'Example Org',
  data: { role: 'admin' }
)

begin
  sdk.identify_user(user)
rescue => e
  # error handling logic
end
```

## Enabling and Disabling Tracking <a href="#enabling-and-disabling-tracking" id="enabling-and-disabling-tracking"></a>

You can globally enable or disable event tracking for the current SDK instance. This might be useful for development/testing or respecting user consent.

```ruby
Evntaly::SDK.disable_tracking  # Disables tracking
Evntaly::SDK.enable_tracking   # Enables tracking
```

## Best Practices <a href="#best-practices" id="best-practices"></a>

* **Initialize early:** Always initialize the SDK as early as possible.
* **Avoid sensitive data:** Do not pass sensitive personal data directly to the SDK.
* **Monitor API limits:** Regularly check API limits to avoid missing critical events.

## Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* **Events not appearing:** Check if the SDK is initialized correctly and the API tokens are valid.
* **Network errors:** Ensure your network allows requests to `https://evntaly.com`.

***

## Support <a href="#support" id="support"></a>

For additional help, contact support at **<support@evntaly.com>**.

## ✨ **Open-source community Achievements** <a href="#open-source-community-achievements" id="open-source-community-achievements"></a>

**Huge shout-out and thank you for the legendary**[ **Sayed El-Essawy**](https://www.linkedin.com/in/sayed-alesawy/) **who developed this SDK and it has been added, reviewed and tested by the Evntaly team.**
