Class: PostHog::FieldParser
- Inherits:
-
Object
- Object
- PostHog::FieldParser
- Extended by:
- Utils
- 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 Utils
convert_to_datetime, date_in_iso8601, datetime_in_iso8601, formatted_offset, 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”
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/posthog/field_parser.rb', line 87 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”
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 |
# File 'lib/posthog/field_parser.rb', line 11 def parse_for_capture(fields) common = parse_common_fields(fields) event = fields[:event] properties = fields[:properties] || {} groups = fields[:groups] check_presence!(event, 'event') check_is_hash!(properties, 'properties') if groups check_is_hash!(groups, 'groups') properties["$groups"] = groups end isoify_dates! properties common.merge( { type: 'capture', event: event.to_s, properties: properties.merge(common[:properties] || {}) } ) end |
.parse_for_group_identify(fields) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/posthog/field_parser.rb', line 58 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”
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/posthog/field_parser.rb', line 40 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 |