module Staccato
The `Staccato` module namespace
@author Tony Pitale
Constants
Public Class Methods
as_url(hit, uri = nil)
click to toggle source
Build a url string from any hit type
@param hit [Hit] anything that returns a hash for params @param uri [URI] @return String
# File lib/staccato.rb, line 54 def self.as_url(hit, uri = nil) uri ||= hit.tracker.default_uri uri.query = URI.encode_www_form(hit.params) uri.to_s end
build_client_id()
click to toggle source
Build a new random `client_id`
@return [String] a random value suitable for use as a `client_id`
# File lib/staccato.rb, line 33 def self.build_client_id SecureRandom.uuid end
default_adapter()
click to toggle source
The default adapter to use for sending hits
# File lib/staccato.rb, line 44 def self.default_adapter require 'staccato/adapter/net_http' Staccato::Adapter::Net::HTTP end
ga_collection_uri(ssl = false)
click to toggle source
The tracking endpoint we use to submit requests to GA
# File lib/staccato.rb, line 38 def self.ga_collection_uri(ssl = false) url = (ssl ? 'https://' : 'http://') + 'www.google-analytics.com/collect' URI(url) end
tracker(id, client_id = nil, options = {}) { |tracker| ... }
click to toggle source
Build a new tracker instance
If the first argument is explicitly `nil`, a `NoopTracker` is returned which responds to all the same `tracker` methods but does no tracking
@param id [String, nil] the id provided by google, i.e., `UA-XXXXXX-Y` @param client_id [String, Integer, nil] a unique id to track the session of
an individual user
@param hit_options [Hash] options for use in all hits from this tracker @yield [Staccato::Tracker] the new tracker @return [Staccato::Tracker] a new tracker is returned
# File lib/staccato.rb, line 22 def self.tracker(id, client_id = nil, options = {}) klass = id.nil? ? Staccato::NoopTracker : Staccato::Tracker klass.new(id, client_id, options).tap do |tracker| yield tracker if block_given? end end