Class: PostHog::FieldParser Private

Inherits:
Object
  • Object
show all
Extended by:
Logging, Utils
Defined in:
lib/posthog/field_parser.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Converts public SDK method arguments into PostHog API event payloads.

Constant Summary

Constants included from Utils

Utils::UTC_OFFSET_WITHOUT_COLON, Utils::UTC_OFFSET_WITH_COLON

Class Method Summary collapse

Methods included from Logging

included, logger

Methods included from Utils

convert_to_datetime, date_in_iso8601, datetime_in_iso8601, deep_symbolize_keys, 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

Class Method Details

.parse_for_alias(fields) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

In addition to the common fields, alias accepts:

  • “alias”

Parameters:

  • fields (Hash)

Returns:

  • (Hash)


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/posthog/field_parser.rb', line 105

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) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

In addition to the common fields, capture accepts:

  • “event”

  • “properties”

  • “groups”

  • “uuid”

Parameters:

  • fields (Hash)

Returns:

  • (Hash)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/posthog/field_parser.rb', line 24

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) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • fields (Hash)

Returns:

  • (Hash)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/posthog/field_parser.rb', line 74

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: (common[:properties] || {}).merge(
        '$group_type': group_type,
        '$group_key': group_key,
        '$group_set': properties
      )
    }
  )
end

.parse_for_identify(fields) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

In addition to the common fields, identify accepts:

  • “properties”

Parameters:

  • fields (Hash)

Returns:

  • (Hash)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/posthog/field_parser.rb', line 54

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