reputable 0.1.15 → 0.1.16

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: 46a14f8686b7e3ad1aa8a8c2e22f5c14f13a3d6667ad9bb4ca1e088024989f7d
4
- data.tar.gz: 6b6e95c46a329214b02279c23d02b55067f8a86f74cc6f17159b35dd43d08ef6
3
+ metadata.gz: d33fb1c68fdaca4082540ed61021d61ec5d687779c6c290635327dfe58a83ec7
4
+ data.tar.gz: 8a217cc36dcc8eef21623025b2dca9b0ccd697b1a312fd46bcfa814c7958e189
5
5
  SHA512:
6
- metadata.gz: 542429b9c9716d69889873b9212b4500669a074c24595f8f933f64568161ca6a562de7b6aa307ede64252b35599d5e768279abee078724d358ab2a2bc14f6f90
7
- data.tar.gz: e3978a1b8e21332bd1a7e1ef26a719398c478762f74a5959bdc8c85c720de7fe97a03b4c525df7c892273329f8c1d02c1fe38163fcdee21d92479dfc81b735a2
6
+ metadata.gz: d9470847736221d9aa4b0c0012487f18b32ed15bba2f22d5e85bbcd3f376263aa66899b8e14eda2058b0aa0e52e1c659845a516dee09709f379d9ef660cd2ed4
7
+ data.tar.gz: 879cc235f75b50f054db621572dbd2dfb58020102bc784d14fed109b921bfa82a4f91f0fe4fff7c7c3f2811ff0f292d5638ab2864323bcf93ddbcd18ecf18a3c
data/README.md CHANGED
@@ -301,6 +301,33 @@ Notes:
301
301
  - Use `blocked_page_path` only for local blocked pages (or to build a custom `failure_url`).
302
302
  - Override `challenge_redirect_status` (default `302`) or `verification_force_challenge` if needed.
303
303
 
304
+ ### Server/JS Request Reconciliation
305
+
306
+ When using both server-side tracking (Rack middleware) and client-side JavaScript tracking, requests can be double-counted. The reconciliation system prevents this by correlating requests using a unique `request_id`.
307
+
308
+ **Automatic Request ID**: The middleware automatically generates a UUID for each request and stores it in `env['reputable.request_id']`. This ID is included when pushing to the Redis buffer.
309
+
310
+ **Exposing to JavaScript**: To enable reconciliation, expose the request_id in your views:
311
+
312
+ ```erb
313
+ <%# In your layout (app/views/layouts/application.html.erb) %>
314
+ <meta name="reputable-request-id" content="<%= request.env['reputable.request_id'] %>">
315
+
316
+ <%# Or via JavaScript variable %>
317
+ <script>
318
+ window.reputableConfig = {
319
+ requestId: '<%= request.env['reputable.request_id'] %>'
320
+ };
321
+ </script>
322
+ ```
323
+
324
+ The JavaScript snippet will automatically read the request_id from:
325
+ 1. `data-reputable-request-id` attribute on the script tag
326
+ 2. `window.reputableConfig.requestId`
327
+ 3. `<meta name="reputable-request-id">` tag
328
+
329
+ **Bot Detection Signal**: If the middleware tracks a request but JavaScript never fires (after a 10-second grace period), the request is flagged with `risk:no_js`. This is a strong bot signal—bots and crawlers typically don't render JavaScript.
330
+
304
331
  ### Default Skipped Paths
305
332
 
306
333
  The middleware automatically skips:
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "blocked_page"
4
+ require "securerandom"
4
5
 
5
6
  module Reputable
6
7
  # Rack middleware for automatic request tracking
@@ -61,6 +62,10 @@ module Reputable
61
62
  end
62
63
 
63
64
  def call(env)
65
+ # Generate a unique request ID for reconciliation with JS tracking
66
+ # This ID is exposed to views so it can be included in the JS snippet
67
+ env['reputable.request_id'] = SecureRandom.uuid
68
+
64
69
  # Check for verification return parameters and verify signature if present
65
70
  handle_verification_return(env)
66
71
 
@@ -390,7 +395,8 @@ module Reputable
390
395
  method: request.request_method,
391
396
  user_agent: env["HTTP_USER_AGENT"],
392
397
  referer: env["HTTP_REFERER"],
393
- tags: build_tags(env)
398
+ tags: build_tags(env),
399
+ request_id: env["reputable.request_id"]
394
400
  }.compact
395
401
  rescue StandardError => e
396
402
  Reputable.logger&.debug("Reputable build_params: #{e.class} - #{e.message}")
@@ -24,6 +24,7 @@ module Reputable
24
24
  # @option options [String] :country Country code (ISO 3166-1 alpha-2)
25
25
  # @option options [Array<String>] :tags Custom classification tags
26
26
  # @option options [Hash] :metadata Additional metadata
27
+ # @option options [String] :request_id Unique request ID for reconciliation with JS tracking
27
28
  # @return [Boolean] true if successfully pushed to buffer, false otherwise
28
29
  #
29
30
  # @example Basic usage
@@ -32,7 +33,7 @@ module Reputable
32
33
  # path: "/products/123"
33
34
  # )
34
35
  #
35
- # @example Full usage
36
+ # @example Full usage with request_id for JS reconciliation
36
37
  # Reputable::Tracker.track_request(
37
38
  # ip: request.ip,
38
39
  # path: request.path,
@@ -40,6 +41,7 @@ module Reputable
40
41
  # method: request.request_method,
41
42
  # user_agent: request.user_agent,
42
43
  # referer: request.referer,
44
+ # request_id: env['reputable.request_id'],
43
45
  # tags: ["view:page:product", "trust:channel:organic"]
44
46
  # )
45
47
  def track_request(ip:, path:, **options)
@@ -80,7 +82,8 @@ module Reputable
80
82
  referer: options[:referer],
81
83
  country: options[:country],
82
84
  tags: options[:tags] || [],
83
- metadata: options[:metadata]
85
+ metadata: options[:metadata],
86
+ request_id: options[:request_id]
84
87
  }.compact
85
88
  end
86
89
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Reputable
4
- VERSION = "0.1.15"
4
+ VERSION = "0.1.16"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reputable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reputable
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-01-28 00:00:00.000000000 Z
11
+ date: 2026-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis