shopcircle-orbit 1.2.0 → 1.3.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/README.md +17 -3
- data/lib/shopcircle/orbit/rails/middleware.rb +8 -3
- data/lib/shopcircle/orbit/transport.rb +4 -5
- data/lib/shopcircle/orbit/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: d9d216746a4630244fb0e572da6096aa4e0755e8dd51149b633d6f052b3e4b1c
|
|
4
|
+
data.tar.gz: d81da736f6c0964d9b30ee64d35c1408577686bb01ca2c0226f4f26ff6d99503
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 927f107a154501f0db7616e3bdda426826e808142240ff42c344b4f0d574259d8c05d8b21f935c48d610b8dc475b2c97617620e0164eeee0930411132ae62ff4
|
|
7
|
+
data.tar.gz: cab6c08b1f6f39018c9139f4517e6630036c61d595a8a1c08a97fedace37e28d072c4601744a69da3ca4c4d90197eb25dc017cdd377e836f7ec0591c7b7d21a7
|
data/README.md
CHANGED
|
@@ -162,11 +162,25 @@ class OrderTest < ActiveSupport::TestCase
|
|
|
162
162
|
end
|
|
163
163
|
```
|
|
164
164
|
|
|
165
|
-
##
|
|
165
|
+
## Page / screen views
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
Page views are the `screen_view` event — that's what the dashboard counts under Pages, pageviews and bounce rate. There are three ways to capture them:
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
1. **Auto (Rails middleware).** The SDK automatically inserts Rack middleware that tracks `screen_view` for full HTML GET requests (server-rendered navigations). Asset paths, XHR/AJAX and JSON requests are excluded.
|
|
170
|
+
|
|
171
|
+
2. **AJAX / Turbo / Hotwire / SPA frontends.** These route changes happen in the browser and never reach Rails, so the middleware can't see them. Track those with the browser JS SDK — it hooks the History API and emits `screen_view` on every route change:
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
new ShopCircleOrbit({ clientId: "YOUR_CLIENT_ID", trackScreenViews: true })
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
3. **Manual (server-side).** To record a screen view yourself (a rendered view, a non-GET flow, or a path the middleware skips), emit the canonical event:
|
|
178
|
+
|
|
179
|
+
```ruby
|
|
180
|
+
ShopCircle::Orbit.track("screen_view", path: "/pricing")
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
To disable the auto middleware:
|
|
170
184
|
|
|
171
185
|
```ruby
|
|
172
186
|
# config/application.rb
|
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
module ShopCircle
|
|
4
4
|
module Orbit
|
|
5
5
|
module Rails
|
|
6
|
-
# Rack middleware that auto-tracks
|
|
7
|
-
# Skips assets, XHR, and non-GET
|
|
6
|
+
# Rack middleware that auto-tracks screen_view events for full HTML page
|
|
7
|
+
# requests (server-rendered navigations). Skips assets, XHR/AJAX, and non-GET
|
|
8
|
+
# requests — client-side SPA/AJAX/Turbo route changes are not visible to the
|
|
9
|
+
# server, so track those with the browser JS SDK (trackScreenViews) instead.
|
|
10
|
+
#
|
|
11
|
+
# Emits "screen_view" (the platform's canonical page/screen-view event) so it
|
|
12
|
+
# is counted in Pages, pageviews, bounce rate and journeys.
|
|
8
13
|
#
|
|
9
14
|
# Opt out by removing from the middleware stack:
|
|
10
15
|
#
|
|
@@ -33,7 +38,7 @@ module ShopCircle
|
|
|
33
38
|
props[:ip] = request.ip
|
|
34
39
|
props[:referrer] = request.referrer
|
|
35
40
|
end
|
|
36
|
-
ShopCircle::Orbit.track("
|
|
41
|
+
ShopCircle::Orbit.track("screen_view", props)
|
|
37
42
|
end
|
|
38
43
|
rescue StandardError => e
|
|
39
44
|
ShopCircle::Orbit.configuration.resolved_logger.warn("[shopcircle-orbit] Tracking error: #{e.message}")
|
|
@@ -78,11 +78,10 @@ module ShopCircle
|
|
|
78
78
|
request["shopcircle-client-secret"] = @config.client_secret
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
#
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
end
|
|
81
|
+
# Always attach an ingest token — required for public clients,
|
|
82
|
+
# accepted by secret-authenticated clients too.
|
|
83
|
+
token = fetch_ingest_token
|
|
84
|
+
request["shopcircle-ingest-token"] = token if token
|
|
86
85
|
|
|
87
86
|
request.body = body
|
|
88
87
|
|