Class: PostHog::FieldParser
- Inherits:
-
Object
- Object
- PostHog::FieldParser
- Defined in:
- lib/posthog/field_parser.rb
Constant Summary
Constants included from Utils
Utils::UTC_OFFSET_WITHOUT_COLON, Utils::UTC_OFFSET_WITH_COLON
Class Method Summary collapse
-
.parse_for_alias(fields) ⇒ Object
In addition to the common fields, alias accepts:.
-
.parse_for_capture(fields) ⇒ Object
In addition to the common fields, capture accepts:.
- .parse_for_group_identify(fields) ⇒ Object
-
.parse_for_identify(fields) ⇒ Object
In addition to the common fields, identify accepts:.
Methods included from Logging
Methods included from Utils
convert_to_datetime, date_in_iso8601, datetime_in_iso8601, formatted_offset, get_by_symbol_or_string_key, is_valid_regex, isoify_dates, isoify_dates!, seconds_to_utc_offset, stringify_keys, symbolize_keys, symbolize_keys!, time_in_iso8601, uid
Class Method Details
.parse_for_alias(fields) ⇒ Object
In addition to the common fields, alias accepts:
-
“alias”
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/posthog/field_parser.rb', line 95 def parse_for_alias(fields) common = parse_common_fields(fields) distinct_id = common[:distinct_id] # must both be set and move to properties alias_field = fields[:alias] check_presence! alias_field, 'alias' common.merge( { type: 'alias', event: '$create_alias', distinct_id: distinct_id, properties: { distinct_id: distinct_id, alias: alias_field }.merge( common[:properties] || {} ) } ) end |
.parse_for_capture(fields) ⇒ Object
In addition to the common fields, capture accepts:
-
“event”
-
“properties”
-
“groups”
-
“uuid”
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 |
# File 'lib/posthog/field_parser.rb', line 17 def parse_for_capture(fields) common = parse_common_fields(fields) event = fields[:event] properties = fields[:properties] || {} groups = fields[:groups] uuid = fields[:uuid] check_presence!(event, 'event') check_is_hash!(properties, 'properties') if groups check_is_hash!(groups, 'groups') properties['$groups'] = groups end isoify_dates! properties common['uuid'] = uuid if valid_uuid_for_event_props? uuid common.merge( { type: 'capture', event: event.to_s, properties: properties.merge(common[:properties] || {}) } ) end |
.parse_for_group_identify(fields) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/posthog/field_parser.rb', line 66 def parse_for_group_identify(fields) properties = fields[:properties] || {} group_type = fields[:group_type] group_key = fields[:group_key] check_presence!(group_type, 'group type') check_presence!(group_key, 'group_key') check_is_hash!(properties, 'properties') fields[:distinct_id] ||= "$#{group_type}_#{group_key}" common = parse_common_fields(fields) isoify_dates! properties common.merge( { event: '$groupidentify', properties: { '$group_type': group_type, '$group_key': group_key, '$group_set': properties.merge(common[:properties] || {}) } } ) end |
.parse_for_identify(fields) ⇒ Object
In addition to the common fields, identify accepts:
-
“properties”
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/posthog/field_parser.rb', line 48 def parse_for_identify(fields) common = parse_common_fields(fields) properties = fields[:properties] || {} check_is_hash!(properties, 'properties') isoify_dates! properties common.merge( { type: 'identify', event: '$identify', '$set': properties, properties: properties.merge(common[:properties] || {}) } ) end |