posthog-ruby 2.10.0 → 2.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: d987590608ff1c705f8f419d43cb6ef439233f8b3dbc5e3ac84bd64b3d552d9a
4
- data.tar.gz: d4ae4f458a8a9faa654519b958cc20f828638ead4696dbc8a8c03ed198e44606
3
+ metadata.gz: 952a3d08e42e35c4006614c4ea33cb0fb7216c250f2eade20bb6c37d12fb5b13
4
+ data.tar.gz: 9f4773ec646c3e7e4f5183d818245d0dab1f275ec5f01de1ddcc073483499fbb
5
5
  SHA512:
6
- metadata.gz: a9671f5f0fb37ae15a605b1118f09a526fa383aa129335a78a85f8b54c772e8c28ade9e3fd06bf36e142f7a994eca33400965add6c1e2ceebf3b8fcc32d8df23
7
- data.tar.gz: 5fd8756e6c1f20bb0df3c40e8e72aa9c9d79dedd2bedb0c53930254d8a58417b75c38867f9e2e673bd0a53968cb7beded76cc6be18760d3fe8755d33cc75cd1b
6
+ metadata.gz: f3b66458d3987de0296702f9ef32a3ec90485fb263a986ff7e703ee6ca5113be320acb28fa07b48231401898e630c24f2c11067e6a01aa5bc7860ce494b15a40
7
+ data.tar.gz: 92d1b482dbe35e57c30cbc0160a6be1f1589cb63a8871eaaefdde8c64aa49d8d1d280a05d6ecd4f55fb1a850e62f73c756878081d53b6bede4b21c9859cfd006
@@ -26,6 +26,8 @@ class PostHog
26
26
  # Measured in seconds, defaults to 30.
27
27
  # @option opts [Integer] :feature_flag_request_timeout_seconds How long to wait for feature flag evaluation.
28
28
  # Measured in seconds, defaults to 3.
29
+ # @option opts [Proc] :before_send A block that receives the event hash and should return either a modified hash
30
+ # to be sent to PostHog or nil to prevent the event from being sent. e.g. `before_send: ->(event) { event }`
29
31
  def initialize(opts = {})
30
32
  symbolize_keys!(opts)
31
33
 
@@ -59,6 +61,8 @@ class PostHog
59
61
  @distinct_id_has_sent_flag_calls = SizeLimitedHash.new(Defaults::MAX_HASH_SIZE) do |hash, key|
60
62
  hash[key] = []
61
63
  end
64
+
65
+ @before_send = opts[:before_send]
62
66
  end
63
67
 
64
68
  # Synchronously waits until the worker has cleared the queue.
@@ -342,10 +346,36 @@ class PostHog
342
346
 
343
347
  private
344
348
 
349
+ # before_send should run immediately before the event is sent to the queue.
350
+ # @param [Object] action The event to be sent to PostHog
351
+ # @return [null, Object, nil] The processed event or nil if the event should not be sent
352
+ def process_before_send(action)
353
+ return action if action.nil? || action.empty?
354
+ return action unless @before_send
355
+
356
+ begin
357
+ processed_action = @before_send.call(action)
358
+
359
+ if processed_action.nil?
360
+ logger.warn("Event #{action[:event]} was rejected in beforeSend function")
361
+ elsif processed_action.empty?
362
+ logger.warn("Event #{action[:event]} has no properties after beforeSend function, this is likely an error")
363
+ end
364
+
365
+ processed_action
366
+ rescue StandardError => e
367
+ logger.error("Error in beforeSend function - using original event: #{e.message}")
368
+ action
369
+ end
370
+ end
371
+
345
372
  # private: Enqueues the action.
346
373
  #
347
374
  # returns Boolean of whether the item was added to the queue.
348
375
  def enqueue(action)
376
+ action = process_before_send(action)
377
+ return false if action.nil? || action.empty?
378
+
349
379
  # add our request id for tracing purposes
350
380
  action[:messageId] ||= uid
351
381
 
@@ -1,3 +1,3 @@
1
1
  class PostHog
2
- VERSION = '2.10.0'.freeze
2
+ VERSION = '2.11.0'.freeze
3
3
  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: 2.10.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''