@guardian/commercial-core 5.4.1 → 5.4.2
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.
- package/dist/cjs/event-timer.d.ts +0 -1
- package/dist/cjs/event-timer.js +1 -3
- package/dist/cjs/send-commercial-metrics.d.ts +0 -1
- package/dist/cjs/send-commercial-metrics.js +18 -1
- package/dist/esm/event-timer.d.ts +0 -1
- package/dist/esm/event-timer.js +1 -3
- package/dist/esm/send-commercial-metrics.d.ts +0 -1
- package/dist/esm/send-commercial-metrics.js +18 -1
- package/package.json +1 -1
package/dist/cjs/event-timer.js
CHANGED
|
@@ -93,9 +93,7 @@ class EventTimer {
|
|
|
93
93
|
},
|
|
94
94
|
],
|
|
95
95
|
};
|
|
96
|
-
this.properties = {
|
|
97
|
-
offlineCount: window.guardian.offlineCount,
|
|
98
|
-
};
|
|
96
|
+
this.properties = {};
|
|
99
97
|
if (window.navigator.connection) {
|
|
100
98
|
this.properties.type = window.navigator.connection.type;
|
|
101
99
|
this.properties.downlink = window.navigator.connection.downlink;
|
|
@@ -55,6 +55,23 @@ function sendMetrics() {
|
|
|
55
55
|
(0, libs_1.log)('commercial', 'About to send commercial metrics', commercialMetricsPayload);
|
|
56
56
|
return navigator.sendBeacon(endpoint, JSON.stringify(commercialMetricsPayload));
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Gather how many times the user has experienced the “offline” event
|
|
60
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/offline_event
|
|
61
|
+
*
|
|
62
|
+
* This value should be fetched as late as possible in the page lifecycle,
|
|
63
|
+
* to get an accurate value.
|
|
64
|
+
*
|
|
65
|
+
* Relevant for an @guardian/open-journalism investigation.
|
|
66
|
+
*/
|
|
67
|
+
const getOfflineCount = () => window.guardian.offlineCount
|
|
68
|
+
? [
|
|
69
|
+
{
|
|
70
|
+
name: 'offlineCount',
|
|
71
|
+
value: window.guardian.offlineCount,
|
|
72
|
+
},
|
|
73
|
+
]
|
|
74
|
+
: [];
|
|
58
75
|
function gatherMetricsOnPageUnload() {
|
|
59
76
|
// Assemble commercial properties and metrics
|
|
60
77
|
const eventTimer = event_timer_1.EventTimer.get();
|
|
@@ -65,7 +82,7 @@ function gatherMetricsOnPageUnload() {
|
|
|
65
82
|
.concat(devProperties)
|
|
66
83
|
.concat(adBlockerProperties);
|
|
67
84
|
commercialMetricsPayload.properties = properties;
|
|
68
|
-
const metrics = roundTimeStamp(eventTimer.events);
|
|
85
|
+
const metrics = roundTimeStamp(eventTimer.events).concat(getOfflineCount());
|
|
69
86
|
commercialMetricsPayload.metrics = metrics;
|
|
70
87
|
sendMetrics();
|
|
71
88
|
}
|
package/dist/esm/event-timer.js
CHANGED
|
@@ -90,9 +90,7 @@ class EventTimer {
|
|
|
90
90
|
},
|
|
91
91
|
],
|
|
92
92
|
};
|
|
93
|
-
this.properties = {
|
|
94
|
-
offlineCount: window.guardian.offlineCount,
|
|
95
|
-
};
|
|
93
|
+
this.properties = {};
|
|
96
94
|
if (window.navigator.connection) {
|
|
97
95
|
this.properties.type = window.navigator.connection.type;
|
|
98
96
|
this.properties.downlink = window.navigator.connection.downlink;
|
|
@@ -52,6 +52,23 @@ function sendMetrics() {
|
|
|
52
52
|
log('commercial', 'About to send commercial metrics', commercialMetricsPayload);
|
|
53
53
|
return navigator.sendBeacon(endpoint, JSON.stringify(commercialMetricsPayload));
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Gather how many times the user has experienced the “offline” event
|
|
57
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/offline_event
|
|
58
|
+
*
|
|
59
|
+
* This value should be fetched as late as possible in the page lifecycle,
|
|
60
|
+
* to get an accurate value.
|
|
61
|
+
*
|
|
62
|
+
* Relevant for an @guardian/open-journalism investigation.
|
|
63
|
+
*/
|
|
64
|
+
const getOfflineCount = () => window.guardian.offlineCount
|
|
65
|
+
? [
|
|
66
|
+
{
|
|
67
|
+
name: 'offlineCount',
|
|
68
|
+
value: window.guardian.offlineCount,
|
|
69
|
+
},
|
|
70
|
+
]
|
|
71
|
+
: [];
|
|
55
72
|
function gatherMetricsOnPageUnload() {
|
|
56
73
|
// Assemble commercial properties and metrics
|
|
57
74
|
const eventTimer = EventTimer.get();
|
|
@@ -62,7 +79,7 @@ function gatherMetricsOnPageUnload() {
|
|
|
62
79
|
.concat(devProperties)
|
|
63
80
|
.concat(adBlockerProperties);
|
|
64
81
|
commercialMetricsPayload.properties = properties;
|
|
65
|
-
const metrics = roundTimeStamp(eventTimer.events);
|
|
82
|
+
const metrics = roundTimeStamp(eventTimer.events).concat(getOfflineCount());
|
|
66
83
|
commercialMetricsPayload.metrics = metrics;
|
|
67
84
|
sendMetrics();
|
|
68
85
|
}
|