mbuzz 0.10.1 → 0.12.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: 71d8b00de3facb7fd1290c03f1493edf09586333ad6ea44e1de03ebba375805f
4
- data.tar.gz: 69eac0945b4b2630038753770fd398154cc1d407e15e9e8ff0d1770fb53bf95d
3
+ metadata.gz: fd98d9872cc6ec740c9b705e67f9a883e534fb5fa07dbc610b8829680bf8381d
4
+ data.tar.gz: 48c12c4a9a7ab7904aebe2f08249d06eef325b65fb99004556c8bcd262b909fb
5
5
  SHA512:
6
- metadata.gz: 5f0a99184a1860342c7088c1642495d11db115ecbd7571bfffd6f29ea8fc770d6d0ea3d473f1ae7a6681eadb19d8b387ce86968df369d5e785301a1f157b2ad3
7
- data.tar.gz: 3ba3d4419fa579e5840a46e398202637f4d7f5b119fbc2815b1cac5db1504f4d0f69a5d68481ad1075bb875d42e0121aa9f06696bf9cc9a254accb9c7a1a0aab
6
+ metadata.gz: e3bee0fa8f5bfc4daee2a9ffa3743d7d00d06818e2bc0b2ebbaa0e4de6c9011d23ba33f991292c11336c2094a2b1a6d75b9a8db5a4da7d02a76cc56d5a2477c6
7
+ data.tar.gz: 42e8200e96d6c1837f9fd2e177024452acd6cf3ffc35a346faabfd6f8fbdb04885c54272f84bc171ce7e97072bd14b11a17ff82ff1ec5a56b304382e050cba60
data/CHANGELOG.md CHANGED
@@ -5,6 +5,32 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [0.12.0] - 2026-11-16
11
+
12
+ ### Added
13
+
14
+ - **`api_url:` option for data-resident installs.** `init()` accepts it again (removed in 0.8.2 so a live install could not be redirected). Explicit opt-in: `https://` only; a region key (`sk_live_au_...`) must be paired with it and it with a region key, otherwise `init()` throws; there is no fallback host, so a failed request is dropped, never retried against `api.mbuzz.co`. Installs that do not set it behave exactly as before. `Mbuzz.init` now validates it; previously `config.api_url` was an unchecked accessor, which still exists but is not validated when assigned directly.
15
+
16
+ ## [0.11.0] - 2026-10-14
17
+
18
+ ### Added
19
+
20
+ - **Meta's `_fbp` is forwarded on the session call.** The SDK reads the `_fbp` cookie the customer's
21
+ Meta Pixel already set and sends it as `fbp` on the session payload, on both paths (the session
22
+ endpoint and the tracking middleware). Meta merges a server event with the browser Pixel's event on
23
+ `event_name` + `fbp` when the event IDs differ, so without it every server `Lead` counted as a
24
+ second one. Accepts Meta's `fb.<n>.<ts>.<random>` and the optional appendix its server-side
25
+ Parameter Builder adds (`...AQECAQIB`); anything else is dropped. Never written, never invented.
26
+ The key is omitted, not null, when the cookie is absent or malformed. No install change needed.
27
+
28
+ ### Fixed
29
+
30
+ - **A session call made outside Rack/Rails failed silently.** `SessionRequest` called
31
+ `Time#iso8601` without `require "time"`; Rack and Rails load it, a plain script did not, and the
32
+ `NoMethodError` was rescued to `false`.
33
+
8
34
  ## [0.10.1] - 2026-09-17
9
35
 
10
36
  ### Fixed — the visitor's IP now reaches mbuzz on session create
data/README.md CHANGED
@@ -240,7 +240,7 @@ is what preserves its full two-year life — a cookie written by `document.cooki
240
240
  ```ruby
241
241
  Mbuzz.init(
242
242
  api_key: "sk_live_...", # Required - from mbuzz.co dashboard
243
- api_url: "https://api.mbuzz.co/api/v1", # Optional - API endpoint
243
+ api_url: nil, # Optional - data-resident installs only: https host for a region key (sk_live_au_...); a region key requires it and vice versa
244
244
  debug: false # Optional - enable debug logging
245
245
  )
