diff --git a/lib/posthog/client.rb b/lib/posthog/client.rb index cc346f9..51a2b8e 100644 --- a/lib/posthog/client.rb +++ b/lib/posthog/client.rb @@ -50,7 +50,7 @@ def initialize(opts = {}) @api_key, opts[:host] ) - + @distinct_id_has_sent_flag_calls = SizeLimitedHash.new(Defaults::MAX_HASH_SIZE) { |hash, key| hash[key] = Array.new } at_exit { @worker_thread && @worker_thread[:should_exit] = true } @@ -87,6 +87,7 @@ def clear # @option attrs [String] :event Event name # @option attrs [Hash] :properties Event properties (optional) # @option attrs [Bool] :send_feature_flags Whether to send feature flags with this event (optional) + # @option attrs [String] :uuid ID that uniquely identifies an event # @macro common_attrs def capture(attrs) symbolize_keys! attrs @@ -160,7 +161,7 @@ def is_feature_enabled(flag_key, distinct_id, groups: {}, person_properties: {}, # @param [Hash] groups # @param [Hash] person_properties key-value pairs of properties to associate with the user. # @param [Hash] group_properties - # + # # @return [String, nil] The value of the feature flag # # The provided properties are used to calculate feature flags locally, if possible. @@ -202,7 +203,7 @@ def get_feature_flag(key, distinct_id, groups: {}, person_properties: {}, group_ # @param [Hash] groups # @param [Hash] person_properties key-value pairs of properties to associate with the user. # @param [Hash] group_properties - # + # # @return [Hash] String (not symbol) key value pairs of flag and their values def get_all_flags(distinct_id, groups: {}, person_properties: {}, group_properties: {}, only_evaluate_locally: false) person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups, person_properties, group_properties) diff --git a/lib/posthog/field_parser.rb b/lib/posthog/field_parser.rb index fb72982..25fc6b1 100644 --- a/lib/posthog/field_parser.rb +++ b/lib/posthog/field_parser.rb @@ -8,12 +8,14 @@ class << self # - "event" # - "properties" # - "groups" + # - "uuid" 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') @@ -23,6 +25,11 @@ def parse_for_capture(fields) properties["$groups"] = groups end + if uuid + check_is_uuid!(uuid) + common[:uuid] = uuid + end + isoify_dates! properties common.merge( @@ -164,6 +171,12 @@ def check_presence!(obj, name) def check_is_hash!(obj, name) raise ArgumentError, "#{name} must be a Hash" unless obj.is_a? Hash end + + def check_is_uuid!(uuid) + unless uuid.match?(/^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/i) + raise ArgumentError, "uuid is not formated like a uuid" + end + end end end end