posthog-ruby 3.0.1 → 3.1.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: e4e71138d169f5c226e194b90e5a0d9e0243389eb98bd32e9da67b2b5bf45c57
4
- data.tar.gz: c814fc65c03770c4ac056b4ab74d0b39efb268e1b7b778a29d06120158b20533
3
+ metadata.gz: 2c7c88ed8541cb75a430abfde7ec41a1df10253839b5bfaf4f92eb838b677860
4
+ data.tar.gz: 6d4549bb4e56e3d95a28ed0f70b75c275d45a30a40b8aa09756a5bcef0edfd5b
5
5
  SHA512:
6
- metadata.gz: 9b8950767de513e3aeae1487b7eacf1e272af98689d6906d1e04837c4bd8a7b7e7aba4c9cdb2d5eae8503b7e83d7d7e0c59e0d9952076da769500abb8839d51f
7
- data.tar.gz: 7ce785b37aeda279b27b8fde71592561c8854133a91a70f316b415487e601bd5646cb857b909c473eb30fd8767a50678b9c2ba5b43041827b1232775ccd2efe6
6
+ metadata.gz: eae21f85d2fd42612fc5aa7488db52cb7280f68a9bdb58bac1ead90f3c871ecb30d0195e2f211413fb2b6858846c0c5521da2e1c14d9833baf8128b5784370fb
7
+ data.tar.gz: 1329afd21f70e229b2126dddbae1d19a69fef99494c073a0d01cffb6160ae6a79f0471e56f3886bfe5a80432415c0e3901f98c5d327f68f65a0f9ea6c18197f0
@@ -8,6 +8,7 @@ require 'posthog/utils'
8
8
  require 'posthog/send_worker'
9
9
  require 'posthog/noop_worker'
10
10
  require 'posthog/feature_flags'
11
+ require 'posthog/send_feature_flags_options'
11
12
 
12
13
  module PostHog
13
14
  class Client
@@ -96,7 +97,8 @@ module PostHog
96
97
  #
97
98
  # @option attrs [String] :event Event name
98
99
  # @option attrs [Hash] :properties Event properties (optional)
99
- # @option attrs [Bool] :send_feature_flags Whether to send feature flags with this event (optional)
100
+ # @option attrs [Bool, Hash, SendFeatureFlagsOptions] :send_feature_flags
101
+ # Whether to send feature flags with this event, or configuration for feature flag evaluation (optional)
100
102
  # @option attrs [String] :uuid ID that uniquely identifies an event;
101
103
  # events in PostHog are deduplicated by the
102
104
  # combination of teamId, timestamp date,
@@ -105,10 +107,38 @@ module PostHog
105
107
  def capture(attrs)
106
108
  symbolize_keys! attrs
107
109
 
108
- if attrs[:send_feature_flags]
109
- feature_variants = @feature_flags_poller.get_feature_variants(attrs[:distinct_id], attrs[:groups] || {})
110
+ send_feature_flags_param = attrs[:send_feature_flags]
111
+ if send_feature_flags_param
112
+ # Handle different types of send_feature_flags parameter
113
+ case send_feature_flags_param
114
+ when true
115
+ # Backward compatibility: simple boolean
116
+ feature_variants = @feature_flags_poller.get_feature_variants(attrs[:distinct_id], attrs[:groups] || {})
117
+ when Hash
118
+ # Hash with options
119
+ options = SendFeatureFlagsOptions.from_hash(send_feature_flags_param)
120
+ feature_variants = @feature_flags_poller.get_feature_variants(
121
+ attrs[:distinct_id],
122
+ attrs[:groups] || {},
123
+ options ? options.person_properties : {},
124
+ options ? options.group_properties : {},
125
+ options ? options.only_evaluate_locally : false
126
+ )
127
+ when SendFeatureFlagsOptions
128
+ # SendFeatureFlagsOptions object
129
+ feature_variants = @feature_flags_poller.get_feature_variants(
130
+ attrs[:distinct_id],
131
+ attrs[:groups] || {},
132
+ send_feature_flags_param.person_properties,
133
+ send_feature_flags_param.group_properties,
134
+ send_feature_flags_param.only_evaluate_locally || false
135
+ )
136
+ else
137
+ # Invalid type, treat as false
138
+ feature_variants = nil
139
+ end
110
140
 
111
- attrs[:feature_variants] = feature_variants
141
+ attrs[:feature_variants] = feature_variants if feature_variants
112
142
  end
113
143
 
114
144
  enqueue(FieldParser.parse_for_capture(attrs))
@@ -62,6 +62,7 @@ module PostHog
62
62
  groups = {},
63
63
  person_properties = {},
64
64
  group_properties = {},