246
246
  ```
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Time#iso8601 lives here, not in core. Rack and Rails load it; a plain script
4
+ # did not, and the session call then failed silently (rescued to false).
5
+ require "time"
6
+
3
7
  module Mbuzz
4
8
  class Client
5
9
  class SessionRequest
@@ -13,7 +17,7 @@ module Mbuzz
13
17
  ACCEPTED_STATUS = "accepted"
14
18
 
15
19
  def initialize(visitor_id:, session_id:, url:, referrer: nil, device_fingerprint: nil,
16
- user_agent: nil, started_at: nil, ip: nil)
20
+ user_agent: nil, started_at: nil, ip: nil, fbp: nil)
17
21
  @visitor_id = visitor_id
18
22
  @session_id = session_id
19
23
  @url = url
@@ -22,6 +26,7 @@ module Mbuzz
22
26
  @user_agent = user_agent
23
27
  @started_at = started_at
24
28
  @ip = ip
29
+ @fbp = fbp
25
30
  end
26
31
 
27
32
  def call
@@ -35,7 +40,7 @@ module Mbuzz
35
40
  private
36
41
 
37
42
  attr_reader :visitor_id, :session_id, :url, :referrer, :device_fingerprint, :user_agent,
38
- :started_at, :ip
43
+ :started_at, :ip, :fbp
39
44
 
40
45
  def valid?
41
46
  present?(visitor_id) && present?(session_id) && present?(url)
@@ -59,6 +64,9 @@ module Mbuzz
59
64
  device_fingerprint: device_fingerprint,
60
65
  user_agent: user_agent,
61
66
  ip: ip,
67
+ # Meta's browser id, already format-checked by Mbuzz::Fbp. Dropped by
68
+ # .compact when absent: omitted, not null.
69
+ fbp: fbp,
62
70
  started_at: started_at || Time.now.utc.iso8601
63
71
  }.compact
64
72
  end
data/lib/mbuzz/client.rb CHANGED
@@ -33,7 +33,7 @@ module Mbuzz
33
33
  end
34
34
 
35
35
  def self.session(visitor_id:, session_id:, url:, referrer: nil, device_fingerprint: nil,
36
- user_agent: nil, started_at: nil, ip: nil)
36
+ user_agent: nil, started_at: nil, ip: nil, fbp: nil)
37
37
  SessionRequest.new(
38
38
  visitor_id: visitor_id,
39
39
  session_id: session_id,
@@ -42,7 +42,8 @@ module Mbuzz
42
42
  device_fingerprint: device_fingerprint,
43
43
  user_agent: user_agent,
44
44
  started_at: started_at,
45
- ip: ip
45
+ ip: ip,
46
+ fbp: fbp
46
47
  ).call
47
48
  end
48
49
  end
@@ -26,7 +26,7 @@ module Mbuzz
26
26
  ].freeze
27
27
 
28
28
  def initialize
29
- @api_url = "https://api.mbuzz.co/api/v1"
29
+ @api_url = DEFAULT_API_URL
30
30
  @enabled = true
31
31
  @debug = false
32
32
  @timeout = 5
@@ -36,6 +36,26 @@ module Mbuzz
36
36
  @skip_extensions = []
37
37
  end
38
38
 
39
+ DEFAULT_API_URL = "https://api.mbuzz.co/api/v1"
40
+ REGION_KEY = /\Ask_[a-z]+_[a-z]{2}_/
41
+
42
+ # api_url is an explicit opt-in for data-resident installs (spec M9). https
43
+ # only; no api_url means api.mbuzz.co, always; a region key (sk_live_au_...)
44
+ # must be paired with api_url and api_url with a region key; test keys are
45
+ # exempt from the pairing. There is no fallback host: a failed request is
46
+ # dropped, never retried against api.mbuzz.co.
47
+ def self.resolve_api_url(api_key, api_url)
48
+ has_url = !api_url.to_s.empty?
49
+ raise ConfigurationError, "api_url must start with https://" if has_url && !api_url.start_with?("https://")
50
+
51
+ unless api_key.to_s.start_with?("sk_test_") || has_url == REGION_KEY.match?(api_key.to_s)
52
+ raise ConfigurationError, "api_url and the API key region must be set together: " \
53
+ "a region key needs api_url, and api_url needs a region key"
54
+ end
55
+
56
+ (has_url ? api_url : DEFAULT_API_URL).chomp("/")
57
+ end
58
+
39
59
  def validate!
40
60
  raise ConfigurationError, "api_key is required" if api_key.nil? || api_key.empty?
41
61
  end
data/lib/mbuzz/fbp.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mbuzz
4
+ # Meta's browser id, written client-side by the customer's Meta Pixel. Read
5
+ # only, never set: forwarded on the session call so Meta can merge mbuzz's
6
+ # server event with the Pixel's browser event.
7
+ module Fbp
8
+ # Meta's documented shape, fb.<subdomainIndex>.<creationTime>.<random>, plus
9
+ # the optional appendix Meta's server-side Parameter Builder adds
10
+ # (fb.1.<ts>.<random>.AQECAQIB). Both are valid to Meta. \A…\z, not ^…$:
11
+ # `$` matches before a trailing newline.
12
+ FORMAT = /\Afb\.\d+\.\d+\.\d+(?:\.[A-Za-z0-9_-]+)?\z/
13
+
14
+ # The Pixel's _fbp, or nil when absent or not in Meta's format. mbuzz never
15
+ # invents one and never rewrites what it forwards.
16
+ def self.read(value)
17
+ value if value.is_a?(String) && FORMAT.match?(value)
18
+ end
19
+ end
20
+ end
@@ -67,6 +67,7 @@ module Mbuzz
67
67
  referrer: payload["referrer"],
68
68
  ip: ip,
69
69
  user_agent: user_agent,
70
+ fbp: Fbp.read(request.cookies[FBP_COOKIE_NAME]),
70
71
  device_fingerprint: Digest::SHA256.hexdigest("#{ip}|#{user_agent}")[0, 32]
71
72
  }.freeze
72
73
  end
@@ -94,7 +95,8 @@ module Mbuzz
94
95
  referrer: context[:referrer],
95
96
  device_fingerprint: context[:device_fingerprint],
96
97
  user_agent: context[:user_agent],
97
- ip: context[:ip]
98
+ ip: context[:ip],
99
+ fbp: context[:fbp]
98
100
  )
99
101
  rescue StandardError => e
100
102
  log_error("Session creation failed: #{e.message}") if Mbuzz.config.debug
@@ -102,6 +102,7 @@ module Mbuzz
102
102
  referrer: request.referer,
103
103
  ip: ip,
104
104
  user_agent: user_agent,
105
+ fbp: Fbp.read(request.cookies[FBP_COOKIE_NAME]),
105
106
  device_fingerprint: Digest::SHA256.hexdigest("#{ip}|#{user_agent}")[0, 32]
106
107
  }.freeze
107
108
  end
@@ -134,7 +135,8 @@ module Mbuzz
134
135
  referrer: context[:referrer],
135
136
  device_fingerprint: context[:device_fingerprint],
136
137
  user_agent: context[:user_agent],
137
- ip: context[:ip]
138
+ ip: context[:ip],
139
+ fbp: context[:fbp]
138
140
  )
139
141
  end
140
142
 
data/lib/mbuzz/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mbuzz
4
- VERSION = "0.10.1"
4
+ VERSION = "0.12.0"
5
5
  end
data/lib/mbuzz.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "mbuzz/version"
4
4
  require_relative "mbuzz/configuration"
5
5
  require_relative "mbuzz/dropped_call"
6
6
  require_relative "mbuzz/visitor/identifier"
7
+ require_relative "mbuzz/fbp"
7
8
  require_relative "mbuzz/request_context"
8
9
  require_relative "mbuzz/api"
9
10
  require_relative "mbuzz/client"
@@ -29,6 +30,9 @@ module Mbuzz
29
30
  VISITOR_COOKIE_PATH = "/"
30
31
  VISITOR_COOKIE_SAME_SITE = "Lax"
31
32
 
33
+ # Meta Pixel's browser id. Read only; see Mbuzz::Fbp.
34
+ FBP_COOKIE_NAME = "_fbp"
35
+
32
36
  # The one request a cached page always sends to the app. Kept off /api and
33
37
  # /assets so host-app routing and cache rules don't shadow it.
34
38
  SESSION_ENDPOINT_PATH = "/_mbuzz/session"
@@ -52,8 +56,11 @@ module Mbuzz
52
56
  # @param debug [Boolean, nil] Enable debug logging
53
57
  # @param skip_paths [Array<String>, nil] Additional paths to skip tracking (e.g., ["/admin", "/internal"])
54
58
  # @param skip_extensions [Array<String>, nil] Additional extensions to skip (e.g., [".pdf"])
55
- def self.init(api_key:, session_timeout: nil, debug: nil, skip_paths: nil, skip_extensions: nil)
56
- config.api_key = api_key
59
+ def self.init(api_key:, api_url: nil, session_timeout: nil, debug: nil, skip_paths: nil, skip_extensions: nil)
60
+ Configuration.resolve_api_url(api_key, api_url).then do |resolved_url|
61
+ config.api_key = api_key
62
+ config.api_url = resolved_url
63
+ end
57
64
  config.session_timeout = session_timeout if session_timeout
58
65
  config.debug = debug unless debug.nil?
59
66
  config.skip_paths = skip_paths if skip_paths
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mbuzz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mbuzz team
@@ -47,6 +47,7 @@ files:
47
47
  - lib/mbuzz/controller_helpers.rb
48
48
  - lib/mbuzz/current.rb
49
49
  - lib/mbuzz/dropped_call.rb
50
+ - lib/mbuzz/fbp.rb
50
51
  - lib/mbuzz/middleware/session_endpoint.rb
51
52
  - lib/mbuzz/middleware/tracking.rb
52
53
  - lib/mbuzz/railtie.rb