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 +4 -4
- data/lib/posthog/client.rb +30 -0
- data/lib/posthog/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 952a3d08e42e35c4006614c4ea33cb0fb7216c250f2eade20bb6c37d12fb5b13
|
4
|
+
data.tar.gz: 9f4773ec646c3e7e4f5183d818245d0dab1f275ec5f01de1ddcc073483499fbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3b66458d3987de0296702f9ef32a3ec90485fb263a986ff7e703ee6ca5113be320acb28fa07b48231401898e630c24f2c11067e6a01aa5bc7860ce494b15a40
|
7
|
+
data.tar.gz: 92d1b482dbe35e57c30cbc0160a6be1f1589cb63a8871eaaefdde8c64aa49d8d1d280a05d6ecd4f55fb1a850e62f73c756878081d53b6bede4b21c9859cfd006
|
data/lib/posthog/client.rb
CHANGED
@@ -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
|
|
data/lib/posthog/version.rb
CHANGED