posthog-ruby 3.32.1 → 3.33.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/emails.rb +36 -8
- data/lib/posthog/feature_flags.rb +26 -2
- 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: 8da64dae9d5b02bfb1ad78f4557e4b9bfcba9c5e629dec50f71bb451968029e8
|
|
4
|
+
data.tar.gz: bcbd76ebc1e9f82e7cadd467be7793ab84255e0c67f8cbdfec1582fd1e9a1a48
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b8c19b770ee14ddc7b7dfabbce0fd50b1cfa421f544ab02ab0418a75673ded97a4f84b41eaf25be1b0dc31a0b1d8d6f87d49a9bb83d600dc1398cbdbe09c04ca
|
|
7
|
+
data.tar.gz: 070fad978093afa5ebbe163f2f56538f99812bfc90335e30f76c609ee521b9d521b34f0a387c70bad0ef51f8bdbe2ffc12ae38da96a08ffa827b0d28380e54ed
|
data/lib/posthog/emails.rb
CHANGED
|
@@ -94,7 +94,7 @@ module PostHog
|
|
|
94
94
|
"project's engagement setting."
|
|
95
95
|
CODE_FORM_WHY = 'A send with template_key takes its content from your code.'
|
|
96
96
|
TEMPLATE_FIELDS = %i[template_data].freeze
|
|
97
|
-
CODE_FIELDS = %i[subject html text from reply_to capture_engagement].freeze
|
|
97
|
+
CODE_FIELDS = %i[subject html text from reply_to sensitive tracking capture_engagement].freeze
|
|
98
98
|
NETWORK_ERRORS = [
|
|
99
99
|
Timeout::Error, SocketError, SystemCallError, IOError, EOFError, OpenSSL::SSL::SSLError,
|
|
100
100
|
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Zlib::Error
|
|
@@ -140,8 +140,22 @@ module PostHog
|
|
|
140
140
|
# @param from [String] Code form: a verified sender, such as `Acme <hello@example.com>`. Without it, the
|
|
141
141
|
# project's default sender.
|
|
142
142
|
# @param reply_to [String, Array<String>] Code form: one address or a list of addresses.
|
|
143
|
-
# @param
|
|
144
|
-
#
|
|
143
|
+
# @param sensitive [Boolean] Code form: +true+ when the email carries login links, reset tokens or codes. A
|
|
144
|
+
# sensitive email keeps its links unchanged unless +tracking+ turns clicks on, leaves its subject off engagement
|
|
145
|
+
# events, and keeps its content out of logs. Left out, the email takes the setting of the template made in
|
|
146
|
+
# PostHog whose key matches +template_key+, and is sensitive when no template matches. Sent only when you set
|
|
147
|
+
# it, and needs a PostHog version that takes it.
|
|
148
|
+
# @param tracking [Boolean, Hash] Code form: what PostHog tracks for the email. Left out, PostHog counts opens and
|
|
149
|
+
# captures engagement events, and tracks clicks only when the email isn't sensitive. +true+ turns on opens,
|
|
150
|
+
# clicks and engagement events, even for a sensitive email. +false+ turns them all off: the email has no open
|
|
151
|
+
# pixel and no rewritten links, and PostHog captures no engagement events for it. A Hash such as
|
|
152
|
+
# +{ clicks: true }+ sets +:opens+ (default +true+), +:clicks+ (default: on unless the email is sensitive) and
|
|
153
|
+
# +:engagement+ (default +true+) one by one. Turn clicks on for a sensitive email only when its links are safe to
|
|
154
|
+
# rewrite. Click tracking needs open tracking. A project whose admin turned engagement capture off captures
|
|
155
|
+
# nothing, whatever the send says. Sent only when you set it, and needs a PostHog version that takes it.
|
|
156
|
+
# @param capture_engagement [Boolean] Deprecated: use +tracking: { engagement: false }+ instead. Code form:
|
|
157
|
+
# whether PostHog captures the email's engagement events. It still works, but a send can't set both. Sent
|
|
158
|
+
# only when you set it.
|
|
145
159
|
# @param distinct_id [String] The recipient's distinct ID in your product. The email's events go to this
|
|
146
160
|
# person. Without it, they go to a person whose distinct ID is the email address.
|
|
147
161
|
# @param idempotency_key [String] 1 to 255 visible ASCII characters. A send with a key PostHog has already
|
|
@@ -155,11 +169,12 @@ module PostHog
|
|
|
155
169
|
# @raise [ArgumentError] An argument has the wrong type or format, or the call mixes the two forms.
|
|
156
170
|
def send(
|
|
157
171
|
to:, template_id: nil, template_data: nil, template_key: nil, subject: nil, html: nil, text: nil, from: nil,
|
|
158
|
-
reply_to: nil,
|
|
172
|
+
reply_to: nil, sensitive: nil, tracking: nil, capture_engagement: nil, distinct_id: nil, idempotency_key: nil,
|
|
173
|
+
max_retries: nil
|
|
159
174
|
)
|
|
160
175
|
fields = {
|
|
161
176
|
template_data: template_data, subject: subject, html: html, text: text, from: from, reply_to: reply_to,
|
|
162
|
-
capture_engagement: capture_engagement
|
|
177
|
+
sensitive: sensitive, tracking: tracking, capture_engagement: capture_engagement
|
|
163
178
|
}.compact
|
|
164
179
|
check_recipient(to, distinct_id, idempotency_key, max_retries)
|
|
165
180
|
payload = content(template_id, template_key, fields).merge(to: to)
|
|
@@ -305,16 +320,29 @@ module PostHog
|
|
|
305
320
|
%i[html text from].each do |name|
|
|
306
321
|
raise ArgumentError, "#{name} must be a string." if fields.key?(name) && !fields[name].is_a?(String)
|
|
307
322
|
end
|
|
308
|
-
|
|
309
|
-
raise ArgumentError,
|
|
323
|
+
%i[capture_engagement sensitive].each do |name|
|
|
324
|
+
raise ArgumentError, "#{name} must be true or false." unless [nil, true, false].include?(fields[name])
|
|
310
325
|
end
|
|
311
326
|
|
|
312
327
|
code = fields.slice(:subject, :html, :text, :from).merge(template_key: template_key)
|
|
313
328
|
code[:reply_to] = addresses(fields[:reply_to]) if fields.key?(:reply_to)
|
|
314
|
-
code[:capture_engagement] = fields.
|
|
329
|
+
code[:capture_engagement] = fields[:capture_engagement] if fields.key?(:capture_engagement)
|
|
330
|
+
code[:sensitive] = fields[:sensitive] if fields.key?(:sensitive)
|
|
331
|
+
code[:tracking] = tracking(fields[:tracking]) if fields.key?(:tracking)
|
|
315
332
|
code
|
|
316
333
|
end
|
|
317
334
|
|
|
335
|
+
def tracking(value)
|
|
336
|
+
return value if [true, false].include?(value)
|
|
337
|
+
raise ArgumentError, 'tracking must be true, false or a Hash such as { clicks: true }.' unless value.is_a?(Hash)
|
|
338
|
+
|
|
339
|
+
kinds = value.compact
|
|
340
|
+
kinds.each do |kind, on|
|
|
341
|
+
raise ArgumentError, "tracking[#{kind.inspect}] must be true or false." unless [true, false].include?(on)
|
|
342
|
+
end
|
|
343
|
+
kinds
|
|
344
|
+
end
|
|
345
|
+
|
|
318
346
|
def refuse_fields(fields, allowed:, form:, other_form:, why:)
|
|
319
347
|
field = fields.keys.find { |name| !allowed.include?(name) }
|
|
320
348
|
return if field.nil?
|
|
@@ -548,9 +548,9 @@ module PostHog
|
|
|
548
548
|
when 'w'
|
|
549
549
|
parsed_dt = parsed_dt.prev_day(number * 7)
|
|
550
550
|
when 'm'
|
|
551
|
-
parsed_dt = parsed_dt
|
|
551
|
+
parsed_dt = subtract_months(parsed_dt, number)
|
|
552
552
|
when 'y'
|
|
553
|
-
parsed_dt = parsed_dt
|
|
553
|
+
parsed_dt = subtract_years(parsed_dt, number)
|
|
554
554
|
else
|
|
555
555
|
return nil
|
|
556
556
|
end
|
|
@@ -558,6 +558,30 @@ module PostHog
|
|
|
558
558
|
parsed_dt
|
|
559
559
|
end
|
|
560
560
|
|
|
561
|
+
# Steps back one month at a time and clamps the day after every step, as the
|
|
562
|
+
# SDK spec requires: March 31 minus two months is January 28. A single
|
|
563
|
+
# prev_month(2) clamps once and lands on January 31.
|
|
564
|
+
def self.subtract_months(date_time, months)
|
|
565
|
+
steps = 0
|
|
566
|
+
# Every month has at least 28 days, so once the day is 28 or less no step
|
|
567
|
+
# can clamp it again and the rest can be done in one jump.
|
|
568
|
+
while steps < months && date_time.day > 28
|
|
569
|
+
date_time = date_time.prev_month
|
|
570
|
+
steps += 1
|
|
571
|
+
end
|
|
572
|
+
date_time.prev_month(months - steps)
|
|
573
|
+
end
|
|
574
|
+
private_class_method :subtract_months
|
|
575
|
+
|
|
576
|
+
# Years work the same way. Only February 29 can clamp, and only on the first
|
|
577
|
+
# step, so one step followed by a single jump matches stepping every year.
|
|
578
|
+
def self.subtract_years(date_time, years)
|
|
579
|
+
return date_time if years.zero?
|
|
580
|
+
|
|
581
|
+
date_time.prev_year.prev_year(years - 1)
|
|
582
|
+
end
|
|
583
|
+
private_class_method :subtract_years
|
|
584
|
+
|
|
561
585
|
# Parse a single semver numeric identifier, rejecting empty, non-digit, or
|
|
562
586
|
# leading-zero values per semver 2.0.0 §2. `reason` names the owner of the value:
|
|
563
587
|
# UNSUPPORTED_DEFINITION for a filter value, MISSING_CONTEXT for a value the call passed.
|
data/lib/posthog/version.rb
CHANGED