Method: Segment::Analytics::Client#page
- Defined in:
- lib/segment/analytics/client.rb
#page(attrs) ⇒ Object
public: Records a page view
attrs - Hash
:anonymous_id - String of the user's id when you don't know who they are yet. (optional but you must provide either an anonymous_id or user_id. See: https://segment.io/docs/tracking - api/track/#user - id)
:category - String of the page category (optional)
:context - Hash of context (optional)
:integrations - Hash what integrations this event goes to. (optional)
:name - String name of the page
:options - Hash such as user traits. (optional)
:properties - Hash of page properties (optional)
:timestamp - Time of when the pageview occured (optional)
:user_id - String of the id to alias from
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/segment/analytics/client.rb', line 208 def page(attrs) symbolize_keys! attrs check_user_id! attrs name = attrs[:name].to_s properties = attrs[:properties] || {} = attrs[:timestamp] || Time.new context = attrs[:context] || {} fail ArgumentError, '.name must be a string' unless !name.empty? fail ArgumentError, '.properties must be a hash' unless properties.is_a? Hash isoify_dates! properties add_context context enqueue({ :userId => attrs[:user_id], :anonymousId => attrs[:anonymous_id], :name => name, :category => attrs[:category], :properties => properties, :integrations => attrs[:integrations], :options => attrs[:options], :context => context, :timestamp => datetime_in_iso8601(), :type => 'page' }) end |