@storewatch/react 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +13 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +30 -0
- package/dist/provider.d.ts +17 -0
- package/package.json +43 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Edin Skeja
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @storewatch/react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React bindings for the Storewatch browser SDK.
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { StorewatchProvider, useStorewatch, money } from "@storewatch/react";
|
|
7
|
+
|
|
8
|
+
<StorewatchProvider publicKey="sw_pk_…" endpoint="https://ingest.example.com/v1/batch">
|
|
9
|
+
<App />
|
|
10
|
+
</StorewatchProvider>;
|
|
11
|
+
|
|
12
|
+
const sw = useStorewatch();
|
|
13
|
+
sw.track("add_to_cart", { productId, quantity: 1, cartValue: money(1249, "SEK") });
|
|
14
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/provider.tsx
|
|
4
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
5
|
+
import { getStorewatch, init } from "@storewatch/browser";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
var StorewatchContext = createContext(null);
|
|
8
|
+
function StorewatchProvider({ children, ...options }) {
|
|
9
|
+
const [client, setClient] = useState(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
setClient(init(options));
|
|
12
|
+
}, [options.publicKey]);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
client?.setConsent(options.consent ?? "pending");
|
|
15
|
+
}, [client, options.consent]);
|
|
16
|
+
return /* @__PURE__ */ jsx(StorewatchContext.Provider, { value: client, children });
|
|
17
|
+
}
|
|
18
|
+
function useStorewatch() {
|
|
19
|
+
return useContext(StorewatchContext) ?? getStorewatch();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
import { getStorewatch as getStorewatch2, init as init2, money } from "@storewatch/browser";
|
|
24
|
+
export {
|
|
25
|
+
StorewatchProvider,
|
|
26
|
+
getStorewatch2 as getStorewatch,
|
|
27
|
+
init2 as init,
|
|
28
|
+
money,
|
|
29
|
+
useStorewatch
|
|
30
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type Storewatch, type StorewatchOptions } from "@storewatch/browser";
|
|
3
|
+
export type StorewatchProviderProps = StorewatchOptions & {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Initialises Storewatch once per page. `consent` is reactive: pass your
|
|
8
|
+
* consent banner's state and changes are applied immediately.
|
|
9
|
+
*/
|
|
10
|
+
export declare function StorewatchProvider({ children, ...options }: StorewatchProviderProps): import("react").JSX.Element;
|
|
11
|
+
/**
|
|
12
|
+
* The Storewatch client. Works with or without a provider (e.g. when init
|
|
13
|
+
* happened in Next's instrumentation-client.ts). Safe to call before init
|
|
14
|
+
* (including from child effects, which React runs first): early calls are
|
|
15
|
+
* queued and replayed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useStorewatch(): Storewatch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storewatch/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React bindings for the Storewatch browser SDK.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@storewatch/browser": "0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@testing-library/react": "^16.3.3",
|
|
29
|
+
"@types/react": "^19.3.0",
|
|
30
|
+
"happy-dom": "^21.0.1",
|
|
31
|
+
"react": "^19.3.1",
|
|
32
|
+
"react-dom": "^19.3.1",
|
|
33
|
+
"tsup": "^9.0.0",
|
|
34
|
+
"@storewatch/config": "0.0.0"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"storewatch",
|
|
38
|
+
"analytics",
|
|
39
|
+
"ecommerce"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "rm -rf dist && tsup && tsc -p tsconfig.build.json",
|
|
43
|
+
"typecheck": "tsc -p .",
|
|
44
|
+
"test": "vitest run"
|
|
45
|
+
}
|
|
6
46
|
}
|