9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/bento/sdk/field_parser.rb', line 9
def parse_for_track(fields, write_key)
common = parse_common_fields(fields)
event = fields[:event]
custom_fields = fields[:custom_fields] || {}
details = fields[:details] || {}
identity = fields[:identity] || {}
visitor_uuid = fields[:visitor_uuid] || Digest::SHA2.hexdigest("api" + identity.to_s + write_key)
page = fields[:page] || {}
check_presence!(event, "event")
check_is_hash!(details, "details")
check_is_hash!(page, "page")
check_is_hash!(identity, "identity")
check_is_hash!(custom_fields, "custom_fields")
isoify_dates! details
final_event = {
id: SecureRandom.hex(10),
site: write_key,
identity: identity,
visit: Digest::SHA2.hexdigest(Time.now.strftime("%B %e, %Y") + identity.to_s + write_key),
visitor: visitor_uuid,
type: event.to_s,
date: Time.now,
browser: {
"user_agent" => "Bento/API (Rails)",
},
page: page,
details: details,
fields: custom_fields,
}
common = common.merge(final_event)
common
end
|