posthog-ruby 3.7.0 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afcf66d4afc793e15c83b53e455ef605218def4581460279d45721b82c1f73f2
4
- data.tar.gz: 96f13bf72ddc840302d71c21072db26bdd098b73fd862455dc65b745357dc7d2
3
+ metadata.gz: 4400cef0c43dd5e79c18f38712b6f0033271f798ad8f97362338516ab491185a
4
+ data.tar.gz: c789f72bcd04df210a74e79d9069e20a5a7f02b0b9b48eae344f58a33c348c8e
5
5
  SHA512:
6
- metadata.gz: 8b3e3871c5be034db9928b012cc0a3417121dc6f1ab4e7c5ece24e1c637dc04959ef50e4f551de598e11c4922d4f54048a9438bb03c86eb1e0eac67eabefdf7d
7
- data.tar.gz: 3bf3128f6333b9678aa9c3a616494fcbff369ece30a0b0c422468cdab8856902a4184a560da84d6dbadb3dc935555b7402fe63d9158ea1da62589115247e7357
6
+ metadata.gz: fc6f2f8cfd188881c9aec1ab5867bf555ebfc8fdf12f87e2fb086884e75968e268df8346b1463a563bb48529f6f7c6326366718885c6e6584aa140ff5aa15f87
7
+ data.tar.gz: 7b6c516b339b0beaa8a0980d5e1d02027e826065f6bb28c85817344227cced2500b95e359bfe8955af952f553dc9b6cee958be8ffe2f52629d1bd1cf3df5e6f6
@@ -364,15 +364,15 @@ module PostHog
364
364
  !!response
365
365
  end
366
366
 
367
- # @param [String] flag_key The unique flag key of the feature flag
367
+ # @param [String, Symbol] flag_key The unique flag key of the feature flag
368
368
  # @return [String] The decrypted value of the feature flag payload
369
369
  def get_remote_config_payload(flag_key)
370
- @feature_flags_poller.get_remote_config_payload(flag_key)
370
+ @feature_flags_poller.get_remote_config_payload(flag_key.to_s)
371
371
  end
372
372
 
373
373
  # Returns whether the given feature flag is enabled for the given user or not
374
374
  #
375
- # @param [String] key The key of the feature flag
375
+ # @param [String, Symbol] key The key of the feature flag
376
376
  # @param [String] distinct_id The distinct id of the user
377
377
  # @param [Hash] groups
378
378
  # @param [Hash] person_properties key-value pairs of properties to associate with the user.
@@ -455,7 +455,7 @@ module PostHog
455
455
  # @param [Hash] group_properties
456
456
  # @param [Boolean] only_evaluate_locally Skip the remote /flags call entirely
457
457
  # @param [Boolean] disable_geoip Stamped on captured access events
458
- # @param [Array<String>] flag_keys When set, scopes the underlying /flags
458
+ # @param [Array<String, Symbol>] flag_keys When set, scopes the underlying /flags
459
459
  # request to only these flag keys (sent as `flag_keys_to_evaluate`).
460
460
  # Distinct from {FeatureFlagEvaluations#only}, which filters the
461
461
  # already-fetched snapshot in memory.
@@ -598,7 +598,7 @@ module PostHog
598
598
  # @deprecated Use {#get_feature_flag_result} instead, which returns both the flag value and payload
599
599
  # and properly raises the $feature_flag_called event.
600
600
  #
601
- # @param [String] key The key of the feature flag
601
+ # @param [String, Symbol] key The key of the feature flag
602
602
  # @param [String] distinct_id The distinct id of the user
603
603
  # @option [String or boolean] match_value The value of the feature flag to be matched
604
604
  # @option [Hash] groups
@@ -623,6 +623,7 @@ module PostHog
623
623
  'instead — this consolidates flag evaluation into a single `/flags` request per ' \
624
624
  'incoming request.'
625
625
  )
626
+ key = key.to_s
626
627
  person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups,
627
628
  person_properties, group_properties)
628
629
  @feature_flags_poller.get_feature_flag_payload(key, distinct_id, match_value, groups, person_properties,
@@ -725,6 +726,7 @@ module PostHog
725
726
  only_evaluate_locally: false,
726
727
  send_feature_flag_events: true
727
728
  )
729
+ key = key.to_s
728
730
  person_properties, group_properties = add_local_person_and_group_properties(
729
731
  distinct_id, groups, person_properties, group_properties
730
732
  )
@@ -125,6 +125,7 @@ module PostHog
125
125
 
126
126
  def get_flags(distinct_id, groups = {}, person_properties = {}, group_properties = {}, flag_keys = nil,
127
127
  disable_geoip = nil)