65
+ only_evaluate_locally = false,
65
66
  raise_on_error = false
66
67
  )
67
68
  # TODO: Convert to options hash for easier argument passing
@@ -70,7 +71,7 @@ module PostHog
70
71
  groups,
71
72
  person_properties,
72
73
  group_properties,
73
- false,
74
+ only_evaluate_locally,
74
75
  raise_on_error
75
76
  )
76
77
 
@@ -537,6 +538,14 @@ module PostHog
537
538
 
538
539
  unless (condition[:properties] || []).empty?
539
540
  if !condition[:properties].all? do |prop|
541
+ # Skip flag dependencies as they are not supported in local evaluation
542
+ if prop[:type] == 'flag'
543
+ logger.warn(
544
+ '[FEATURE FLAGS] Flag dependency filters are not supported in local evaluation. ' \
545
+ "Skipping condition for flag '#{flag[:key]}' with dependency on flag '#{prop[:key]}'"
546
+ )
547
+ next true
548
+ end
540
549
  FeatureFlagsPoller.match_property(prop, properties)
541
550
  end
542
551
  return false
@@ -142,7 +142,7 @@ module PostHog
142
142
  }
143
143
  }
144
144
 
145
- if send_feature_flags
145
+ if send_feature_flags && fields[:feature_variants]
146
146
  feature_variants = fields[:feature_variants]
147
147
  active_feature_variants = {}
148
148
  feature_variants.each do |key, value|
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'posthog/utils'
4
+
5
+ module PostHog
6
+ # Options for configuring feature flag behavior in capture calls
7
+ class SendFeatureFlagsOptions
8
+ attr_reader :only_evaluate_locally, :person_properties, :group_properties
9
+
10
+ def initialize(only_evaluate_locally: nil, person_properties: nil, group_properties: nil)
11
+ @only_evaluate_locally = only_evaluate_locally
12
+ @person_properties = person_properties || {}
13
+ @group_properties = group_properties || {}
14
+ end
15
+
16
+ def to_h
17
+ {
18
+ only_evaluate_locally: @only_evaluate_locally,
19
+ person_properties: @person_properties,
20
+ group_properties: @group_properties
21
+ }
22
+ end
23
+
24
+ def self.from_hash(hash)
25
+ return nil unless hash.is_a?(Hash)
26
+
27
+ new(
28
+ only_evaluate_locally: PostHog::Utils.get_by_symbol_or_string_key(hash, :only_evaluate_locally),
29
+ person_properties: PostHog::Utils.get_by_symbol_or_string_key(hash, :person_properties),
30
+ group_properties: PostHog::Utils.get_by_symbol_or_string_key(hash, :group_properties)
31
+ )
32
+ end
33
+ end
34
+ end
data/lib/posthog/utils.rb CHANGED
@@ -112,6 +112,24 @@ module PostHog
112
112
  false
113
113
  end
114
114
 
115
+ # public: Get value from hash by symbol key first, then string key
116
+ # Handles falsy values correctly (unlike ||)
117
+ #
118
+ # hash - Hash to lookup value in
119
+ # key - Symbol or String key to lookup
120
+ #
121
+ # Returns the value if found, nil otherwise
122
+ def get_by_symbol_or_string_key(hash, key)
123
+ symbol_key = key.to_sym
124
+ string_key = key.to_s
125
+
126
+ if hash.key?(symbol_key)
127
+ hash[symbol_key]
128
+ else
129
+ hash[string_key]
130
+ end
131
+ end
132
+
115
133
  class SizeLimitedHash < Hash
116
134
  def initialize(max_length, ...)
117
135
  super(...)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.0.1'
4
+ VERSION = '3.1.0'
5
5
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthog-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2025-07-24 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: concurrent-ruby
@@ -44,6 +45,7 @@ files:
44
45
  - lib/posthog/message_batch.rb
45
46
  - lib/posthog/noop_worker.rb
46
47
  - lib/posthog/response.rb
48
+ - lib/posthog/send_feature_flags_options.rb
47
49
  - lib/posthog/send_worker.rb
48
50
  - lib/posthog/transport.rb
49
51
  - lib/posthog/utils.rb
@@ -53,6 +55,7 @@ licenses:
53
55
  - MIT
54
56
  metadata:
55
57
  rubygems_mfa_required: 'true'
58
+ post_install_message:
56
59
  rdoc_options: []
57
60
  require_paths:
58
61
  - lib
@@ -67,7 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
70
  - !ruby/object:Gem::Version
68
71
  version: '0'
69
72
  requirements: []
70
- rubygems_version: 3.6.9
73
+ rubygems_version: 3.5.10
74
+ signing_key:
71
75
  specification_version: 4
72
76
  summary: PostHog library
73
77
  test_files: []