Skip to content

Commit 0627301

Browse files
committed
Add snippet version to the beacons
1 parent e7a5520 commit 0627301

File tree

8 files changed

+18
-2
lines changed

8 files changed

+18
-2
lines changed

rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const scriptOutput = (file, minified) => ({
2424
sourcemap: true,
2525
});
2626

27-
const snippetOutput = (file, target) => {
27+
const snippetOutput = (file, target = "es5") => {
2828
const versionString = `${pkg.config.snippetVersion}${target === "es5" ? "" : `-${target}`}`;
2929
const preamble = `/* SpeedCurve RUM Snippet v${versionString} */`;
3030

src/beacon.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export class Beacon {
204204
collectionDuration: now() - collectionStart,
205205
pageId: this.pageId,
206206
scriptVersion: VERSION,
207+
snippetVersion: this.config.snippetVersion,
207208
sessionId: this.sessionId,
208209
startTime: this.startTime,
209210
},
@@ -239,6 +240,9 @@ export type BeaconMetaData = {
239240
/** The lux.js version that sent the beacon */
240241
scriptVersion: string;
241242

243+
/** The lux.js snippet version that sent the beacon */
244+
snippetVersion?: string;
245+
242246
/** How long in milliseconds did this beacon capture page data for */
243247
measureDuration: number;
244248

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { LuxGlobal } from "./global";
12
import { ServerTimingConfig } from "./server-timing";
23
import { UrlPatternMapping } from "./url-matcher";
34

@@ -26,6 +27,7 @@ export interface ConfigObject {
2627
samplerate: number;
2728
sendBeaconOnPageHidden: boolean;
2829
serverTiming?: ServerTimingConfig;
30+
snippetVersion?: LuxGlobal["snippetVersion"];
2931
trackErrors: boolean;
3032
trackHiddenPages: boolean;
3133
}

src/global.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ export interface LuxGlobal extends UserConfig {
2727
/** Timestamp representing when the LUX snippet was evaluated */
2828
ns?: number;
2929
send: () => void;
30+
snippetVersion?: string;
3031
version?: string;
3132
}

src/lux.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,10 @@ LUX = (function () {
14351435
queryParams.push("fl=" + gFlags);
14361436
}
14371437

1438+
if (LUX.snippetVersion) {
1439+
queryParams.push("sv=" + LUX.snippetVersion);
1440+
}
1441+
14381442
const customDataValues = CustomData.valuesToString(customData);
14391443

14401444
if (customDataValues) {
@@ -2065,6 +2069,7 @@ LUX = (function () {
20652069

20662070
// Public properties
20672071
globalLux.version = VERSION;
2072+
globalLux.snippetVersion = LUX.snippetVersion;
20682073

20692074
/**
20702075
* Run a command from the command queue

src/snippet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ LUX.markLoadTime = () => LUX.cmd(["markLoadTime", msSinceNavigationStart()]);
2222
LUX.measure = _measure;
2323
LUX.on = (event, callback) => LUX.cmd(["on", event, callback]);
2424
LUX.send = () => LUX.cmd(["send"]);
25+
LUX.snippetVersion = __SNIPPET_VERSION;
2526
LUX.ns = scriptStartTime;
2627

2728
export default LUX;

src/version.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { version as pkgVersion, config as pkgConfig } from "../package.json";
12
import { padStart } from "./string";
23

3-
export const VERSION = "4.2.1";
4+
export const VERSION = pkgVersion;
5+
export const SNIPPET_VERSION = pkgConfig.snippetVersion;
46

57
/**
68
* Returns the version of the script as a float to be stored in legacy systems that do not support

src/window.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { LuxGlobal } from "./global";
22

33
declare global {
44
declare const __ENABLE_POLYFILLS: boolean;
5+
declare const __SNIPPET_VERSION: string;
56

67
// LUX globals
78
interface Window {

0 commit comments

Comments
 (0)