Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removing session_id

  • Loading branch information...
commit 6cb7b17c581d078a24560cebf308df18c64fda59 1 parent 7c30d04
@calvinfo calvinfo authored
View
30 lib/analytics/client.rb
@@ -31,23 +31,21 @@ def initialize (options = {})
#
# options - Hash
# :event - String of event name.
- # :sessionId - String of the user session. (optional with userId)
- # :userId - String of the user id. (optional with sessionId)
- # :context - Hash of context. (optional)
+ # :user_id - String of the user id.
# :properties - Hash of event properties. (optional)
# :timestamp - Time of when the event occurred. (optional)
+ # :context - Hash of context. (optional)
def track(options)
check_secret
event = options[:event]
- session_id = options[:session_id]
user_id = options[:user_id]
- context = options[:context] || {}
properties = options[:properties] || {}
timestamp = options[:timestamp] || Time.new
+ context = options[:context] || {}
- ensure_user(session_id, user_id)
+ ensure_user(user_id)
check_timestamp(timestamp)
if event.nil? || event.empty?
@@ -57,7 +55,6 @@ def track(options)
add_context(context)
enqueue({ event: event,
- sessionId: session_id,
userId: user_id,
context: context,
properties: properties,
@@ -68,30 +65,27 @@ def track(options)
# public: Identifies a user
#
# options - Hash
- # :sessionId - String of the user session. (optional with userId)
- # :userId - String of the user id. (optional with sessionId)
- # :context - Hash of context. (optional)
+ # :user_id - String of the user id
# :traits - Hash of user traits. (optional)
# :timestamp - Time of when the event occurred. (optional)
+ # :context - Hash of context. (optional)
def identify(options)
check_secret
- session_id = options[:session_id]
user_id = options[:user_id]
- context = options[:context] || {}
traits = options[:traits] || {}
timestamp = options[:timestamp] || Time.new
+ context = options[:context] || {}
- ensure_user(session_id, user_id)
+ ensure_user(user_id)
check_timestamp(timestamp)
fail ArgumentError, 'Must supply traits as a hash' unless traits.is_a? Hash
add_context(context)
- enqueue({ sessionId: session_id,
- userId: user_id,
+ enqueue({ userId: user_id,
context: context,
traits: traits,
timestamp: timestamp.iso8601,
@@ -119,14 +113,12 @@ def enqueue(action)
# private: Ensures that a user id was passed in.
#
- # session_id - String of the session
# user_id - String of the user id
#
- def ensure_user(session_id, user_id)
- message = 'Must supply either a non-empty session_id or user_id (or both)'
+ def ensure_user(user_id)
+ message = 'Must supply a non-empty user_id'
valid = user_id.is_a?(String) && !user_id.empty?
- valid ||= session_id.is_a?(String) && !session_id.empty?
fail ArgumentError, message unless valid
end
View
2  spec/client_spec.rb
@@ -26,7 +26,7 @@
expect { @client.track(user_id: 'user') }.to raise_error(ArgumentError)
end
- it 'should error without a user or session' do
+ it 'should error without a user_id' do
expect { @client.track(event: 'Event') }.to raise_error(ArgumentError)
end
View
2  spec/module_spec.rb
@@ -17,7 +17,7 @@
expect { Analytics.track user_id: 'user' }.to raise_error(ArgumentError)
end
- it 'should error without a user or session' do
+ it 'should error without a user_id' do
expect { Analytics.track event: 'Event' }.to raise_error(ArgumentError)
end
View
5 spec/spec_helper.rb
@@ -21,14 +21,12 @@ module AnalyticsHelpers
}
USER_ID = 'Bret'
- SESSION_ID = '4815162342'
# Hashes sent to the client
module Queued
TRACK = TRACK.merge({ user_id: USER_ID })
- IDENTIFY = IDENTIFY.merge({ user_id: USER_ID,
- session_id: SESSION_ID })
+ IDENTIFY = IDENTIFY.merge({ user_id: USER_ID })
end
# Hashes which are sent from the consumer
@@ -37,7 +35,6 @@ module Requested
action: 'track' })
IDENTIFY = IDENTIFY.merge({ userId: USER_ID,
- sessionId: SESSION_ID,
action: 'identify' })
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.