RelationKit supports sending custom events via our backend REST API. This is often the next step folks take after integrating with our JavaScript drop-in, but not required to use RelationKit.
For more information on our JavaScript integration view
To implement events in Ruby, you'll need to create an API key (we recommend one for your front-end integration and a separate one for your REST API integration), and then make two requests.
Make a request to ping RelationKit and ensure we know about your customer.
require "uri"
require "json"
require "net/http"
url = URI("https://api.relationkit.io/api/v1/ping")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer YOUR-TOKEN-HERE"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"customer": {
"user_id": "your-app-unique-user-id-here",
"name": "USER NAME",
"email": "email@example.com",
"custom_attributes": {}
}
})
response = https.request(request)
puts response.read_body
Once you're sure the user exists, you can make a request to the Events Create endpoint
require "uri"
require "json"
require "net/http"
url = URI("https://api.relationkit.io/api/v1/events")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer TOKEN-HERE"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"event": {
"user_id": "your-unique-user-id-here",
"name": "visted-endpoint",
"metadata": {}
}
})
response = https.request(request)
puts response.read_body
For the event name: we recommend naming it with dashes in between and using human readable sentences. We'll automatically add a few events like "subscribed-to-email-list" and "unsubscribed-from-email-list" for events we manage for you.
Both the metadata and custom_attributes follows the same principles for attributes you send over. The below information will also work for the metadata object.
If you pass us a custom attribute ending in _url we'll automatically try and link that passed value in a button on the Customer profile. If you wish to customize the way a link is displayed, you can pass an Object (or Hash) with two keys, one of "title" with the title you want to be displayed on the button, and one of "url" which is the URL you'd like to link out to.
If you pass us a custom attribute ending in _at as a UNIX timestamp we'll automatically read it as a date time.
If you pass us a custom attribute ending in _list as an Array we'll automatically read it as such and display badges for each item in the list on the customer profile.
Once you're satisfied and send your first event you'll see it on the Events page. Happy event sending!
If you need help, don't hesitate to reach out, we'll be happy to help.