GoSquared Ruby Gem

Build Status

Please feel free to open an issue if you find anything not working, or to leave feedback for improvement. You can also get in touch directly: [email protected]

This gems works with the GoSquared API, You can use it for both fetching metrics from your GoSquared account and also posting new events and contacts.

Note: if you are looking to set up GoSquared for the first time and install Analytics, People CRM and Live Chat within a Rails app, you can do so by using our GoSquared-Rails gem

All functions listed in the API documentation are methods you can call on the GoSquared class.

You can generate an API key from your GoSquared Account Settings.


gem install gosquared

Then require GoSquared in your application

require 'gosquared'

Tracking API

This is for sending data to GoSquared. It allows you to track:

  • Events
  • Transactions
  • People profiles

Track Events

gs = Gosquared::RubyLibrary.new("your_API_key","your_project_token")

gs.tracking.event({ event: { name: 'event' } })

#builds the url to the 'GoSquared Tracking' endpoint with the "events" dimension and an event to add to the events list


#posts the data to the 'GoSquared Tracking' endpoint

Response Message: OK
=> #<Net::HTTPOK 200 OK readbody=true>

Track Transactions

gs = Gosquared::RubyLibrary.new("your_API_key","your_project_token")

  transaction: { id: "1", revenue: 50, quantity: 1,
  previous_transaction_timestamp: Time.new }


Response Message: OK
=> #<Net::HTTPOK 200 OK readbody=true>

Create or Update People profiles

This method is useful for importing existing user profiles into GoSquared people and updating profiles you have already added.

It's highly recommended that you also implement the front end javascript 'identify' method on your site. This enables us to track a the user's session activity and browser information against their People profile.

We also recommend using an email address for the person_id. To do this, the email address needs to be prefixed with email: like in the example below.

gs = Gosquared::RubyLibrary.new("your_API_key","your_project_token")

  person_id: "email:[email protected]", # Required

  # Reserved property names
  properties: {
    name: "Test User",
    username: "testuser",
    phone: "+44123456789",
    created_at:"2016-06-07T15:44:20Z", # ISO 8601 formatted String
    company_industry:"Customer Analytics",
    company_size: 15000,

    # Custom properties
    custom: {
      # custom_property_name: "custom property value"  # You can track as many custom properties as you like


Response Message: OK
=> #<Net::HTTPOK 200 OK readbody=true>

Reporting API

This is for pulling data from your GoSquared account. It is split into 3 sections;

  • Now - realtime data
  • Trends – historical data (includes ecommerce)
  • People - user data
  • Account - administration


The Now API provides real-time concurrent information about your sites and apps, such as the number of concurrent visitors online, the most popular pages right now, the most influential traffic sources, and much more.

Now Example:

gs = Gosquared::RubyLibrary.new("your_API_key","your_project_token")

#instantiates new GoSquared object


#builds the url to the 'GoSquared Now' endpoint with the "Concurrents dimension"


#fetches the data from the 'GoSquared Now' endpoint

=> {"visitors"=>3, "returning"=>1, "pages"=>0, "active"=>0, "tagged"=>0}

The Trends API provides historical analytics information for any given period in a project's history. The data for the current period updates in real-time, so the figures are always fresh and up-to-date.

Trends Example:

gs = Gosquared::RubyLibrary.new("your_API_key","your_project_token")


#builds the url to the 'GoSquared Trends' endpoint with the "Trends dimension" and date filters


#fetches the filtered data from the 'GoSquared Trends' endpoint

=> {"list"=>[{"id"=>"chrome", "browser"=>"chrome", "name"=>"Chrome", "metrics"=>{"visits"=>3}}], "cardinality"=>1, "dimension"=>"browser", "range"=>{"from"=>"2016-06-30T00:00:00+01:00", "to"=>"2016-07-07T23:59:59+01:00"}, "interval"=>"day"}


gs = Gosquared::RubyLibrary.new("your_API_key","your_project_token")


#builds the url to the 'GoSquared People' endpoint with the "people" dimension.


#fetches all smartgroups associated with the account.


The Account API allows you to perform administrative actions against GoSquared accounts. This includes actions like changing settings, configuration, and listing resources under the account.

Account Example:

gs = Gosquared::RubyLibrary.new("your_API_key","your_project_token")


#builds the url to the 'GoSquared Account' endpoint with the "Blocked dimension" and ip address to add to the blocked list


#posts the data to the 'GoSquared Account' endpoint

Response Message: OK
=> #<Net::HTTPOK 200 OK readbody=true>


#builds the url to the 'GoSquared Account' endpoint with the "Sites" dimension and token you want to retrieve the site by.