Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handling identify, set and consent while clarity is stopped #319

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.1",
"version": "0.7.2",
"npmClient": "yarn",
"useWorkspaces": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "clarity",
"private": true,
"version": "0.7.1",
"version": "0.7.2",
"repository": "https://github.com/microsoft/clarity.git",
"author": "Sarvesh Nagpal <[email protected]>",
"license": "MIT",
Expand Down
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.1",
"version": "2",
ender336 marked this conversation as resolved.
Show resolved Hide resolved
"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.1"
"clarity-js": "^0.7.2"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^19.0.1",
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.1",
"version": "0.7.2",
"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.1",
"clarity-js": "^0.7.1",
"clarity-visualize": "^0.7.1"
"clarity-decode": "^0.7.2",
"clarity-js": "^0.7.2",
"clarity-visualize": "^0.7.2"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/clarity-devtools/static/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"manifest_version": 2,
"name": "Microsoft Clarity Developer Tools",
"description": "Clarity helps you understand how users are interacting with your website.",
"version": "0.7.1",
"version_name": "0.7.1",
"version": "0.7.2",
"version_name": "0.7.2",
"minimum_chrome_version": "50",
"devtools_page": "devtools.html",
"icons": {
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.1",
"version": "0.7.2",
"description": "An analytics library that uses web page interactions to generate aggregated insights",
"author": "Microsoft Corp.",
"license": "MIT",
Expand Down
8 changes: 8 additions & 0 deletions packages/clarity-js/src/clarity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function start(config: Config = null): void {
core.start();
data.start();
modules.forEach(x => measure(x.start)());
executeQueue();
}
}

Expand Down Expand Up @@ -53,3 +54,10 @@ export function stop(): void {
core.stop();
}
}

export function executeQueue(): void {
const w = window as any;
const c = 'clarity';
const queue = w[c] ? (w[c].q || []) : [];
while (queue.length > 0) { w[c](...queue.shift()); }
}
6 changes: 6 additions & 0 deletions packages/clarity-js/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export function suspend(): void {
}
}

export function queue(functionName: string, args: IArguments): void {
const w = window as any;
const c = 'clarity';
(w[c].q=w[c].q||[]).push([functionName].concat(Array.from(args)));
}

function restart(): void {
clarity.start();
custom.event(Constant.Clarity, Constant.Restart);
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.1";
let version = "0.7.2";
export default version;
2 changes: 2 additions & 0 deletions packages/clarity-js/src/data/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export function consent(): void {
if (core.active()) {
config.track = true;
track(user(), BooleanFlag.True);
} else {
core.queue("consent", arguments);
}
}

Expand Down
19 changes: 14 additions & 5 deletions packages/clarity-js/src/data/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ export function start(): void {
}

export function set(variable: string, value: string | string[]): void {
let values = typeof value === Constant.String ? [value as string] : value as string[];
log(variable, values);
if (core.active()) {
let values = typeof value === Constant.String ? [value as string] : value as string[];
log(variable, values);
} else {
core.queue("set", arguments);
}
}

export function identify(userId: string, sessionId: string = null, pageId: string = null): void {
log(Constant.UserId, [userId]);
log(Constant.SessionId, [sessionId]);
log(Constant.PageId, [pageId]);
if (core.active()) {
log(Constant.UserId, [userId]);
log(Constant.SessionId, [sessionId]);
log(Constant.PageId, [pageId]);
} else {
core.queue("identify", arguments);
}

}

function log(variable: string, value: string[]): void {
ender336 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 2 additions & 1 deletion packages/clarity-js/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as clarity from "@src/clarity";
const queue = w[c] ? (w[c].q || []) : [];
w[c] = function(method: string, ...args: any[]): void { return clarity[method](...args); }
w[c].v = clarity.version;
while (queue.length > 0) { w[c](...queue.shift()); }
w[c].q = queue;
clarity.executeQueue();
}
})();
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.1",
"version": "0.7.2",
"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.1"
"clarity-decode": "^0.7.2"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^19.0.1",
Expand Down