mytart 0.5.2 → 0.6.0
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/index.d.mts +43 -3
- package/dist/index.d.ts +43 -3
- package/dist/index.js +105 -0
- package/dist/index.mjs +104 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -35,7 +35,7 @@ interface ConsentSettings {
|
|
|
35
35
|
/** Controls storage for security purposes (e.g. authentication). */
|
|
36
36
|
security_storage?: ConsentState;
|
|
37
37
|
}
|
|
38
|
-
type ProviderName = 'google-analytics' | 'mixpanel' | 'segment' | 'amplitude' | 'plausible' | 'posthog' | 'meta-pixel';
|
|
38
|
+
type ProviderName = 'google-analytics' | 'mixpanel' | 'segment' | 'amplitude' | 'plausible' | 'posthog' | 'meta-pixel' | 'clarity';
|
|
39
39
|
type GoogleAnalyticsAppType = 'browser' | 'server';
|
|
40
40
|
interface GoogleAnalyticsConfig extends BaseProviderConfig {
|
|
41
41
|
provider: 'google-analytics';
|
|
@@ -180,7 +180,18 @@ interface MetaPixelConfig extends BaseProviderConfig {
|
|
|
180
180
|
/** Enable Meta Pixel debug mode (`fbq('set', 'debug', true)`). */
|
|
181
181
|
debug?: boolean;
|
|
182
182
|
}
|
|
183
|
-
|
|
183
|
+
interface ClarityConfig extends BaseProviderConfig {
|
|
184
|
+
provider: 'clarity';
|
|
185
|
+
/** The Clarity project ID (from the Clarity dashboard). */
|
|
186
|
+
projectId: string;
|
|
187
|
+
/**
|
|
188
|
+
* Enable Clarity cookie consent mode. When `true`, calls
|
|
189
|
+
* `clarity('consent')` after initialisation so Clarity sets cookies.
|
|
190
|
+
* When omitted or `false`, Clarity operates in cookieless mode.
|
|
191
|
+
*/
|
|
192
|
+
cookie?: boolean;
|
|
193
|
+
}
|
|
194
|
+
type ProviderConfig = GoogleAnalyticsConfig | MixpanelConfig | SegmentConfig | AmplitudeConfig | PlausibleConfig | PostHogConfig | MetaPixelConfig | ClarityConfig;
|
|
184
195
|
interface MytartConfig {
|
|
185
196
|
providers: ProviderConfig[];
|
|
186
197
|
defaultUserId?: string;
|
|
@@ -470,4 +481,33 @@ declare class MetaPixelProvider extends BaseProvider {
|
|
|
470
481
|
page(options: PageOptions): Promise<TrackResult>;
|
|
471
482
|
}
|
|
472
483
|
|
|
473
|
-
|
|
484
|
+
declare global {
|
|
485
|
+
interface Window {
|
|
486
|
+
clarity: ClarityFn & {
|
|
487
|
+
q?: unknown[][];
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
type ClarityFn = (...args: unknown[]) => void;
|
|
492
|
+
declare class ClarityProvider extends BaseProvider {
|
|
493
|
+
readonly name = "clarity";
|
|
494
|
+
private readonly config;
|
|
495
|
+
private clarityReady;
|
|
496
|
+
constructor(config: ClarityConfig);
|
|
497
|
+
/**
|
|
498
|
+
* Injects the official Clarity tracking snippet. Mirrors:
|
|
499
|
+
*
|
|
500
|
+
* (function(c,l,a,r,i,t,y){
|
|
501
|
+
* c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
|
|
502
|
+
* t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
|
|
503
|
+
* y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
|
|
504
|
+
* })(window, document, "clarity", "script", "PROJECT_ID");
|
|
505
|
+
*/
|
|
506
|
+
private initClarity;
|
|
507
|
+
private ensureClarity;
|
|
508
|
+
track(options: TrackOptions): Promise<TrackResult>;
|
|
509
|
+
identify(options: IdentifyOptions): Promise<TrackResult>;
|
|
510
|
+
page(options: PageOptions): Promise<TrackResult>;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export { type AmplitudeConfig, AmplitudeProvider, BaseProvider, type BaseProviderConfig, type ClarityConfig, ClarityProvider, type ConsentSettings, type ConsentState, type EventContext, type GoogleAnalyticsAppType, type GoogleAnalyticsConfig, GoogleAnalyticsProvider, type IdentifyOptions, type MetaPixelAdvancedMatching, type MetaPixelAppType, type MetaPixelConfig, MetaPixelProvider, type MixpanelConfig, MixpanelProvider, Mytart, type MytartConfig, type MytartError, type PageOptions, type PlausibleConfig, PlausibleProvider, type PostHogConfig, PostHogProvider, type ProviderConfig, type ProviderName, type SegmentConfig, SegmentProvider, type TrackOptions, type TrackResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ interface ConsentSettings {
|
|
|
35
35
|
/** Controls storage for security purposes (e.g. authentication). */
|
|
36
36
|
security_storage?: ConsentState;
|
|
37
37
|
}
|
|
38
|
-
type ProviderName = 'google-analytics' | 'mixpanel' | 'segment' | 'amplitude' | 'plausible' | 'posthog' | 'meta-pixel';
|
|
38
|
+
type ProviderName = 'google-analytics' | 'mixpanel' | 'segment' | 'amplitude' | 'plausible' | 'posthog' | 'meta-pixel' | 'clarity';
|
|
39
39
|
type GoogleAnalyticsAppType = 'browser' | 'server';
|
|
40
40
|
interface GoogleAnalyticsConfig extends BaseProviderConfig {
|
|
41
41
|
provider: 'google-analytics';
|
|
@@ -180,7 +180,18 @@ interface MetaPixelConfig extends BaseProviderConfig {
|
|
|
180
180
|
/** Enable Meta Pixel debug mode (`fbq('set', 'debug', true)`). */
|
|
181
181
|
debug?: boolean;
|
|
182
182
|
}
|
|
183
|
-
|
|
183
|
+
interface ClarityConfig extends BaseProviderConfig {
|
|
184
|
+
provider: 'clarity';
|
|
185
|
+
/** The Clarity project ID (from the Clarity dashboard). */
|
|
186
|
+
projectId: string;
|
|
187
|
+
/**
|
|
188
|
+
* Enable Clarity cookie consent mode. When `true`, calls
|
|
189
|
+
* `clarity('consent')` after initialisation so Clarity sets cookies.
|
|
190
|
+
* When omitted or `false`, Clarity operates in cookieless mode.
|
|
191
|
+
*/
|
|
192
|
+
cookie?: boolean;
|
|
193
|
+
}
|
|
194
|
+
type ProviderConfig = GoogleAnalyticsConfig | MixpanelConfig | SegmentConfig | AmplitudeConfig | PlausibleConfig | PostHogConfig | MetaPixelConfig | ClarityConfig;
|
|
184
195
|
interface MytartConfig {
|
|
185
196
|
providers: ProviderConfig[];
|
|
186
197
|
defaultUserId?: string;
|
|
@@ -470,4 +481,33 @@ declare class MetaPixelProvider extends BaseProvider {
|
|
|
470
481
|
page(options: PageOptions): Promise<TrackResult>;
|
|
471
482
|
}
|
|
472
483
|
|
|
473
|
-
|
|
484
|
+
declare global {
|
|
485
|
+
interface Window {
|
|
486
|
+
clarity: ClarityFn & {
|
|
487
|
+
q?: unknown[][];
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
type ClarityFn = (...args: unknown[]) => void;
|
|
492
|
+
declare class ClarityProvider extends BaseProvider {
|
|
493
|
+
readonly name = "clarity";
|
|
494
|
+
private readonly config;
|
|
495
|
+
private clarityReady;
|
|
496
|
+
constructor(config: ClarityConfig);
|
|
497
|
+
/**
|
|
498
|
+
* Injects the official Clarity tracking snippet. Mirrors:
|
|
499
|
+
*
|
|
500
|
+
* (function(c,l,a,r,i,t,y){
|
|
501
|
+
* c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
|
|
502
|
+
* t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
|
|
503
|
+
* y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
|
|
504
|
+
* })(window, document, "clarity", "script", "PROJECT_ID");
|
|
505
|
+
*/
|
|
506
|
+
private initClarity;
|
|
507
|
+
private ensureClarity;
|
|
508
|
+
track(options: TrackOptions): Promise<TrackResult>;
|
|
509
|
+
identify(options: IdentifyOptions): Promise<TrackResult>;
|
|
510
|
+
page(options: PageOptions): Promise<TrackResult>;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export { type AmplitudeConfig, AmplitudeProvider, BaseProvider, type BaseProviderConfig, type ClarityConfig, ClarityProvider, type ConsentSettings, type ConsentState, type EventContext, type GoogleAnalyticsAppType, type GoogleAnalyticsConfig, GoogleAnalyticsProvider, type IdentifyOptions, type MetaPixelAdvancedMatching, type MetaPixelAppType, type MetaPixelConfig, MetaPixelProvider, type MixpanelConfig, MixpanelProvider, Mytart, type MytartConfig, type MytartError, type PageOptions, type PlausibleConfig, PlausibleProvider, type PostHogConfig, PostHogProvider, type ProviderConfig, type ProviderName, type SegmentConfig, SegmentProvider, type TrackOptions, type TrackResult };
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
AmplitudeProvider: () => AmplitudeProvider,
|
|
34
34
|
BaseProvider: () => BaseProvider,
|
|
35
|
+
ClarityProvider: () => ClarityProvider,
|
|
35
36
|
GoogleAnalyticsProvider: () => GoogleAnalyticsProvider,
|
|
36
37
|
MetaPixelProvider: () => MetaPixelProvider,
|
|
37
38
|
MixpanelProvider: () => MixpanelProvider,
|
|
@@ -1092,6 +1093,107 @@ var MetaPixelProvider = class extends BaseProvider {
|
|
|
1092
1093
|
}
|
|
1093
1094
|
};
|
|
1094
1095
|
|
|
1096
|
+
// src/providers/clarity.ts
|
|
1097
|
+
var CLARITY_SCRIPT_BASE = "https://www.clarity.ms/tag/";
|
|
1098
|
+
var ClarityProvider = class extends BaseProvider {
|
|
1099
|
+
constructor(config) {
|
|
1100
|
+
super();
|
|
1101
|
+
this.name = "clarity";
|
|
1102
|
+
this.clarityReady = null;
|
|
1103
|
+
this.config = config;
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Injects the official Clarity tracking snippet. Mirrors:
|
|
1107
|
+
*
|
|
1108
|
+
* (function(c,l,a,r,i,t,y){
|
|
1109
|
+
* c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
|
|
1110
|
+
* t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
|
|
1111
|
+
* y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
|
|
1112
|
+
* })(window, document, "clarity", "script", "PROJECT_ID");
|
|
1113
|
+
*/
|
|
1114
|
+
initClarity() {
|
|
1115
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
1116
|
+
return Promise.resolve();
|
|
1117
|
+
}
|
|
1118
|
+
if (!window.clarity) {
|
|
1119
|
+
const q = [];
|
|
1120
|
+
const fn = function clarity(...args) {
|
|
1121
|
+
q.push(args);
|
|
1122
|
+
};
|
|
1123
|
+
fn.q = q;
|
|
1124
|
+
window.clarity = fn;
|
|
1125
|
+
}
|
|
1126
|
+
if (this.config.cookie) {
|
|
1127
|
+
window.clarity("consent");
|
|
1128
|
+
}
|
|
1129
|
+
return new Promise((resolve) => {
|
|
1130
|
+
const script = document.createElement("script");
|
|
1131
|
+
script.async = true;
|
|
1132
|
+
script.src = CLARITY_SCRIPT_BASE + this.config.projectId;
|
|
1133
|
+
script.onload = () => resolve();
|
|
1134
|
+
script.onerror = () => resolve();
|
|
1135
|
+
document.head.appendChild(script);
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
ensureClarity() {
|
|
1139
|
+
if (!this.clarityReady) {
|
|
1140
|
+
this.clarityReady = this.initClarity();
|
|
1141
|
+
}
|
|
1142
|
+
return this.clarityReady;
|
|
1143
|
+
}
|
|
1144
|
+
async track(options) {
|
|
1145
|
+
if (typeof window === "undefined") {
|
|
1146
|
+
return this.buildSuccess(200);
|
|
1147
|
+
}
|
|
1148
|
+
await this.ensureClarity();
|
|
1149
|
+
window.clarity("event", options.event);
|
|
1150
|
+
if (options.properties) {
|
|
1151
|
+
for (const [key, value] of Object.entries(options.properties)) {
|
|
1152
|
+
window.clarity("set", key, String(value));
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
return this.buildSuccess(200);
|
|
1156
|
+
}
|
|
1157
|
+
async identify(options) {
|
|
1158
|
+
if (typeof window === "undefined") {
|
|
1159
|
+
return this.buildSuccess(200);
|
|
1160
|
+
}
|
|
1161
|
+
await this.ensureClarity();
|
|
1162
|
+
const friendlyName = options.traits?.name ?? void 0;
|
|
1163
|
+
window.clarity("identify", options.userId, void 0, void 0, friendlyName);
|
|
1164
|
+
if (options.traits) {
|
|
1165
|
+
for (const [key, value] of Object.entries(options.traits)) {
|
|
1166
|
+
if (key !== "name") {
|
|
1167
|
+
window.clarity("set", key, String(value));
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
return this.buildSuccess(200);
|
|
1172
|
+
}
|
|
1173
|
+
async page(options) {
|
|
1174
|
+
if (typeof window === "undefined") {
|
|
1175
|
+
return this.buildSuccess(200);
|
|
1176
|
+
}
|
|
1177
|
+
await this.ensureClarity();
|
|
1178
|
+
window.clarity("event", "PageView");
|
|
1179
|
+
if (options.url) {
|
|
1180
|
+
window.clarity("set", "pageUrl", options.url);
|
|
1181
|
+
}
|
|
1182
|
+
if (options.name) {
|
|
1183
|
+
window.clarity("set", "pageName", options.name);
|
|
1184
|
+
}
|
|
1185
|
+
if (options.referrer) {
|
|
1186
|
+
window.clarity("set", "referrer", options.referrer);
|
|
1187
|
+
}
|
|
1188
|
+
if (options.properties) {
|
|
1189
|
+
for (const [key, value] of Object.entries(options.properties)) {
|
|
1190
|
+
window.clarity("set", key, String(value));
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
return this.buildSuccess(200);
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
|
|
1095
1197
|
// src/mytart.ts
|
|
1096
1198
|
function createProvider(config) {
|
|
1097
1199
|
switch (config.provider) {
|
|
@@ -1109,6 +1211,8 @@ function createProvider(config) {
|
|
|
1109
1211
|
return new PostHogProvider(config);
|
|
1110
1212
|
case "meta-pixel":
|
|
1111
1213
|
return new MetaPixelProvider(config);
|
|
1214
|
+
case "clarity":
|
|
1215
|
+
return new ClarityProvider(config);
|
|
1112
1216
|
default: {
|
|
1113
1217
|
const exhaustive = config;
|
|
1114
1218
|
throw new Error(`Unknown provider: ${exhaustive.provider}`);
|
|
@@ -1169,6 +1273,7 @@ var Mytart = class {
|
|
|
1169
1273
|
0 && (module.exports = {
|
|
1170
1274
|
AmplitudeProvider,
|
|
1171
1275
|
BaseProvider,
|
|
1276
|
+
ClarityProvider,
|
|
1172
1277
|
GoogleAnalyticsProvider,
|
|
1173
1278
|
MetaPixelProvider,
|
|
1174
1279
|
MixpanelProvider,
|
package/dist/index.mjs
CHANGED
|
@@ -1048,6 +1048,107 @@ var MetaPixelProvider = class extends BaseProvider {
|
|
|
1048
1048
|
}
|
|
1049
1049
|
};
|
|
1050
1050
|
|
|
1051
|
+
// src/providers/clarity.ts
|
|
1052
|
+
var CLARITY_SCRIPT_BASE = "https://www.clarity.ms/tag/";
|
|
1053
|
+
var ClarityProvider = class extends BaseProvider {
|
|
1054
|
+
constructor(config) {
|
|
1055
|
+
super();
|
|
1056
|
+
this.name = "clarity";
|
|
1057
|
+
this.clarityReady = null;
|
|
1058
|
+
this.config = config;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Injects the official Clarity tracking snippet. Mirrors:
|
|
1062
|
+
*
|
|
1063
|
+
* (function(c,l,a,r,i,t,y){
|
|
1064
|
+
* c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
|
|
1065
|
+
* t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
|
|
1066
|
+
* y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
|
|
1067
|
+
* })(window, document, "clarity", "script", "PROJECT_ID");
|
|
1068
|
+
*/
|
|
1069
|
+
initClarity() {
|
|
1070
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
1071
|
+
return Promise.resolve();
|
|
1072
|
+
}
|
|
1073
|
+
if (!window.clarity) {
|
|
1074
|
+
const q = [];
|
|
1075
|
+
const fn = function clarity(...args) {
|
|
1076
|
+
q.push(args);
|
|
1077
|
+
};
|
|
1078
|
+
fn.q = q;
|
|
1079
|
+
window.clarity = fn;
|
|
1080
|
+
}
|
|
1081
|
+
if (this.config.cookie) {
|
|
1082
|
+
window.clarity("consent");
|
|
1083
|
+
}
|
|
1084
|
+
return new Promise((resolve) => {
|
|
1085
|
+
const script = document.createElement("script");
|
|
1086
|
+
script.async = true;
|
|
1087
|
+
script.src = CLARITY_SCRIPT_BASE + this.config.projectId;
|
|
1088
|
+
script.onload = () => resolve();
|
|
1089
|
+
script.onerror = () => resolve();
|
|
1090
|
+
document.head.appendChild(script);
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
ensureClarity() {
|
|
1094
|
+
if (!this.clarityReady) {
|
|
1095
|
+
this.clarityReady = this.initClarity();
|
|
1096
|
+
}
|
|
1097
|
+
return this.clarityReady;
|
|
1098
|
+
}
|
|
1099
|
+
async track(options) {
|
|
1100
|
+
if (typeof window === "undefined") {
|
|
1101
|
+
return this.buildSuccess(200);
|
|
1102
|
+
}
|
|
1103
|
+
await this.ensureClarity();
|
|
1104
|
+
window.clarity("event", options.event);
|
|
1105
|
+
if (options.properties) {
|
|
1106
|
+
for (const [key, value] of Object.entries(options.properties)) {
|
|
1107
|
+
window.clarity("set", key, String(value));
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
return this.buildSuccess(200);
|
|
1111
|
+
}
|
|
1112
|
+
async identify(options) {
|
|
1113
|
+
if (typeof window === "undefined") {
|
|
1114
|
+
return this.buildSuccess(200);
|
|
1115
|
+
}
|
|
1116
|
+
await this.ensureClarity();
|
|
1117
|
+
const friendlyName = options.traits?.name ?? void 0;
|
|
1118
|
+
window.clarity("identify", options.userId, void 0, void 0, friendlyName);
|
|
1119
|
+
if (options.traits) {
|
|
1120
|
+
for (const [key, value] of Object.entries(options.traits)) {
|
|
1121
|
+
if (key !== "name") {
|
|
1122
|
+
window.clarity("set", key, String(value));
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return this.buildSuccess(200);
|
|
1127
|
+
}
|
|
1128
|
+
async page(options) {
|
|
1129
|
+
if (typeof window === "undefined") {
|
|
1130
|
+
return this.buildSuccess(200);
|
|
1131
|
+
}
|
|
1132
|
+
await this.ensureClarity();
|
|
1133
|
+
window.clarity("event", "PageView");
|
|
1134
|
+
if (options.url) {
|
|
1135
|
+
window.clarity("set", "pageUrl", options.url);
|
|
1136
|
+
}
|
|
1137
|
+
if (options.name) {
|
|
1138
|
+
window.clarity("set", "pageName", options.name);
|
|
1139
|
+
}
|
|
1140
|
+
if (options.referrer) {
|
|
1141
|
+
window.clarity("set", "referrer", options.referrer);
|
|
1142
|
+
}
|
|
1143
|
+
if (options.properties) {
|
|
1144
|
+
for (const [key, value] of Object.entries(options.properties)) {
|
|
1145
|
+
window.clarity("set", key, String(value));
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
return this.buildSuccess(200);
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1051
1152
|
// src/mytart.ts
|
|
1052
1153
|
function createProvider(config) {
|
|
1053
1154
|
switch (config.provider) {
|
|
@@ -1065,6 +1166,8 @@ function createProvider(config) {
|
|
|
1065
1166
|
return new PostHogProvider(config);
|
|
1066
1167
|
case "meta-pixel":
|
|
1067
1168
|
return new MetaPixelProvider(config);
|
|
1169
|
+
case "clarity":
|
|
1170
|
+
return new ClarityProvider(config);
|
|
1068
1171
|
default: {
|
|
1069
1172
|
const exhaustive = config;
|
|
1070
1173
|
throw new Error(`Unknown provider: ${exhaustive.provider}`);
|
|
@@ -1124,6 +1227,7 @@ var Mytart = class {
|
|
|
1124
1227
|
export {
|
|
1125
1228
|
AmplitudeProvider,
|
|
1126
1229
|
BaseProvider,
|
|
1230
|
+
ClarityProvider,
|
|
1127
1231
|
GoogleAnalyticsProvider,
|
|
1128
1232
|
MetaPixelProvider,
|
|
1129
1233
|
MixpanelProvider,
|