Skip to content

Commit 6da50a7

Browse files
authored
Merge pull request #14124 from bbc/missing-page-view-change
Move pageview tracking to OptimizelyProvider
2 parents 6aafde7 + 87f2597 commit 6da50a7

16 files changed

Lines changed: 469 additions & 354 deletions

File tree

src/app/components/OptimizelyPageMetrics/PageViewTracking/index.test.tsx

Lines changed: 0 additions & 119 deletions
This file was deleted.

src/app/components/OptimizelyPageMetrics/PageViewTracking/index.tsx

Lines changed: 0 additions & 114 deletions
This file was deleted.

src/app/components/OptimizelyPageMetrics/README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ The `OptimizelyPageMetric` component:
1919

2020
| Name | type | default | Description |
2121
| ----------------- | ------- | ------- | ----------------------------------- |
22-
| trackPageView | boolean | false | Enables tracking of page views. |
2322
| trackPageDepth | boolean | false | Enables tracking of scroll depth. |
2423
| trackPageComplete | boolean | false | Enables tracking of page completes. |
25-
| trackVisit | boolean | false | Enables tracking of visits. |
24+
25+
> Page view (`page-views`) and visit (`visit`) events are not controlled by this component. They are tracked from the Optimizely `DECISION` notification listener in [`withOptimizelyProvider`](../../legacy/containers/PageHandlers/withOptimizelyProvider/index.tsx). See [Page views per visit ratio metric](#page-views-per-visit-ratio-metric) below.
2626
2727
## experimentsForPageMetrics Array
2828

@@ -61,7 +61,7 @@ You can use once on a page
6161

6262
```tsx
6363
{
64-
<OptimizelyPageMetrics trackPageComplete trackPageView trackPageDepth />;
64+
<OptimizelyPageMetrics trackPageComplete trackPageDepth />;
6565
}
6666
```
6767

@@ -74,9 +74,9 @@ Or multiple times to invoke different page metrics in different sections of the
7474
<OptimizelyPageMetrics trackPageComplete />
7575
</main>;
7676
{
77-
/* Track page views & scroll depth outside the main section of the page */
77+
/* Track scroll depth outside the main section of the page */
7878
}
79-
<OptimizelyPageMetrics trackPageView trackPageDepth />;
79+
<OptimizelyPageMetrics trackPageDepth />;
8080
}
8181
```
8282

@@ -87,10 +87,8 @@ The page views per visit ratio metric is built from two Optimizely events:
8787
- numerator: `page-views`
8888
- denominator: `visit`
8989

90-
Visit counting is session based. A new visit is counted when there has been at least 30 minutes of inactivity since the last tracked page view. Each tracked page view updates the last activity timestamp so that continued browsing keeps the same visit.
91-
92-
When `trackPageView` and `trackVisit` are both enabled, the visit event is sent before the page view event on the same page load. This ensures the ratio metric counts the page view within Optimizely's 48 hour attribution window for the denominator.
90+
Both events are tracked from the `DECISION` notification listener in [`withOptimizelyProvider`](../../legacy/containers/PageHandlers/withOptimizelyProvider/index.tsx), not from this component. Tracking them from the listener ensures the visit (denominator) is always sent before the page view (numerator) on the same page load, so the page view falls inside Optimizely's 48 hour attribution window for the denominator. Tracking from the listener also guarantees the events fire for every activated experiment, independent of this component's render lifecycle.
9391

94-
For page views per visit, enable both `trackPageView` and `trackVisit`. Visit events are emitted from the page view tracker to preserve ordering and avoid duplicate visits.
92+
Events are de-duplicated per navigation: while the current URL (pathname + query string) is unchanged, multiple `DECISION` notifications will only emit `page-views` (and `visit`) once; navigating to a different URL and later returning may emit `page-views` again, and `visit` will only emit when the 30-minute inactivity window has elapsed.
9593

9694
For interpretation, add the numerator and denominator events as separate metrics alongside the ratio metric in Optimizely.

src/app/components/OptimizelyPageMetrics/experimentsForPageMetrics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ type ExperimentsForPageTypeMetrics = {
1111
const experimentsForPageMetrics: ExperimentsForPageTypeMetrics = [
1212
{
1313
pageType: ARTICLE_PAGE,
14-
activeExperiments: ['newswb_ws_topic_discovery_module'],
14+
activeExperiments: ['test_page_views_aa_3'],
1515
},
1616
{
1717
pageType: MEDIA_ARTICLE_PAGE,
18-
activeExperiments: ['newswb_ws_topic_discovery_module'],
18+
activeExperiments: ['test_page_views_aa_3'],
1919
},
2020
];
2121

0 commit comments

Comments
 (0)