posthog-ruby 3.9.5 → 3.11.0

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: 26f691859b23fd8a734457d5210bcfe633213c352c7362b375cf0107c169fce6
4
- data.tar.gz: b4b3803c627bf7f2f680e26ea986c40a5c36ec73ec87ef197b4d4fa702e5cb77
3
+ metadata.gz: 334d837a2faf144afce1125f198607af7d4078b34329c394df8e4e221bf1ab89
4
+ data.tar.gz: 62c48db3c45c0a962294546c06b485ace4e4d6f40bd5178f6c393f61e4243344
5
5
  SHA512:
6
- metadata.gz: 4163a8b03c807016df84525b4adf6aa4a55af22c5354e4710dd82d2fc5222015c242a22ad5e9564614686527c0ff97e72cd0b40d18b3bace964bcb68d3fe8c7c
7
- data.tar.gz: 5ad637fd4df58d0d296b30c820c7017957ed4eae7488e639402504b4d477a97d30e9533a2fe14373ae5806ee515eab21522a2c6ef81222de4ce9e43dd1042a18
6
+ metadata.gz: 2e23767920c9f2169e45dfae59515e15bb17df9d6c69d08caaea786b4ee3a84f2e47aac6ac0f677b9193862eaf571c6657f1975142b749d8766fb49fcbf4c2c4
7
+ data.tar.gz: 7e51f30ec5ff951e639ce97efba159fa63a419897b12b5ca6418149323fd7a2ae469bbca2ba13eb9fa02cf8071cf0e39453cd96282eaadf4bdf1331e4269ae6e
@@ -73,6 +73,9 @@ module PostHog
73
73
  # Intended only for local development or custom deployments.
74
74
  # @option opts [Object] :flag_definition_cache_provider An object implementing the {FlagDefinitionCacheProvider}
75
75
  # interface for distributed flag definition caching.
76
+ # @option opts [Boolean] :is_server +true+ to stamp captured events with `$is_server => true` so PostHog
77
+ # attributes them as server-side. Defaults to +true+. Set to +false+ when running posthog-ruby as a
78
+ # client/CLI so the device OS is attributed normally and `$is_server` is omitted.
76
79
  def initialize(opts = {})
77
80
  symbolize_keys!(opts)
78
81
 
@@ -141,6 +144,7 @@ module PostHog
141
144
  end
142
145
 
143
146
  @before_send = opts[:before_send]
147
+ @is_server = opts.fetch(:is_server, true) != false
144
148
  @deprecation_emitted_for = Concurrent::Set.new
145
149
  end
146
150
 
@@ -272,6 +276,7 @@ module PostHog
272
276
  attrs[:feature_variants] = feature_variants if feature_variants
273
277
  end
274
278
 
279
+ attrs[:is_server] = @is_server
275
280
  enqueue(FieldParser.parse_for_capture(attrs))
276
281
  end
277
282
 
@@ -317,6 +322,7 @@ module PostHog
317
322
  return false if @disabled
318
323
 
319
324
  symbolize_keys! attrs
325
+ attrs[:is_server] = @is_server
320
326
  enqueue(FieldParser.parse_for_identify(attrs))
321
327
  end
322
328
 
@@ -334,6 +340,7 @@ module PostHog
334
340
  return false if @disabled
335
341
 
336
342
  symbolize_keys! attrs
343
+ attrs[:is_server] = @is_server
337
344
  enqueue(FieldParser.parse_for_group_identify(attrs))
338
345
  end
339
346
 
@@ -348,6 +355,7 @@ module PostHog
348
355
  return false if @disabled
349
356
 
350
357
  symbolize_keys! attrs
358
+ attrs[:is_server] = @is_server
351
359
  enqueue(FieldParser.parse_for_alias(attrs))
352
360
  end
353
361
 
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Portions of this file are derived from getsentry/sentry-ruby by Software, Inc. dba Sentry
4
- # Licensed under the MIT License
3
+ # Portions of this file are derived from getsentry/sentry-ruby
4
+ # Copyright (c) 2020 Sentry
5
+ # Licensed under the MIT License: https://github.com/getsentry/sentry-ruby/blob/master/LICENSE
5
6
  # - sentry-ruby/lib/sentry/interfaces/single_exception.rb
6
7
  # - sentry-ruby/lib/sentry/interfaces/stacktrace_builder.rb
7
8
  # - sentry-ruby/lib/sentry/backtrace.rb
@@ -961,6 +961,7 @@ module PostHog
961
961
 
962
962
  flag_conditions = flag_filters[:groups] || []
963
963
  flag_aggregation = flag_filters[:aggregation_group_type_index]
964
+ early_exit = flag_filters[:early_exit] == true
964
965
  is_inconclusive = false
