Skip to content

Commit

Permalink
Merge pull request #284 from moustaphaalaa/live-signals
Browse files Browse the repository at this point in the history
Live signals
  • Loading branch information
AbdelrhmanMagdy authored Apr 2, 2024
2 parents ba9be9b + 28107b0 commit 5bf0f46
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.7.24",
"version": "0.7.29",
"npmClient": "yarn",
"useWorkspaces": true
}
4 changes: 2 additions & 2 deletions packages/clarity-decode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-decode",
"version": "0.7.28",
"version": "0.7.29",
"description": "An analytics library that uses web page interactions to generate aggregated insights",
"author": "Microsoft Corp.",
"license": "MIT",
Expand All @@ -26,7 +26,7 @@
"url": "https://github.com/Microsoft/clarity/issues"
},
"dependencies": {
"clarity-js": "^0.7.28"
"clarity-js": "^0.7.29"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/clarity-devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-devtools",
"version": "0.7.28",
"version": "0.7.29",
"private": true,
"description": "Adds Clarity debugging support to browser devtools",
"author": "Microsoft Corp.",
Expand All @@ -24,9 +24,9 @@
"url": "https://github.com/Microsoft/clarity/issues"
},
"dependencies": {
"clarity-decode": "^0.7.28",
"clarity-js": "^0.7.28",
"clarity-visualize": "^0.7.28"
"clarity-decode": "^0.7.29",
"clarity-js": "^0.7.29",
"clarity-visualize": "^0.7.29"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-js",
"version": "0.7.28",
"version": "0.7.29",
"description": "An analytics library that uses web page interactions to generate aggregated insights",
"author": "Microsoft Corp.",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-js/src/clarity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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];
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-js/src/core/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
let version = "0.7.28";
let version = "0.7.29";
export default version;
1 change: 1 addition & 0 deletions packages/clarity-js/src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
30 changes: 30 additions & 0 deletions packages/clarity-js/src/data/signal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ClaritySignal, SignalCallback } from '@clarity-types/data';

export let signalCallback: SignalCallback = null;

export function signal(cb: SignalCallback): void {
signalCallback = cb;
}

function parseSignals(signalsPayload: string): ClaritySignal[] {
try{
const parsedSignals: ClaritySignal[] = JSON.parse(signalsPayload);
return parsedSignals;
}catch{
return []
}
}

export function signalsEvent(signalsPayload: string) {
try {
if (!signalCallback) {
return;
}
const signals = parseSignals(signalsPayload);
signals.forEach((signal) => {
signalCallback(signal);
});
} catch {
//do nothing
}
}
4 changes: 4 additions & 0 deletions packages/clarity-js/src/data/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,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 { signalsEvent } from "@src/data/signal";

let discoverBytes: number = 0;
let playbackBytes: number = 0;
Expand Down Expand Up @@ -271,6 +272,9 @@ function response(payload: string): void {
case Constant.Extract:
if (parts.length > 1) { extract.trigger(parts[1]); }
break;
case Constant.Signal:
if (parts.length > 1) { signalsEvent(parts[1]); }
break;
}
}
}
7 changes: 7 additions & 0 deletions packages/clarity-js/types/data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface MetadataCallbackOptions {
callback: MetadataCallback,
wait: boolean
}
export type SignalCallback = (data: ClaritySignal) => void

/* Enum */
export const enum Event {
Expand Down Expand Up @@ -278,6 +279,7 @@ export const enum Constant {
End = "END",
Upgrade = "UPGRADE",
Action = "ACTION",
Signal = "SIGNAL",
Extract = "EXTRACT",
UserHint = "userHint",
UserType = "userType",
Expand Down Expand Up @@ -444,3 +446,8 @@ export interface UploadData {
attempts: number;
status: number;
}

export interface ClaritySignal {
type: string
value?: number
}
1 change: 1 addition & 0 deletions packages/clarity-js/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Clarity {
set: (variable: string, value: string | string[]) => void;
identify: (userId: string, sessionId?: string, pageId?: string, userHint?: string) => void;
metadata: (callback: Data.MetadataCallback, wait?: boolean) => void;
signal: (callback: Data.SignalCallback) => void;
}

interface Selector {
Expand Down
4 changes: 2 additions & 2 deletions packages/clarity-visualize/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-visualize",
"version": "0.7.28",
"version": "0.7.29",
"description": "An analytics library that uses web page interactions to generate aggregated insights",
"author": "Microsoft Corp.",
"license": "MIT",
Expand All @@ -27,7 +27,7 @@
"url": "https://github.com/Microsoft/clarity/issues"
},
"dependencies": {
"clarity-decode": "^0.7.28"
"clarity-decode": "^0.7.29"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down

0 comments on commit 5bf0f46

Please sign in to comment.