128
+ flag_keys = flag_keys.map(&:to_s) if flag_keys.is_a?(Array)
128
129
  request_data = {
129
130
  distinct_id: distinct_id,
130
131
  groups: groups,
@@ -160,7 +161,7 @@ module PostHog
160
161
  end
161
162
 
162
163
  def get_remote_config_payload(flag_key)
163
- _request_remote_config_payload(flag_key)
164
+ _request_remote_config_payload(flag_key.to_s)
164
165
  end
165
166
 
166
167
  def get_feature_flag(
@@ -171,6 +172,8 @@ module PostHog
171
172
  group_properties = {},
172
173
  only_evaluate_locally = false
173
174
  )
175
+ key = key.to_s
176
+
174
177
  # make sure they're loaded on first run
175
178
  load_feature_flags
176
179
 
@@ -363,6 +366,8 @@ module PostHog
363
366
  group_properties = {},
364
367
  only_evaluate_locally = false
365
368
  )
369
+ key = key.to_s
370
+
366
371
  if match_value.nil?
367
372
  match_value = get_feature_flag(
368
373
  key,
@@ -892,7 +897,8 @@ module PostHog
892
897
 
893
898
  aggregation_group_type_index = flag_filters[:aggregation_group_type_index]
894
899
  if aggregation_group_type_index.nil?
895
- return match_feature_flag_properties(flag, distinct_id, person_properties, evaluation_cache, @cohorts)
900
+ return match_feature_flag_properties(flag, distinct_id, person_properties, evaluation_cache, @cohorts,
901
+ groups: groups, group_properties: group_properties)
896
902
  end
897
903
 
898
904
  group_name = @group_type_mapping[aggregation_group_type_index.to_s.to_sym]
@@ -916,12 +922,13 @@ module PostHog
916
922
 
917
923
  focused_group_properties = group_properties[group_name_symbol]
918
924
  match_feature_flag_properties(flag, groups[group_name_symbol], focused_group_properties, evaluation_cache,
919
- @cohorts)
925
+ @cohorts, groups: groups, group_properties: group_properties)
920
926
  end
921
927
 
922
928
  def _compute_flag_payload_locally(key, match_value)
923
929
  return nil if @feature_flags_by_key.nil?
924
930
 
931
+ key = key.to_s
925
932
  response = nil
926
933
  if [true, false].include? match_value
927
934
  response = @feature_flags_by_key.dig(key, :filters, :payloads, match_value.to_s.to_sym)
@@ -931,23 +938,57 @@ module PostHog
931
938
  response
932
939
  end
933
940
 
934
- def match_feature_flag_properties(flag, distinct_id, properties, evaluation_cache, cohort_properties = {})
941
+ def match_feature_flag_properties(flag, distinct_id, properties, evaluation_cache, cohort_properties = {},
942
+ groups: {}, group_properties: {})
935
943
  flag_filters = flag[:filters] || {}
936
944
 
937
945
  flag_conditions = flag_filters[:groups] || []
946
+ flag_aggregation = flag_filters[:aggregation_group_type_index]
938
947
  is_inconclusive = false
939
948
  result = nil
940
949
 
941
950
  # NOTE: This NEEDS to be `each` because `each_key` breaks
942
951
  flag_conditions.each do |condition|
943
- if condition_match(flag, distinct_id, condition, properties, evaluation_cache, cohort_properties)
952
+ # Per-condition aggregation overrides only when the condition explicitly
953
+ # sets its own aggregation_group_type_index (mixed targeting). When absent,
954
+ # use the properties/bucketing already resolved by the caller.
955
+ condition_aggregation = condition.fetch(:aggregation_group_type_index, flag_aggregation)
956
+
957
+ effective_properties = properties
958
+ effective_bucketing = distinct_id
959
+
960
+ # Mixed-override path: condition-level aggregation differs from flag-level.
961
+ # This assumes flag-level aggregation is nil for mixed flags.
962
+ if condition_aggregation != flag_aggregation
963
+ if condition_aggregation.nil?
964
+ # Person condition under a mixed flag — caller already passed person props/bucketing.
965
+ else
966
+ group_name = @group_type_mapping[condition_aggregation.to_s.to_sym]
967
+ if group_name.nil? || !groups.key?(group_name.to_sym)
968
+ logger.debug do
969
+ "[FEATURE FLAGS] Skipping group condition for flag '#{flag[:key]}': " \
970
+ "group type index #{condition_aggregation} not available"
971
+ end
972
+ next
973
+ end
974
+ unless group_properties.key?(group_name.to_sym)
975
+ is_inconclusive = true
976
+ next
977
+ end
978
+ effective_properties = group_properties[group_name.to_sym]
979
+ effective_bucketing = groups[group_name.to_sym]
980
+ end
981
+ end
982
+
983
+ if condition_match(flag, effective_bucketing, condition, effective_properties, evaluation_cache,
984
+ cohort_properties)
944
985
  variant_override = condition[:variant]
945
986
  flag_multivariate = flag_filters[:multivariate] || {}
946
987
  flag_variants = flag_multivariate[:variants] || []
947
988
  variant = if flag_variants.map { |variant| variant[:key] }.include?(condition[:variant])
948
989
  variant_override
949
990
  else
950
- get_matching_variant(flag, distinct_id)
991
+ get_matching_variant(flag, effective_bucketing)
951
992
  end
952
993
  result = variant || true
953
994
  break
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.7.0'
4
+ VERSION = '3.8.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthog-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''