Not logged in - Login
< back

Library: Ruby

We have made a library for PHP to help you start using A Trigger in a minute. This PHP library is made to avoid possible errors in your application. Even if API server become unavailable, your application will work without any problem. On the other hand, all requests are Async by default and no slowness will happen.


  1. First you need to follow Quick Start Guide.
  2. You have this personal details from your Account Setup page:
    1. API Key
    2. API Secret

Step 1: Initialize

Add analytics-rubyATrigger to your project's Gemfile:

gem 'ATrigger'
#gem install ATrigger

Then,You addcan create separate ATrigger clients, but the followingeasiest and recommended way is to yourjust PHPuse script:

//require(dirname(__FILE__)the .module. '/ATriggerPHP/ATrigger.php');
If you're using Rails, put this in config/initializers/ATrigger.rb.


Analytics.init({ onlykey: need"YOUR_API_KEY", tosecret: call"YOUR_API_Secret" init})
#Debug-friendly: onceATrigger::init({key: when"YOUR_API_KEY", yoursecret: php"YOUR_API_Secret", file is requested. All of your files will then have access to the same ATrigger client.

//Debug-friendly: ATrigger::init("YOUR_APIKey","YOUR_APISecret",async: false, true);debug: true})

In development you might want to use development settings above to start debugging. Also you can require 'ATrigger' from your application code and then run the ATrigger::init method. You only need to initialize the module once. Whenever you require ATrigger from another file in your app you'll have access to the same Analytics instance.

Unicorn If you're using unicorn in production to run multiple ruby processes, you'll need to initialize the module in the post-fork section of your unicorn.rb config file.

# unicorn.rb

before_fork do |server, worker|

after_fork do |server, worker|
  defined?(Analytics) and Analytics.init({ key: "YOUR_API_KEY", secret: "YOUR_API_Secret" })

#Debug-friendly: ATrigger::init({key: "YOUR_API_KEY", secret: "YOUR_API_Secret", async: false, debug: true})

Passenger If you're using passenger in production to run multiple worker processes, you'll need to initialize the analytics module in your environment.rb when those workers are initiated.

# config/environment.rb

if defined?(PhusionPassenger)
  PhusionPassenger.on_event(:starting_worker_process) do |forked|

    if forked # We're in smart spawning mode.
      Analytics.init({ key: "YOUR_API_KEY", secret: "YOUR_API_Secret" })
      #Debug-friendly: ATrigger::init({key: "YOUR_API_KEY", secret: "YOUR_API_Secret", async: false, debug: true})
      # We're in direct spawning mode. We don't need to do anything.

Step 2: Start Using, Functions