From 8435adf44983757fd2b7a57660fdf8d4356917be Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Mon, 10 Oct 2022 12:43:54 +0200 Subject: [PATCH 01/20] support live signals and dispatch clarity live signals events --- packages/clarity-js/src/core/config.ts | 1 + packages/clarity-js/src/core/signals.ts | 18 ++++++++++++++++++ packages/clarity-js/src/data/upload.ts | 10 ++++++++-- packages/clarity-js/types/core.d.ts | 1 + packages/clarity-js/types/data.d.ts | 6 ++++++ 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 packages/clarity-js/src/core/signals.ts diff --git a/packages/clarity-js/src/core/config.ts b/packages/clarity-js/src/core/config.ts index 3b2b947b..e4578398 100644 --- a/packages/clarity-js/src/core/config.ts +++ b/packages/clarity-js/src/core/config.ts @@ -17,6 +17,7 @@ let config: Config = { fallback: null, upgrade: null, action: null + signals: false, }; export default config; diff --git a/packages/clarity-js/src/core/signals.ts b/packages/clarity-js/src/core/signals.ts new file mode 100644 index 00000000..ea26c013 --- /dev/null +++ b/packages/clarity-js/src/core/signals.ts @@ -0,0 +1,18 @@ +import { ClaritySignal } from "@clarity-types/data"; + +function parseSignals(signalsString: string): ClaritySignal[] { + const signalsJson: ClaritySignal[] = JSON.parse(signalsString) + return signalsJson; +} + +export function dispatchClarityLiveSignalsEvents(signalsString: string) { + try { + const signalsJson = parseSignals(signalsString); + signalsJson.forEach(signal => { + const customSignalEvent = new CustomEvent("clarityLiveSignal", {detail: signal}) + window.dispatchEvent(customSignalEvent) + }) + } catch { + //do nothing + } +} \ No newline at end of file diff --git a/packages/clarity-js/src/data/upload.ts b/packages/clarity-js/src/data/upload.ts index aea72eb5..4f7b7268 100644 --- a/packages/clarity-js/src/data/upload.ts +++ b/packages/clarity-js/src/data/upload.ts @@ -3,6 +3,7 @@ import { BooleanFlag, Check, Constant, EncodedPayload, Event, Metric, Setting, T import * as clarity from "@src/clarity"; import config from "@src/core/config"; import measure from "@src/core/measure"; +import { dispatchClarityLiveSignalsEvents } from "@src/core/signals"; import { time } from "@src/core/time"; import { clearTimeout, setTimeout } from "@src/core/timeout"; import compress from "@src/data/compress"; @@ -242,8 +243,9 @@ function delay(): number { } function response(payload: string): void { - let parts = payload && payload.length > 0 ? payload.split(" ") : [Constant.Empty]; - switch (parts[0]) { + const splittedPayload = payload?.length > 0 ? payload.split("|") : [] + let parts = splittedPayload[0]?.split(" ") + switch (parts?.[0]) { case Constant.End: // Clear out session storage and end the session so we can start fresh the next time limit.trigger(Check.Server); @@ -257,4 +259,8 @@ function response(payload: string): void { if (config.action && parts.length > 1) { config.action(parts[1]); } break; } + // dispatch clarity live signals if available and configured + if (config.signals && splittedPayload[1]) { + dispatchClarityLiveSignalsEvents(splittedPayload[1]) + } } diff --git a/packages/clarity-js/types/core.d.ts b/packages/clarity-js/types/core.d.ts index b3d22096..b7c09687 100644 --- a/packages/clarity-js/types/core.d.ts +++ b/packages/clarity-js/types/core.d.ts @@ -134,6 +134,7 @@ export interface Config { fallback?: string; upgrade?: (key: string) => void; action?: (key: string) => void; + signals?: boolean } export const enum Constant { diff --git a/packages/clarity-js/types/data.d.ts b/packages/clarity-js/types/data.d.ts index f72a2f18..878a24d7 100644 --- a/packages/clarity-js/types/data.d.ts +++ b/packages/clarity-js/types/data.d.ts @@ -401,3 +401,9 @@ export interface UploadData { attempts: number; status: number; } + +export interface ClaritySignal { + type: string + timestamp?: string + value?: number +} From 6b35c6da6649300d981097c3a39f78c489f86d2f Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Mon, 10 Oct 2022 13:37:56 +0200 Subject: [PATCH 02/20] missing comma --- packages/clarity-js/src/core/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/clarity-js/src/core/config.ts b/packages/clarity-js/src/core/config.ts index e4578398..69564f72 100644 --- a/packages/clarity-js/src/core/config.ts +++ b/packages/clarity-js/src/core/config.ts @@ -16,7 +16,7 @@ let config: Config = { upload: null, fallback: null, upgrade: null, - action: null + action: null, signals: false, }; From 769134c9395155f7fae48f300a6e190fd278c44f Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Mon, 17 Oct 2022 13:03:00 +0200 Subject: [PATCH 03/20] support client signals without breaking client actions in collect response --- packages/clarity-js/src/data/upload.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/clarity-js/src/data/upload.ts b/packages/clarity-js/src/data/upload.ts index 4f7b7268..c3a0970f 100644 --- a/packages/clarity-js/src/data/upload.ts +++ b/packages/clarity-js/src/data/upload.ts @@ -243,9 +243,8 @@ function delay(): number { } function response(payload: string): void { - const splittedPayload = payload?.length > 0 ? payload.split("|") : [] - let parts = splittedPayload[0]?.split(" ") - switch (parts?.[0]) { + let parts = payload?.length > 0 ? payload.split(" ") : [Constant.Empty]; + switch (parts[0]) { case Constant.End: // Clear out session storage and end the session so we can start fresh the next time limit.trigger(Check.Server); @@ -256,11 +255,9 @@ function response(payload: string): void { break; case Constant.Action: // Invoke action callback, if configured and has a valid value - if (config.action && parts.length > 1) { config.action(parts[1]); } + if (config.action && parts[1] && parts[1] !== Constant.Signal) { config.action(parts[1]); } break; + break; } - // dispatch clarity live signals if available and configured - if (config.signals && splittedPayload[1]) { - dispatchClarityLiveSignalsEvents(splittedPayload[1]) - } + if (parts.includes(Constant.Signal)) { dispatchClarityLiveSignalsEvents(parts[parts.indexOf(Constant.Signal) +1]) } } From 8c4969cc96dd645cb3e5cecde92a690186372cd2 Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Mon, 17 Oct 2022 13:03:25 +0200 Subject: [PATCH 04/20] client signals file --- packages/clarity-js/src/core/signals.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/clarity-js/src/core/signals.ts b/packages/clarity-js/src/core/signals.ts index ea26c013..7828cf10 100644 --- a/packages/clarity-js/src/core/signals.ts +++ b/packages/clarity-js/src/core/signals.ts @@ -4,15 +4,19 @@ function parseSignals(signalsString: string): ClaritySignal[] { const signalsJson: ClaritySignal[] = JSON.parse(signalsString) return signalsJson; } - +3 export function dispatchClarityLiveSignalsEvents(signalsString: string) { try { - const signalsJson = parseSignals(signalsString); - signalsJson.forEach(signal => { - const customSignalEvent = new CustomEvent("clarityLiveSignal", {detail: signal}) - window.dispatchEvent(customSignalEvent) - }) + const signals = parseSignals(signalsString); + dispatchSignals(signals) } catch { //do nothing } +} + +export function dispatchSignals(signals: ClaritySignal[]) { + signals.forEach(signal => { + const customSignalEvent = new CustomEvent("clarityLiveSignal", {detail: signal}) + window.dispatchEvent(customSignalEvent) + }) } \ No newline at end of file From 39a4dba0961539b27bef399d6fb56ad6458f1da9 Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Mon, 17 Oct 2022 13:04:37 +0200 Subject: [PATCH 05/20] updated constant with clientSignal --- packages/clarity-js/types/data.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/clarity-js/types/data.d.ts b/packages/clarity-js/types/data.d.ts index 878a24d7..471c9d8c 100644 --- a/packages/clarity-js/types/data.d.ts +++ b/packages/clarity-js/types/data.d.ts @@ -251,7 +251,8 @@ export const enum Constant { Pipe = "|", End = "END", Upgrade = "UPGRADE", - Action = "ACTION", + Action = "ClientAction", + Signal = "ClientSignal", UserId = "userId", SessionId = "sessionId", PageId = "pageId", From d61a31959c1dc4657f42fb700417ff6fc5bbf1fc Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Mon, 17 Oct 2022 13:10:10 +0200 Subject: [PATCH 06/20] removed signals flag in config as it's not used --- packages/clarity-js/src/core/config.ts | 1 - packages/clarity-js/types/core.d.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/clarity-js/src/core/config.ts b/packages/clarity-js/src/core/config.ts index 69564f72..2ec94558 100644 --- a/packages/clarity-js/src/core/config.ts +++ b/packages/clarity-js/src/core/config.ts @@ -17,7 +17,6 @@ let config: Config = { fallback: null, upgrade: null, action: null, - signals: false, }; export default config; diff --git a/packages/clarity-js/types/core.d.ts b/packages/clarity-js/types/core.d.ts index b7c09687..b3d22096 100644 --- a/packages/clarity-js/types/core.d.ts +++ b/packages/clarity-js/types/core.d.ts @@ -134,7 +134,6 @@ export interface Config { fallback?: string; upgrade?: (key: string) => void; action?: (key: string) => void; - signals?: boolean } export const enum Constant { From bf534a78af637954f385fb19cbce4a12aeeea819 Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Mon, 17 Oct 2022 13:10:39 +0200 Subject: [PATCH 07/20] Update config.ts --- packages/clarity-js/src/core/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/clarity-js/src/core/config.ts b/packages/clarity-js/src/core/config.ts index 2ec94558..3b2b947b 100644 --- a/packages/clarity-js/src/core/config.ts +++ b/packages/clarity-js/src/core/config.ts @@ -16,7 +16,7 @@ let config: Config = { upload: null, fallback: null, upgrade: null, - action: null, + action: null }; export default config; From 3f58529b7f58b3f34980a550f47237b39a9e7fba Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Mon, 17 Oct 2022 13:22:26 +0200 Subject: [PATCH 08/20] revert to action for backward compatibility --- packages/clarity-js/types/data.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/clarity-js/types/data.d.ts b/packages/clarity-js/types/data.d.ts index 471c9d8c..74da5c42 100644 --- a/packages/clarity-js/types/data.d.ts +++ b/packages/clarity-js/types/data.d.ts @@ -251,7 +251,7 @@ export const enum Constant { Pipe = "|", End = "END", Upgrade = "UPGRADE", - Action = "ClientAction", + Action = "ACTION", Signal = "ClientSignal", UserId = "userId", SessionId = "sessionId", From 8984f96803dcbf3f3b45be14dbfab43354d72fbe Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Mon, 17 Oct 2022 13:33:25 +0200 Subject: [PATCH 09/20] Revert "revert to action for backward compatibility" This reverts commit 3f58529b7f58b3f34980a550f47237b39a9e7fba. --- packages/clarity-js/types/data.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/clarity-js/types/data.d.ts b/packages/clarity-js/types/data.d.ts index 74da5c42..471c9d8c 100644 --- a/packages/clarity-js/types/data.d.ts +++ b/packages/clarity-js/types/data.d.ts @@ -251,7 +251,7 @@ export const enum Constant { Pipe = "|", End = "END", Upgrade = "UPGRADE", - Action = "ACTION", + Action = "ClientAction", Signal = "ClientSignal", UserId = "userId", SessionId = "sessionId", From 836d8629e4d379d77d2532dd36016fae4d5a9937 Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Mon, 17 Oct 2022 16:31:23 +0200 Subject: [PATCH 10/20] timestamp in ClaritySignal to be number instead of string --- packages/clarity-js/types/data.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/clarity-js/types/data.d.ts b/packages/clarity-js/types/data.d.ts index 471c9d8c..ae05a1dc 100644 --- a/packages/clarity-js/types/data.d.ts +++ b/packages/clarity-js/types/data.d.ts @@ -405,6 +405,6 @@ export interface UploadData { export interface ClaritySignal { type: string - timestamp?: string + timestamp?: number value?: number } From c657da14658535e6b855acf7825a76132d47eb83 Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Wed, 19 Oct 2022 12:45:22 +0200 Subject: [PATCH 11/20] Update data.d.ts --- packages/clarity-js/types/data.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/clarity-js/types/data.d.ts b/packages/clarity-js/types/data.d.ts index ae05a1dc..efae85d1 100644 --- a/packages/clarity-js/types/data.d.ts +++ b/packages/clarity-js/types/data.d.ts @@ -251,8 +251,8 @@ export const enum Constant { Pipe = "|", End = "END", Upgrade = "UPGRADE", - Action = "ClientAction", - Signal = "ClientSignal", + Action = "ACTION", + Signal = "SIGNAL", UserId = "userId", SessionId = "sessionId", PageId = "pageId", From 48c62b310272db70875b1628e85a1c644a4d166e Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Thu, 9 Feb 2023 20:16:32 +0200 Subject: [PATCH 12/20] exposed api to set signal callback --- packages/clarity-js/src/clarity.ts | 2 +- packages/clarity-js/src/core/signal.ts | 18 ++++++++++++++++++ packages/clarity-js/src/core/signals.ts | 22 ---------------------- packages/clarity-js/src/data/index.ts | 1 + packages/clarity-js/src/data/signal.ts | 9 +++++++++ packages/clarity-js/src/data/upload.ts | 5 +++-- packages/clarity-js/types/data.d.ts | 1 + packages/clarity-js/types/index.d.ts | 1 + 8 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 packages/clarity-js/src/core/signal.ts delete mode 100644 packages/clarity-js/src/core/signals.ts create mode 100644 packages/clarity-js/src/data/signal.ts diff --git a/packages/clarity-js/src/clarity.ts b/packages/clarity-js/src/clarity.ts index 6fa8779d..4dd5e0a5 100644 --- a/packages/clarity-js/src/clarity.ts +++ b/packages/clarity-js/src/clarity.ts @@ -10,7 +10,7 @@ import * as interaction from "@src/interaction"; import * as layout from "@src/layout"; import * as performance from "@src/performance"; export { version }; -export { consent, event, identify, set, upgrade, metadata } from "@src/data"; +export { consent, event, identify, set, upgrade, metadata, signal } from "@src/data"; export { hashText } from "@src/layout"; const modules: Module[] = [diagnostic, layout, interaction, performance]; diff --git a/packages/clarity-js/src/core/signal.ts b/packages/clarity-js/src/core/signal.ts new file mode 100644 index 00000000..a90feb74 --- /dev/null +++ b/packages/clarity-js/src/core/signal.ts @@ -0,0 +1,18 @@ +import { ClaritySignal } from "@clarity-types/data"; +import { signalCallback } from "@src/data/signal"; + +function parseSignals(signalsString: string): ClaritySignal[] { + const signalsJson: ClaritySignal[] = JSON.parse(signalsString) + return signalsJson; +} + +export function signalEvent(signalsString: string) { + try { + const signals = parseSignals(signalsString); + signals.forEach(signal => { + signalCallback(signal) + }) + } catch { + //do nothing + } +} diff --git a/packages/clarity-js/src/core/signals.ts b/packages/clarity-js/src/core/signals.ts deleted file mode 100644 index 7828cf10..00000000 --- a/packages/clarity-js/src/core/signals.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ClaritySignal } from "@clarity-types/data"; - -function parseSignals(signalsString: string): ClaritySignal[] { - const signalsJson: ClaritySignal[] = JSON.parse(signalsString) - return signalsJson; -} -3 -export function dispatchClarityLiveSignalsEvents(signalsString: string) { - try { - const signals = parseSignals(signalsString); - dispatchSignals(signals) - } catch { - //do nothing - } -} - -export function dispatchSignals(signals: ClaritySignal[]) { - signals.forEach(signal => { - const customSignalEvent = new CustomEvent("clarityLiveSignal", {detail: signal}) - window.dispatchEvent(customSignalEvent) - }) -} \ No newline at end of file diff --git a/packages/clarity-js/src/data/index.ts b/packages/clarity-js/src/data/index.ts index 4010efd8..4c5fc040 100644 --- a/packages/clarity-js/src/data/index.ts +++ b/packages/clarity-js/src/data/index.ts @@ -16,6 +16,7 @@ export { event } from "@src/data/custom"; export { consent, metadata } from "@src/data/metadata"; export { upgrade } from "@src/data/upgrade"; export { set, identify } from "@src/data/variable"; +export { signal } from "@src/data/signal"; const modules: Module[] = [baseline, dimension, variable, limit, summary, metadata, envelope, upload, ping, upgrade, extract]; diff --git a/packages/clarity-js/src/data/signal.ts b/packages/clarity-js/src/data/signal.ts new file mode 100644 index 00000000..88e305e8 --- /dev/null +++ b/packages/clarity-js/src/data/signal.ts @@ -0,0 +1,9 @@ +import { SignalCallback } from "@clarity-types/data"; + +export let signalCallback: SignalCallback = null; + +export function signal(cb: SignalCallback): void { + signalCallback = cb +} + + \ No newline at end of file diff --git a/packages/clarity-js/src/data/upload.ts b/packages/clarity-js/src/data/upload.ts index c3a0970f..d5425c59 100644 --- a/packages/clarity-js/src/data/upload.ts +++ b/packages/clarity-js/src/data/upload.ts @@ -3,7 +3,7 @@ import { BooleanFlag, Check, Constant, EncodedPayload, Event, Metric, Setting, T import * as clarity from "@src/clarity"; import config from "@src/core/config"; import measure from "@src/core/measure"; -import { dispatchClarityLiveSignalsEvents } from "@src/core/signals"; +import { signalEvent } from "@src/core/signal"; import { time } from "@src/core/time"; import { clearTimeout, setTimeout } from "@src/core/timeout"; import compress from "@src/data/compress"; @@ -16,6 +16,7 @@ import * as metric from "@src/data/metric"; import * as ping from "@src/data/ping"; import * as timeline from "@src/interaction/timeline"; import * as region from "@src/layout/region"; +import { signalCallback } from "@src/data/signal"; let discoverBytes: number = 0; let playbackBytes: number = 0; @@ -259,5 +260,5 @@ function response(payload: string): void { break; break; } - if (parts.includes(Constant.Signal)) { dispatchClarityLiveSignalsEvents(parts[parts.indexOf(Constant.Signal) +1]) } + if (signalCallback && parts.includes(Constant.Signal)) { signalEvent(parts[parts.indexOf(Constant.Signal) +1]) } } diff --git a/packages/clarity-js/types/data.d.ts b/packages/clarity-js/types/data.d.ts index efae85d1..bd9cebbe 100644 --- a/packages/clarity-js/types/data.d.ts +++ b/packages/clarity-js/types/data.d.ts @@ -8,6 +8,7 @@ export interface MetadataCallbackOptions { callback: MetadataCallback, wait: boolean } +export type SignalCallback = (data: ClaritySignal) => void /* Enum */ export const enum Event { diff --git a/packages/clarity-js/types/index.d.ts b/packages/clarity-js/types/index.d.ts index 5bf0229a..bbf296bc 100644 --- a/packages/clarity-js/types/index.d.ts +++ b/packages/clarity-js/types/index.d.ts @@ -16,6 +16,7 @@ interface Clarity { set: (variable: string, value: string | string[]) => void; identify: (userId: string, sessionId?: string, pageId?: string) => void; metadata: (callback: Data.MetadataCallback, wait?: boolean) => void; + signal: (callback: Data.SignalCallback) => void; } interface Selector { From 8657d2610a52d531f4ba5f3cc314add501b05834 Mon Sep 17 00:00:00 2001 From: Mostafa Alaa Date: Mon, 15 May 2023 15:30:43 +0300 Subject: [PATCH 13/20] removed unnecessary import --- packages/clarity-js/src/data/upload.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/clarity-js/src/data/upload.ts b/packages/clarity-js/src/data/upload.ts index e5bfb566..eeab6033 100644 --- a/packages/clarity-js/src/data/upload.ts +++ b/packages/clarity-js/src/data/upload.ts @@ -16,7 +16,6 @@ import * as metric from "@src/data/metric"; import * as ping from "@src/data/ping"; import * as timeline from "@src/interaction/timeline"; import * as region from "@src/layout/region"; -import { signalCallback } from "@src/data/signal"; import * as extract from "@src/data/extract"; import { report } from "@src/core/report"; From 07ff151b799b72da11e21b832e6491eedfc2b06b Mon Sep 17 00:00:00 2001 From: Abdelrahman Magdy Date: Mon, 11 Mar 2024 14:02:31 +0200 Subject: [PATCH 14/20] Updating version --- lerna.json | 2 +- packages/clarity-decode/package.json | 2 +- packages/clarity-devtools/package.json | 2 +- packages/clarity-js/package.json | 2 +- packages/clarity-js/src/core/version.ts | 2 +- packages/clarity-visualize/package.json | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lerna.json b/lerna.json index 5d9d0351..498278fc 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "0.7.23", + "version": "0.7.25", "npmClient": "yarn", "useWorkspaces": true } diff --git a/packages/clarity-decode/package.json b/packages/clarity-decode/package.json index 8e696f8a..b5349a8a 100644 --- a/packages/clarity-decode/package.json +++ b/packages/clarity-decode/package.json @@ -1,6 +1,6 @@ { "name": "clarity-decode", - "version": "0.7.23", + "version": "0.7.25", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", diff --git a/packages/clarity-devtools/package.json b/packages/clarity-devtools/package.json index d7094c6a..6da0874b 100644 --- a/packages/clarity-devtools/package.json +++ b/packages/clarity-devtools/package.json @@ -1,6 +1,6 @@ { "name": "clarity-devtools", - "version": "0.7.23", + "version": "0.7.25", "private": true, "description": "Adds Clarity debugging support to browser devtools", "author": "Microsoft Corp.", diff --git a/packages/clarity-js/package.json b/packages/clarity-js/package.json index b96355e0..6d1a4cf1 100644 --- a/packages/clarity-js/package.json +++ b/packages/clarity-js/package.json @@ -1,6 +1,6 @@ { "name": "clarity-js", - "version": "0.7.23", + "version": "0.7.25", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", diff --git a/packages/clarity-js/src/core/version.ts b/packages/clarity-js/src/core/version.ts index f1fcf7df..63525337 100644 --- a/packages/clarity-js/src/core/version.ts +++ b/packages/clarity-js/src/core/version.ts @@ -1,2 +1,2 @@ -let version = "0.7.23"; +let version = "0.7.25"; export default version; diff --git a/packages/clarity-visualize/package.json b/packages/clarity-visualize/package.json index 634916f5..e949e408 100644 --- a/packages/clarity-visualize/package.json +++ b/packages/clarity-visualize/package.json @@ -1,6 +1,6 @@ { "name": "clarity-visualize", - "version": "0.7.23", + "version": "0.7.25", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", @@ -27,7 +27,7 @@ "url": "https://github.com/Microsoft/clarity/issues" }, "dependencies": { - "clarity-decode": "^0.7.23" + "clarity-decode": "^0.7.25" }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.0", From fa976e3d97e117d14c8cbf729959d61b6f92f6bb Mon Sep 17 00:00:00 2001 From: Abdelrahman Magdy Date: Tue, 26 Mar 2024 16:52:21 +0200 Subject: [PATCH 15/20] PR comments --- packages/clarity-js/src/core/signal.ts | 18 ------------------ packages/clarity-js/src/data/signal.ts | 23 ++++++++++++++++++++--- packages/clarity-js/src/data/upload.ts | 4 ++-- 3 files changed, 22 insertions(+), 23 deletions(-) delete mode 100644 packages/clarity-js/src/core/signal.ts diff --git a/packages/clarity-js/src/core/signal.ts b/packages/clarity-js/src/core/signal.ts deleted file mode 100644 index a90feb74..00000000 --- a/packages/clarity-js/src/core/signal.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { ClaritySignal } from "@clarity-types/data"; -import { signalCallback } from "@src/data/signal"; - -function parseSignals(signalsString: string): ClaritySignal[] { - const signalsJson: ClaritySignal[] = JSON.parse(signalsString) - return signalsJson; -} - -export function signalEvent(signalsString: string) { - try { - const signals = parseSignals(signalsString); - signals.forEach(signal => { - signalCallback(signal) - }) - } catch { - //do nothing - } -} diff --git a/packages/clarity-js/src/data/signal.ts b/packages/clarity-js/src/data/signal.ts index 88e305e8..580bee22 100644 --- a/packages/clarity-js/src/data/signal.ts +++ b/packages/clarity-js/src/data/signal.ts @@ -1,9 +1,26 @@ -import { SignalCallback } from "@clarity-types/data"; +import { ClaritySignal, SignalCallback } from '@clarity-types/data'; export let signalCallback: SignalCallback = null; export function signal(cb: SignalCallback): void { - signalCallback = cb + signalCallback = cb; } - \ No newline at end of file +function parseSignals(signalsString: string): ClaritySignal[] { + const signalsJson: ClaritySignal[] = JSON.parse(signalsString); + return signalsJson; +} + +export function signalEvent(signalsString: string) { + try { + if (!signalCallback) { + return; + } + const signals = parseSignals(signalsString); + signals.forEach((signal) => { + signalCallback(signal); + }); + } catch { + //do nothing + } +} diff --git a/packages/clarity-js/src/data/upload.ts b/packages/clarity-js/src/data/upload.ts index f206cd68..bf774890 100644 --- a/packages/clarity-js/src/data/upload.ts +++ b/packages/clarity-js/src/data/upload.ts @@ -3,7 +3,6 @@ import { BooleanFlag, Check, Constant, EncodedPayload, Event, Metric, Setting, T import * as clarity from "@src/clarity"; import config from "@src/core/config"; import measure from "@src/core/measure"; -import { signalEvent } from "@src/core/signal"; import { time } from "@src/core/time"; import { clearTimeout, setTimeout } from "@src/core/timeout"; import compress from "@src/data/compress"; @@ -19,6 +18,7 @@ import * as region from "@src/layout/region"; import * as extract from "@src/data/extract"; import * as style from "@src/layout/style"; import { report } from "@src/core/report"; +import { signalEvent } from "@src/data/signal"; let discoverBytes: number = 0; let playbackBytes: number = 0; @@ -273,7 +273,7 @@ function response(payload: string): void { if (parts.length > 1) { extract.trigger(parts[1]); } break; case Constant.Signal: - if (parts.length > 1) { signalEvent(parts[1]) } + if (parts.length > 1) { signalEvent(parts[1]); } break; } } From d7ed021d48792fe50c8dc590b1cd7c2a08723d0d Mon Sep 17 00:00:00 2001 From: Abdelrahman Magdy Date: Tue, 26 Mar 2024 16:53:39 +0200 Subject: [PATCH 16/20] updating version --- lerna.json | 2 +- packages/clarity-decode/package.json | 2 +- packages/clarity-devtools/package.json | 2 +- packages/clarity-js/package.json | 2 +- packages/clarity-js/src/core/version.ts | 2 +- packages/clarity-visualize/package.json | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lerna.json b/lerna.json index 498278fc..1848ec1e 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "0.7.25", + "version": "0.7.26", "npmClient": "yarn", "useWorkspaces": true } diff --git a/packages/clarity-decode/package.json b/packages/clarity-decode/package.json index 73283824..3aeb7f23 100644 --- a/packages/clarity-decode/package.json +++ b/packages/clarity-decode/package.json @@ -1,6 +1,6 @@ { "name": "clarity-decode", - "version": "0.7.25", + "version": "0.7.26", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", diff --git a/packages/clarity-devtools/package.json b/packages/clarity-devtools/package.json index 1b7d51c2..61dc9c13 100644 --- a/packages/clarity-devtools/package.json +++ b/packages/clarity-devtools/package.json @@ -1,6 +1,6 @@ { "name": "clarity-devtools", - "version": "0.7.25", + "version": "0.7.26", "private": true, "description": "Adds Clarity debugging support to browser devtools", "author": "Microsoft Corp.", diff --git a/packages/clarity-js/package.json b/packages/clarity-js/package.json index 6d1a4cf1..7239cdd0 100644 --- a/packages/clarity-js/package.json +++ b/packages/clarity-js/package.json @@ -1,6 +1,6 @@ { "name": "clarity-js", - "version": "0.7.25", + "version": "0.7.26", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", diff --git a/packages/clarity-js/src/core/version.ts b/packages/clarity-js/src/core/version.ts index 63525337..977f0383 100644 --- a/packages/clarity-js/src/core/version.ts +++ b/packages/clarity-js/src/core/version.ts @@ -1,2 +1,2 @@ -let version = "0.7.25"; +let version = "0.7.26"; export default version; diff --git a/packages/clarity-visualize/package.json b/packages/clarity-visualize/package.json index e949e408..1adb0d4f 100644 --- a/packages/clarity-visualize/package.json +++ b/packages/clarity-visualize/package.json @@ -1,6 +1,6 @@ { "name": "clarity-visualize", - "version": "0.7.25", + "version": "0.7.26", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", @@ -27,7 +27,7 @@ "url": "https://github.com/Microsoft/clarity/issues" }, "dependencies": { - "clarity-decode": "^0.7.25" + "clarity-decode": "^0.7.26" }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.0", From 632028915ad139c67ae5330714632a329793eaef Mon Sep 17 00:00:00 2001 From: Abdelrahman Magdy Date: Mon, 1 Apr 2024 14:13:15 +0200 Subject: [PATCH 17/20] removing timestamp --- packages/clarity-js/types/data.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/clarity-js/types/data.d.ts b/packages/clarity-js/types/data.d.ts index ff3daa08..5308fd1e 100644 --- a/packages/clarity-js/types/data.d.ts +++ b/packages/clarity-js/types/data.d.ts @@ -448,6 +448,5 @@ export interface UploadData { export interface ClaritySignal { type: string - timestamp?: number value?: number } From 2f6fb2a0334b0ba263f0439d9552406b2018e571 Mon Sep 17 00:00:00 2001 From: Abdelrahman Magdy Date: Mon, 1 Apr 2024 14:16:02 +0200 Subject: [PATCH 18/20] updating version --- lerna.json | 2 +- packages/clarity-decode/package.json | 2 +- packages/clarity-devtools/package.json | 2 +- packages/clarity-js/package.json | 2 +- packages/clarity-js/src/core/version.ts | 2 +- packages/clarity-visualize/package.json | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lerna.json b/lerna.json index 1848ec1e..cd768a1b 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "0.7.26", + "version": "0.7.27", "npmClient": "yarn", "useWorkspaces": true } diff --git a/packages/clarity-decode/package.json b/packages/clarity-decode/package.json index 3aeb7f23..cfd4ccc1 100644 --- a/packages/clarity-decode/package.json +++ b/packages/clarity-decode/package.json @@ -1,6 +1,6 @@ { "name": "clarity-decode", - "version": "0.7.26", + "version": "0.7.27", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", diff --git a/packages/clarity-devtools/package.json b/packages/clarity-devtools/package.json index 61dc9c13..31a6c117 100644 --- a/packages/clarity-devtools/package.json +++ b/packages/clarity-devtools/package.json @@ -1,6 +1,6 @@ { "name": "clarity-devtools", - "version": "0.7.26", + "version": "0.7.27", "private": true, "description": "Adds Clarity debugging support to browser devtools", "author": "Microsoft Corp.", diff --git a/packages/clarity-js/package.json b/packages/clarity-js/package.json index 7239cdd0..e40852c6 100644 --- a/packages/clarity-js/package.json +++ b/packages/clarity-js/package.json @@ -1,6 +1,6 @@ { "name": "clarity-js", - "version": "0.7.26", + "version": "0.7.27", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", diff --git a/packages/clarity-js/src/core/version.ts b/packages/clarity-js/src/core/version.ts index 977f0383..86d53976 100644 --- a/packages/clarity-js/src/core/version.ts +++ b/packages/clarity-js/src/core/version.ts @@ -1,2 +1,2 @@ -let version = "0.7.26"; +let version = "0.7.27"; export default version; diff --git a/packages/clarity-visualize/package.json b/packages/clarity-visualize/package.json index 1adb0d4f..273b294b 100644 --- a/packages/clarity-visualize/package.json +++ b/packages/clarity-visualize/package.json @@ -1,6 +1,6 @@ { "name": "clarity-visualize", - "version": "0.7.26", + "version": "0.7.27", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", @@ -27,7 +27,7 @@ "url": "https://github.com/Microsoft/clarity/issues" }, "dependencies": { - "clarity-decode": "^0.7.26" + "clarity-decode": "^0.7.27" }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.0", From 89907bc74c7254c2f410cdb45644ba9f46d74f13 Mon Sep 17 00:00:00 2001 From: Abdelrahman Magdy Date: Tue, 2 Apr 2024 14:36:53 +0200 Subject: [PATCH 19/20] renaming variables --- lerna.json | 2 +- packages/clarity-decode/package.json | 4 ++-- packages/clarity-devtools/package.json | 8 ++++---- packages/clarity-js/package.json | 2 +- packages/clarity-js/src/core/version.ts | 2 +- packages/clarity-js/src/data/signal.ts | 14 +++++++++----- packages/clarity-js/src/data/upload.ts | 4 ++-- packages/clarity-visualize/package.json | 4 ++-- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lerna.json b/lerna.json index cd768a1b..d77b938a 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "0.7.27", + "version": "0.7.29", "npmClient": "yarn", "useWorkspaces": true } diff --git a/packages/clarity-decode/package.json b/packages/clarity-decode/package.json index fc76854c..b609ea72 100644 --- a/packages/clarity-decode/package.json +++ b/packages/clarity-decode/package.json @@ -1,6 +1,6 @@ { "name": "clarity-decode", - "version": "0.7.27", + "version": "0.7.29", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", @@ -26,7 +26,7 @@ "url": "https://github.com/Microsoft/clarity/issues" }, "dependencies": { - "clarity-js": "^0.7.26" + "clarity-js": "^0.7.29" }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.0", diff --git a/packages/clarity-devtools/package.json b/packages/clarity-devtools/package.json index fc065f48..9284c8ad 100644 --- a/packages/clarity-devtools/package.json +++ b/packages/clarity-devtools/package.json @@ -1,6 +1,6 @@ { "name": "clarity-devtools", - "version": "0.7.27", + "version": "0.7.29", "private": true, "description": "Adds Clarity debugging support to browser devtools", "author": "Microsoft Corp.", @@ -24,9 +24,9 @@ "url": "https://github.com/Microsoft/clarity/issues" }, "dependencies": { - "clarity-decode": "^0.7.26", - "clarity-js": "^0.7.26", - "clarity-visualize": "^0.7.26" + "clarity-decode": "^0.7.29", + "clarity-js": "^0.7.29", + "clarity-visualize": "^0.7.29" }, "devDependencies": { "@rollup/plugin-node-resolve": "^15.0.0", diff --git a/packages/clarity-js/package.json b/packages/clarity-js/package.json index e40852c6..de77567f 100644 --- a/packages/clarity-js/package.json +++ b/packages/clarity-js/package.json @@ -1,6 +1,6 @@ { "name": "clarity-js", - "version": "0.7.27", + "version": "0.7.29", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", diff --git a/packages/clarity-js/src/core/version.ts b/packages/clarity-js/src/core/version.ts index 86d53976..67edfec0 100644 --- a/packages/clarity-js/src/core/version.ts +++ b/packages/clarity-js/src/core/version.ts @@ -1,2 +1,2 @@ -let version = "0.7.27"; +let version = "0.7.29"; export default version; diff --git a/packages/clarity-js/src/data/signal.ts b/packages/clarity-js/src/data/signal.ts index 580bee22..b7fb1208 100644 --- a/packages/clarity-js/src/data/signal.ts +++ b/packages/clarity-js/src/data/signal.ts @@ -6,17 +6,21 @@ export function signal(cb: SignalCallback): void { signalCallback = cb; } -function parseSignals(signalsString: string): ClaritySignal[] { - const signalsJson: ClaritySignal[] = JSON.parse(signalsString); - return signalsJson; +function parseSignals(signalsPayload: string): ClaritySignal[] { + try{ + const parsedSignals: ClaritySignal[] = JSON.parse(signalsPayload); + return parsedSignals; + }catch{ + return [] + } } -export function signalEvent(signalsString: string) { +export function triggerSignalsEvent(signalsPayload: string) { try { if (!signalCallback) { return; } - const signals = parseSignals(signalsString); + const signals = parseSignals(signalsPayload); signals.forEach((signal) => { signalCallback(signal); }); diff --git a/packages/clarity-js/src/data/upload.ts b/packages/clarity-js/src/data/upload.ts index bf774890..029dd240 100644 --- a/packages/clarity-js/src/data/upload.ts +++ b/packages/clarity-js/src/data/upload.ts @@ -18,7 +18,7 @@ import * as region from "@src/layout/region"; import * as extract from "@src/data/extract"; import * as style from "@src/layout/style"; import { report } from "@src/core/report"; -import { signalEvent } from "@src/data/signal"; +import { triggerSignalsEvent } from "@src/data/signal"; let discoverBytes: number = 0; let playbackBytes: number = 0; @@ -273,7 +273,7 @@ function response(payload: string): void { if (parts.length > 1) { extract.trigger(parts[1]); } break; case Constant.Signal: - if (parts.length > 1) { signalEvent(parts[1]); } + if (parts.length > 1) { triggerSignalsEvent(parts[1]); } break; } } diff --git a/packages/clarity-visualize/package.json b/packages/clarity-visualize/package.json index 273b294b..8d61f497 100644 --- a/packages/clarity-visualize/package.json +++ b/packages/clarity-visualize/package.json @@ -1,6 +1,6 @@ { "name": "clarity-visualize", - "version": "0.7.27", + "version": "0.7.29", "description": "An analytics library that uses web page interactions to generate aggregated insights", "author": "Microsoft Corp.", "license": "MIT", @@ -27,7 +27,7 @@ "url": "https://github.com/Microsoft/clarity/issues" }, "dependencies": { - "clarity-decode": "^0.7.27" + "clarity-decode": "^0.7.29" }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.0", From 29a6fa0a5be6906dd4800a8e3f573daff590e0c7 Mon Sep 17 00:00:00 2001 From: Abdelrahman Magdy Date: Wed, 3 Apr 2024 00:44:49 +0200 Subject: [PATCH 20/20] renaming variables --- packages/clarity-js/src/data/signal.ts | 2 +- packages/clarity-js/src/data/upload.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/clarity-js/src/data/signal.ts b/packages/clarity-js/src/data/signal.ts index b7fb1208..f3d78754 100644 --- a/packages/clarity-js/src/data/signal.ts +++ b/packages/clarity-js/src/data/signal.ts @@ -15,7 +15,7 @@ function parseSignals(signalsPayload: string): ClaritySignal[] { } } -export function triggerSignalsEvent(signalsPayload: string) { +export function signalsEvent(signalsPayload: string) { try { if (!signalCallback) { return; diff --git a/packages/clarity-js/src/data/upload.ts b/packages/clarity-js/src/data/upload.ts index 029dd240..8357d4a3 100644 --- a/packages/clarity-js/src/data/upload.ts +++ b/packages/clarity-js/src/data/upload.ts @@ -18,7 +18,7 @@ import * as region from "@src/layout/region"; import * as extract from "@src/data/extract"; import * as style from "@src/layout/style"; import { report } from "@src/core/report"; -import { triggerSignalsEvent } from "@src/data/signal"; +import { signalsEvent } from "@src/data/signal"; let discoverBytes: number = 0; let playbackBytes: number = 0; @@ -273,7 +273,7 @@ function response(payload: string): void { if (parts.length > 1) { extract.trigger(parts[1]); } break; case Constant.Signal: - if (parts.length > 1) { triggerSignalsEvent(parts[1]); } + if (parts.length > 1) { signalsEvent(parts[1]); } break; } }