@traqio/web 0.0.0-stage → 0.1.1
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 +127 -2
- package/build/cookies.d.ts +13 -0
- package/build/index.cjs +1491 -0
- package/build/index.cjs.map +7 -0
- package/build/index.d.ts +83 -0
- package/build/index.js +1484 -0
- package/build/index.js.map +7 -0
- package/build/snippet.d.ts +6 -0
- package/build/storage.d.ts +46 -0
- package/build/test/fakeBrowser.d.ts +25 -0
- package/build/trackId.d.ts +35 -0
- package/build/traqio.min.js +2 -0
- package/build/traqio.min.js.map +7 -0
- package/package.json +53 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Khufu FZCO
|
|
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,128 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @traqio/web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The browser SDK of [Traqio](https://traqio.app), for websites and web apps — React,
|
|
4
|
+
Vue, Angular, Svelte or plain HTML. Its main job is the **trackID**: when a visitor
|
|
5
|
+
arrives from a Traqio tracking link, the landing URL carries the ad click id as
|
|
6
|
+
`traq_click`. This package reads it, keeps it in **first-party** storage (localStorage,
|
|
7
|
+
plus a cookie on your own domain) and hands it back when the visitor converts — so the
|
|
8
|
+
conversion is tied to its click **deterministically**, not by guesswork.
|
|
9
|
+
|
|
10
|
+
It also records web events and visits, with consent handling and in-page erasure. No
|
|
11
|
+
fingerprinting, no third-party cookie, no advertising id. ~7 KB gzipped, no dependency.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @traqio/web
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or without a build step, with a `<script>` tag (it initialises itself from the
|
|
20
|
+
`data-` attributes and exposes `window.Traqio`):
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<script src="https://cdn.jsdelivr.net/npm/@traqio/web@0.1/build/traqio.min.js"
|
|
24
|
+
data-sdk-key="YOUR_WEB_KEY" async></script>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Initialize
|
|
28
|
+
|
|
29
|
+
Call `init()` once, as early as possible, on every page (once at start-up in a
|
|
30
|
+
single-page app). It is safe during server-side rendering: on a server it does nothing.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { Traqio } from "@traqio/web";
|
|
34
|
+
|
|
35
|
+
Traqio.init({ sdkKey: "YOUR_WEB_KEY" }); // a web key (tq_web_…) from the Traqio console
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Use a web key.** It is public — it sits in your page — so it is protected by its list
|
|
39
|
+
of allowed origins instead of a secret: the Traqio API accepts it only from the
|
|
40
|
+
origins you declared for it (`https://example.com`, `https://app.example.com`).
|
|
41
|
+
Declare every origin that runs the SDK, one by one.
|
|
42
|
+
|
|
43
|
+
## The trackID, at conversion time
|
|
44
|
+
|
|
45
|
+
The conversion that counts (a sign-up, a subscription, a purchase) usually happens on
|
|
46
|
+
your **backend**, where the user id is known. Two ways to get the trackID there:
|
|
47
|
+
|
|
48
|
+
1. **Read the cookie.** The SDK writes `traq_click` on your registrable domain
|
|
49
|
+
(`example.com`), so your backend receives it with the sign-up request itself —
|
|
50
|
+
read it like any other cookie.
|
|
51
|
+
2. **Pass it explicitly**, e.g. in a hidden form field:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const trackId = Traqio.getTrackId(); // null when the visitor did not come from an ad
|
|
55
|
+
form.querySelector<HTMLInputElement>('input[name="traq_click"]')!.value = trackId ?? "";
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The browser SDK never sends the trackID itself: a key that anyone can read in your page
|
|
59
|
+
must not be able to credit a campaign. Your backend sends the conversion with its
|
|
60
|
+
trackID using a **secret** server key.
|
|
61
|
+
|
|
62
|
+
## Track events
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
Traqio.setUserId(user.id); // after sign-in
|
|
66
|
+
|
|
67
|
+
Traqio.track("add_to_cart");
|
|
68
|
+
Traqio.track("purchase", { value: 49, currency: "EUR", transactionId: payment.id, store: "stripe" });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Report the sign-up from your backend** (`signup()` in a server SDK), not from the
|
|
72
|
+
browser: it is your site's conversion — each new user counts once, at their first
|
|
73
|
+
sign-up — and the server knows the user. Send `Traqio.track("signup")` from the browser
|
|
74
|
+
only if you have no backend; sending it from both would count the same person twice,
|
|
75
|
+
because a browser and a signed-in user are not tied together yet.
|
|
76
|
+
|
|
77
|
+
Events are batched, retried, kept across page loads, and flushed when the tab is
|
|
78
|
+
hidden or the page is left.
|
|
79
|
+
|
|
80
|
+
## Frameworks
|
|
81
|
+
|
|
82
|
+
- **React / Next.js** — call `init()` in a `useEffect` of a client component mounted
|
|
83
|
+
once (in Next's App Router, a `"use client"` component in the root layout).
|
|
84
|
+
- **Vue / Nuxt** — call it in `main.ts` before `app.mount()`, or in a Nuxt plugin
|
|
85
|
+
named `traqio.client.ts`.
|
|
86
|
+
- **Angular** — call it in an app initializer, guarded by `isPlatformBrowser` when you
|
|
87
|
+
use SSR.
|
|
88
|
+
- **Plain HTML** — the `<script>` tag above.
|
|
89
|
+
|
|
90
|
+
## Consent
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
Traqio.init({ sdkKey: "YOUR_WEB_KEY", waitForConsent: true });
|
|
94
|
+
// … when your banner gets an answer:
|
|
95
|
+
Traqio.setConsent(true); // stores what the page kept in memory, trackID included
|
|
96
|
+
Traqio.setConsent(false); // removes everything the SDK stored on the device
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
With `waitForConsent`, nothing is written to the device — no localStorage, no
|
|
100
|
+
cookie — until `setConsent(true)`; the SDK still works for the current page, in memory.
|
|
101
|
+
`setConsent` also governs whether data about this visitor may be shared with ad
|
|
102
|
+
networks.
|
|
103
|
+
|
|
104
|
+
## Options
|
|
105
|
+
|
|
106
|
+
| Option | Default | |
|
|
107
|
+
| --- | --- | --- |
|
|
108
|
+
| `sdkKey` | — | Your web key (required) |
|
|
109
|
+
| `endpoint` | `https://api.traqio.app` | Origin of the Traqio API |
|
|
110
|
+
| `userId` | — | Your user id, once known |
|
|
111
|
+
| `consent` | not collected | The visitor's consent, if already known |
|
|
112
|
+
| `waitForConsent` | `false` | Store nothing until `setConsent(true)` |
|
|
113
|
+
| `trackIdDays` | `30` | How long the trackID is kept after the click |
|
|
114
|
+
| `cookies` | `true` | `false` = localStorage only, no sharing across subdomains |
|
|
115
|
+
|
|
116
|
+
## Requirements
|
|
117
|
+
|
|
118
|
+
Any browser with `fetch` and `localStorage` (every evergreen browser). ES2019 output.
|
|
119
|
+
Ships as ESM, CommonJS and a self-contained `<script>` build, with TypeScript types.
|
|
120
|
+
|
|
121
|
+
## Documentation
|
|
122
|
+
|
|
123
|
+
Full guide, per-framework set-up and how attribution works:
|
|
124
|
+
https://traqio.app/docs/sdks/web
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Every cookie the SDK writes carries this prefix — the same namespace as the URL. */
|
|
2
|
+
export declare const COOKIE_PREFIX = "traq_";
|
|
3
|
+
export declare function readCookie(name: string): string | null;
|
|
4
|
+
/**
|
|
5
|
+
* The widest domain this page may set a cookie on — `example.co.uk` for
|
|
6
|
+
* `shop.example.co.uk`. There is no public-suffix list in a browser, so ask the
|
|
7
|
+
* browser itself: try the shortest candidates first, and keep the first one it
|
|
8
|
+
* accepts (it refuses `co.uk`, a public suffix). Null on `localhost` and IP
|
|
9
|
+
* addresses, where a host-only cookie is the only kind there is.
|
|
10
|
+
*/
|
|
11
|
+
export declare function registrableDomain(hostname: string): string | null;
|
|
12
|
+
export declare function writeCookie(name: string, value: string, maxAgeSeconds: number, domain: string | null): void;
|
|
13
|
+
export declare function deleteCookie(name: string, domain: string | null): void;
|