@databuddy/sdk 1.4.0 → 1.4.2
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/Databuddy.js +7 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/tracker.js +6 -9
- package/package.json +34 -27
- package/dist/DatabuddyProvider.d.ts +0 -8
- package/dist/DatabuddyProvider.js +0 -31
package/dist/Databuddy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import pkg from '../package.json';
|
|
3
2
|
import { useEffect } from 'react';
|
|
3
|
+
import pkg from '../package.json' with { type: 'json' };
|
|
4
4
|
/**
|
|
5
5
|
* <Databuddy /> component for Next.js/React apps
|
|
6
6
|
* Injects the databuddy.js script with all config as data attributes
|
|
@@ -8,12 +8,15 @@ import { useEffect } from 'react';
|
|
|
8
8
|
*/
|
|
9
9
|
export function Databuddy(props) {
|
|
10
10
|
useEffect(() => {
|
|
11
|
-
if (typeof window === 'undefined')
|
|
11
|
+
if (typeof window === 'undefined') {
|
|
12
12
|
return;
|
|
13
|
-
|
|
13
|
+
}
|
|
14
|
+
if (props.disabled) {
|
|
14
15
|
return;
|
|
15
|
-
|
|
16
|
+
}
|
|
17
|
+
if (document.querySelector('script[data-databuddy-injected]')) {
|
|
16
18
|
return;
|
|
19
|
+
}
|
|
17
20
|
const script = document.createElement('script');
|
|
18
21
|
script.src = props.scriptUrl || 'https://cdn.databuddy.cc/databuddy.js';
|
|
19
22
|
script.async = true;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/tracker.js
CHANGED
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
* Check if the Databuddy tracker is available
|
|
7
7
|
*/
|
|
8
8
|
export function isTrackerAvailable() {
|
|
9
|
-
return typeof window !== 'undefined' &&
|
|
10
|
-
(!!window.databuddy || !!window.db);
|
|
9
|
+
return typeof window !== 'undefined' && (!!window.databuddy || !!window.db);
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* Get the Databuddy tracker instance
|
|
14
13
|
*/
|
|
15
14
|
export function getTracker() {
|
|
16
|
-
if (typeof window === 'undefined')
|
|
15
|
+
if (typeof window === 'undefined') {
|
|
17
16
|
return null;
|
|
17
|
+
}
|
|
18
18
|
return window.databuddy || null;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -33,8 +33,7 @@ export const track = async (eventName, properties) => {
|
|
|
33
33
|
try {
|
|
34
34
|
await tracker(eventName, properties);
|
|
35
35
|
}
|
|
36
|
-
catch (
|
|
37
|
-
}
|
|
36
|
+
catch (_error) { }
|
|
38
37
|
};
|
|
39
38
|
/**
|
|
40
39
|
* Clear the current session
|
|
@@ -51,8 +50,7 @@ export function clear() {
|
|
|
51
50
|
try {
|
|
52
51
|
tracker();
|
|
53
52
|
}
|
|
54
|
-
catch (
|
|
55
|
-
}
|
|
53
|
+
catch (_error) { }
|
|
56
54
|
}
|
|
57
55
|
/**
|
|
58
56
|
* Flush any queued events
|
|
@@ -69,8 +67,7 @@ export function flush() {
|
|
|
69
67
|
try {
|
|
70
68
|
tracker();
|
|
71
69
|
}
|
|
72
|
-
catch (
|
|
73
|
-
}
|
|
70
|
+
catch (_error) { }
|
|
74
71
|
}
|
|
75
72
|
/**
|
|
76
73
|
* Track an error event
|
package/package.json
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@databuddy/sdk",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@databuddy/sdk",
|
|
3
|
+
"version": "1.4.2",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@types/node": "^20.0.0",
|
|
9
|
+
"typescript": "catalog:"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.js",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"description": "Official Databuddy Analytics SDK",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"analytics",
|
|
25
|
+
"tracking",
|
|
26
|
+
"databuddy",
|
|
27
|
+
"sdk"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"private": false,
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc --project tsconfig.json"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { DatabuddyConfig } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* <Databuddy /> component for Next.js/React apps
|
|
4
|
-
* Injects the databuddy.js script with all config as data attributes
|
|
5
|
-
* Usage: <Databuddy clientId="..." trackScreenViews trackPerformance ... />
|
|
6
|
-
*/
|
|
7
|
-
export declare function Databuddy(props: DatabuddyConfig): null;
|
|
8
|
-
export default Databuddy;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
|
-
/**
|
|
4
|
-
* <Databuddy /> component for Next.js/React apps
|
|
5
|
-
* Injects the databuddy.js script with all config as data attributes
|
|
6
|
-
* Usage: <Databuddy clientId="..." trackScreenViews trackPerformance ... />
|
|
7
|
-
*/
|
|
8
|
-
export function Databuddy(props) {
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
if (typeof window === 'undefined')
|
|
11
|
-
return;
|
|
12
|
-
if (document.querySelector('script[data-databuddy-injected]'))
|
|
13
|
-
return;
|
|
14
|
-
const script = document.createElement('script');
|
|
15
|
-
script.src = props.scriptUrl || 'https://app.databuddy.cc/databuddy.js';
|
|
16
|
-
script.defer = true;
|
|
17
|
-
script.setAttribute('data-databuddy-injected', 'true');
|
|
18
|
-
for (const [key, value] of Object.entries(props)) {
|
|
19
|
-
if (value !== undefined) {
|
|
20
|
-
const dataKey = `data-${key.replace(/([A-Z])/g, '-$1').toLowerCase()}`;
|
|
21
|
-
script.setAttribute(dataKey, String(value));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
document.head.appendChild(script);
|
|
25
|
-
return () => {
|
|
26
|
-
script.remove();
|
|
27
|
-
};
|
|
28
|
-
}, [props]);
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
export default Databuddy;
|