Skip to content
LogZuno

Ruby event tracking

Send events to LogZuno from Ruby, with code that is tested against the API.

This example sends one event to LogZuno's ingestion API from Ruby. It is the exact file our snippet tests send to the API before the docs are published.

Requirements

Ruby 2.7 or later. Only the standard library (net/http and json).

Send an event

# Ruby, standard library only.
require "json"
require "net/http"

endpoint = ENV.fetch("LOGZUNO_ENDPOINT", "https://api.logzuno.app/v1")
uri = URI("#{endpoint}/log")

request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch('LOGZUNO_API_KEY')}"
request["Content-Type"] = "application/json"
request.body = {
  channel: "signups",
  event: "User signed up",
  user_id: "user-123",
  icon: "🎉",
  notify: true,
  tags: { plan: "growth", source: "website" }
}.to_json

response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
puts "#{response.code} #{response.body}"

Export LOGZUNO_API_KEY and run ruby logzuno.rb. LogZuno answers 202 and the event appears in your project's live feed within seconds. Keep the key in an environment variable or your secrets manager, not in source control.

Notes for Ruby

Rails. Keep the key in your credentials or ENV, and send from an Active Job so a request never waits on analytics.

Responses. Net::HTTP doesn't raise on 4xx: check response.code. 202 means accepted; 422 includes the fields that were wrong; 429 includes Retry-After.

Batches. Post { events: [...] } to /v1/batch to send up to 100 at once.

What the request contains

The body is the same in every language: a channel and an event, and optionally user_id, group_id, description, icon, notify and tags. All fields, limits and response codes are in sending events and the ingestion API reference.