965
966
  result = nil
966
967
 
@@ -997,8 +998,9 @@ module PostHog
997
998
  end
998
999
  end
999
1000
 
1000
- if condition_match(flag, effective_bucketing, condition, effective_properties, evaluation_cache,
1001
- cohort_properties)
1001
+ case condition_match_outcome(flag, effective_bucketing, condition, effective_properties, evaluation_cache,
1002
+ cohort_properties)
1003
+ when :match
1002
1004
  variant_override = condition[:variant]
1003
1005
  flag_multivariate = flag_filters[:multivariate] || {}
1004
1006
  flag_variants = flag_multivariate[:variants] || []
@@ -1009,6 +1011,8 @@ module PostHog
1009
1011
  end
1010
1012
  result = variant || true
1011
1013
  break
1014
+ when :out_of_rollout_bound
1015
+ break if early_exit
1012
1016
  end
1013
1017
  rescue RequiresServerEvaluation
1014
1018
  # Static cohort or other missing server-side data - must fallback to API
@@ -1030,6 +1034,18 @@ module PostHog
1030
1034
  end
1031
1035
 
1032
1036
  def condition_match(flag, distinct_id, condition, properties, evaluation_cache, cohort_properties = {})
1037
+ condition_match_outcome(flag, distinct_id, condition, properties, evaluation_cache,
1038
+ cohort_properties) == :match
1039
+ end
1040
+
1041
+ # Evaluates a single condition group and returns a tri-state outcome:
1042
+ # :match - property filters matched AND the rollout included the user
1043
+ # :no_match - a property filter did NOT match
1044
+ # :out_of_rollout_bound - property filters matched (or there were none) but the
1045
+ # rollout percentage excluded the user
1046
+ # Distinguishing :no_match from :out_of_rollout_bound lets the caller implement the
1047
+ # early_exit behavior (mirrors the server-side Rust evaluation engine).
1048
+ def condition_match_outcome(flag, distinct_id, condition, properties, evaluation_cache, cohort_properties = {})
1033
1049
  rollout_percentage = condition[:rollout_percentage]
1034
1050
 
1035
1051
  unless (condition[:properties] || []).empty?
@@ -1040,15 +1056,17 @@ module PostHog
1040
1056
  FeatureFlagsPoller.match_property(prop, properties, cohort_properties)
1041
1057
  end
1042
1058
  end
1043
- return false
1059
+ return :no_match
1044
1060
  end
1045
1061
 
1046
- return true if rollout_percentage.nil?
1062
+ return :match if rollout_percentage.nil?
1047
1063
  end
1048
1064
 
1049
- return false if !rollout_percentage.nil? && (_hash(flag[:key], distinct_id) > (rollout_percentage.to_f / 100))
1065
+ if !rollout_percentage.nil? && (_hash(flag[:key], distinct_id) > (rollout_percentage.to_f / 100))
1066
+ return :out_of_rollout_bound
1067
+ end
1050
1068
 
1051
- true
1069
+ :match
1052
1070
  end
1053
1071
 
1054
1072
  # This function takes a distinct_id and a feature flag key and returns a float between 0 and 1.
@@ -89,11 +89,11 @@ module PostHog
89
89
  common.merge(
90
90
  {
91
91
  event: '$groupidentify',
92
- properties: {
92
+ properties: (common[:properties] || {}).merge(
93
93
  '$group_type': group_type,
94
94
  '$group_key': group_key,
95
- '$group_set': properties.merge(common[:properties] || {})
96
- }
95
+ '$group_set': properties
96
+ )
97
97
  }
98
98
  )
99
99
  end
@@ -141,16 +141,21 @@ module PostHog
141
141
  check_timestamp! timestamp
142
142
  check_presence! distinct_id, 'distinct_id'
143
143
 
144
+ is_server = fields.fetch(:is_server, true) != false
145
+
146
+ properties = {
147
+ '$lib' => 'posthog-ruby',
148
+ '$lib_version' => PostHog::VERSION.to_s
149
+ }
150
+ properties['$is_server'] = true if is_server
151
+
144
152
  parsed = {
145
153
  timestamp: datetime_in_iso8601(timestamp),
146
154
  library: 'posthog-ruby',
147
155
  library_version: PostHog::VERSION.to_s,
148
156
  messageId: message_id,
149
157
  distinct_id: distinct_id,
150
- properties: {
151
- '$lib' => 'posthog-ruby',
152
- '$lib_version' => PostHog::VERSION.to_s
153
- }
158
+ properties: properties
154
159
  }
155
160
 
156
161
  if send_feature_flags && fields[:feature_variants]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.9.5'
4
+ VERSION = '3.11.0'
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.9.5
4
+ version: 3.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''