Skip to content

Instantly share code, notes, and snippets.

@joshed-io
Created January 22, 2013 23:01
Show Gist options
  • Select an option

  • Save joshed-io/4599555 to your computer and use it in GitHub Desktop.

Select an option

Save joshed-io/4599555 to your computer and use it in GitHub Desktop.
Send an event to keen.io via a GET request, useful for placing image beacons.
# Send an event to keen.io via a GET request
# Useful for placing image beacons in email
# (Traditional POST approach is still recommended where possible)
require 'json'
require 'base64'
# Get a project ID and API Key from keen.io
project_id = "your-project-id"
api_key = "your-api-key"
event_collection = "email_opens"
data = {
:recipient => "art@vandelay.com",
:ab_test_choice => "A"
}
encoded_data = Base64.urlsafe_encode64(JSON.dump(data))
url = "https://api.keen.io/3.0/projects/#{project_id}/events/#{event_collection}?api_key=#{api_key}&data=#{encoded_data}"
puts "Here's the URL:\n\n"
puts url
@joshed-io
Copy link
Copy Markdown
Author

To log an event when a user opens an email, place an image tag in the email with the 'src' attribute pointing to the URL like the one we just created.

<img src="<%= url %>">

When the user opens the email (and chooses to view images), the event will be published to Keen IO.

The call returns a 1x1 transparent GIF, so the presentation of your email will not be altered, nor should you see any warnings when debugging in a console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment