class TrakioClient::Track
Public Instance Methods
check_page_view_parameters(url)
click to toggle source
# File lib/trakio_client/track.rb, line 65 def check_page_view_parameters url unless url raise Exceptions::InvalidParameter.new("The `url` parameter must be provided.") end end
check_parameters(event, distinct_id, company_id, properties)
click to toggle source
# File lib/trakio_client/track.rb, line 53 def check_parameters event, distinct_id, company_id, properties unless event raise Exceptions::MissingParameter.new("The `event` parameter must be provided.") end unless distinct_id || company_id raise Exceptions::MissingParameter.new('Either a `company_id` or `distinct_id` parameter must be provided.') end unless properties.is_a?(Hash) raise Exceptions::InvalidParameter.new("The `properties` parameter must be a hash.") end end
page_view(p)
click to toggle source
# File lib/trakio_client/track.rb, line 24 def page_view p args = { event: 'Page view' } distinct_id = p[:distinct_id] || self.distinct_id url = p[:url] title = p[:title] check_page_view_parameters url properties = { url: url, } properties[:title] = title if title args[:properties] = properties args[:distinct_id] = distinct_id if distinct_id run args # right now page_view is an alias of track end
process_time(time)
click to toggle source
# File lib/trakio_client/track.rb, line 41 def process_time time if time if !time.is_a? String time.iso8601 else time end else DateTime.now.iso8601 end end
run(p = {})
click to toggle source
# File lib/trakio_client/track.rb, line 4 def run p = {} event = p[:event] distinct_id = p[:distinct_id] || self.distinct_id company_id = p[:company_id] || self.company_id channel = p[:channel] || self.channel properties = p[:properties] || {} check_parameters event, distinct_id, company_id, properties params = { event: event } params[:time] = process_time p[:time] params[:channel] = channel if channel params[:properties] = properties if properties && !properties.empty? params[:company_id] = company_id if company_id params[:distinct_id] = distinct_id if distinct_id send_request('track', params) end