bwsewell / trak-ruby

Ruby bindings for the trak.io API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

trak.io Ruby API Wrapper

Gem Version

This is the gem that allows Ruby bindings for the trak.io V1 API.

Rails Installation

Add this line to your application's Gemfile:

gem 'trak-ruby'

Create an initilizer config/initializers/trak.rb with the following code:

Trak::API_KEY = "YOUR API KEY HERE"

And then execute:

$ bundle install

Or install it yourself as:

$ gem install 'trak-ruby'

===

API Methods

Identify

Trak.identify(distinct_id, properties)

Identify is how you send trak.io properties about a person like Email, Name, Account Type, Age, etc.

Learn more about implementation of identify on trak.io's API documentation

# Initilaize Trak object
t = Trak.new

t.identify(1, {:name => 'John Smith', :email => 'john@test.com'})

The identify method will set the class variable @distinct_id to whatever you pass as your first parameter.

Alias

Trak.alias(distinct_id, aliases)

Alias is how you set additional distinct ids for a person. This is useful if you initially use trak.io's automatically generated distinct id to identify or track a person but then they login or register and you want to identify them by their email address or your application's id for them. Doing this will allow you to identify users across sessions and devices. But of course you want to tie their activity before and after they logged in together, Trak.alias() will do this for you.

Learn more about implementation of alias on trak.io's API documentation

# Initilaize Trak object
t = Trak.new

# Pass a string to add a new alias for a person with distinct_id = 1
t.alias(1, 'Johnny')

# Pass an array of aliases for a person with distinct_id = 1
t.alias(1, ['Johnny', 'john'])

The alias method will set the class variable @distinct_id to whatever you pass as your first parameter.

Track

Trak.track(event, opts = {})

Track is how you record the actions people perform. You can also record properties specific to those actions. For a "Purchased shirt" event, you might record properties like revenue, size, etc.

Learn more about implementation of track on trak.io's API documentation

# Initilaize Trak object
t = Trak.new

# Log the event 'played video'
t.track('played video')

# Log the event 'played video' for a person with distinct_id = 1
t.track('played video', {:distinct_id => 1})

# Log the event 'played video' on the 'Blog' channel
t.track('played video', {:channel => 'Blog'})

# Log an event with custom properties attached:
# Log the event 'search' on the 'Web site' channel along with
# any related properties you wish to track
t.track('search', {
  :channel => 'Web site',
  :properties => {
    :search_term => 'iPad Air',
    :search_category => 'Electronics',
  },
})

The track method will set the class variable @distinct_id if you pass it a distinct_id in the opts hash.

Page View

Trak.page_view(url, page_title = nil, opts = {})

Page view is just a wrapper for: Trak.track('Page View')

Learn more about implementation of page_view on trak.io's API documentation

# Initilaize Trak object
t = Trak.new

# Log a user visiting the settings page
t.page_view('http://mysite.com/settings', 'Settings')

The page_view method will set the class variable @distinct_id if you pass it a distinct_id in the opts hash.

Annotate

Trak.annotate(event, opts = {})

Annotate is a way of recording system wide events that affect everyone. Annotations are similar to events except they are not associated with any one person.

Learn more about implementation of annotate on trak.io's API documentation

# Initilaize Trak object
t = Trak.new

# Annotate a deploy
t.annotate('Deployed update')

# Annotate a deploy for a specific channel
t.annotate('Deployed update', {:channel => 'Web site'})

Distinct ID

# Initilaize Trak object
t = Trak.new

# Returns the current distinct id
t.distinct_id

# Sets the current distinct_id
t.distinct_id = 1

Channel

# Initilaize Trak object
t = Trak.new

# Returns the current channel
t.channel

# Sets the current channel
t.channel = 'Web site'

===

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Ruby bindings for the trak.io API

License:MIT License


Languages

Language:Ruby 100.0%