pegada 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 +83 -2
- package/dist/index.d.ts +32 -0
- package/dist/index.js +43 -0
- package/package.json +32 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rafael Augusto Franco Desenvolvimento de Software Ltda
|
|
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,84 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pegada
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
SDK de servidor do [Pegada](https://pegada.dev), analytics sem cookies e sem guardar IP.
|
|
4
|
+
|
|
5
|
+
Use para mandar eventos do seu backend: pagamento confirmado, cadastro concluído, partida terminada. Eles entram na mesma visita que o script do navegador conta.
|
|
6
|
+
|
|
7
|
+
- Sem dependências.
|
|
8
|
+
- Nunca lança erro: se o Pegada estiver fora do ar, seu app segue funcionando.
|
|
9
|
+
- Funciona em Node 18+, Bun, Deno, Cloudflare Workers e Lambda (qualquer lugar com `fetch`).
|
|
10
|
+
|
|
11
|
+
## Instalação
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install pegada
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Uso
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { createPegada } from "pegada";
|
|
21
|
+
|
|
22
|
+
const pegada = createPegada({ key: process.env.PEGADA_KEY });
|
|
23
|
+
|
|
24
|
+
await pegada.track(
|
|
25
|
+
"pagamento_confirmado",
|
|
26
|
+
{ plano: "pro", valor: 49 },
|
|
27
|
+
{ ip: request.ip, userAgent: request.headers["user-agent"] },
|
|
28
|
+
);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
A chave do site (`pgd_sk_...`) fica em **Configurações** no [painel](https://pegada.dev/painel). Ela é secreta: use só no servidor, nunca no navegador.
|
|
32
|
+
|
|
33
|
+
O IP e o user agent de quem fez a ação servem para ligar o evento à visita da pessoa. O Pegada não guarda nenhum dos dois: eles viram um código e são descartados.
|
|
34
|
+
|
|
35
|
+
### Vários eventos de uma vez
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
await pegada.trackMany([
|
|
39
|
+
{ name: "item_adicionado", props: { sku: "A12" } },
|
|
40
|
+
{ name: "checkout_iniciado", props: { itens: 3 }, context: { ip, userAgent } },
|
|
41
|
+
]);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Até 50 eventos por chamada.
|
|
45
|
+
|
|
46
|
+
## Opções
|
|
47
|
+
|
|
48
|
+
| Opção | Padrão | O que faz |
|
|
49
|
+
| ----------- | ------------------------------- | ------------------------------------------------ |
|
|
50
|
+
| `key` | | Chave do site. Sem ela, nada é enviado. |
|
|
51
|
+
| `endpoint` | `https://pegada.dev/api/track` | Endereço da API. |
|
|
52
|
+
| `timeoutMs` | `2000` | Tempo máximo de cada envio. |
|
|
53
|
+
| `onError` | | Recebe falhas de rede ou respostas de erro. |
|
|
54
|
+
|
|
55
|
+
## Contexto do evento
|
|
56
|
+
|
|
57
|
+
O terceiro argumento de `track` é opcional:
|
|
58
|
+
|
|
59
|
+
| Campo | O que é |
|
|
60
|
+
| ----------- | --------------------------------------------------------- |
|
|
61
|
+
| `ip` | IP de quem fez a ação |
|
|
62
|
+
| `userAgent` | User agent de quem fez a ação |
|
|
63
|
+
| `path` | Página relacionada |
|
|
64
|
+
| `at` | Quando aconteceu (`Date` ou ISO, até 24 h atrás) |
|
|
65
|
+
| `country` | Código ISO do país, se você souber |
|
|
66
|
+
|
|
67
|
+
Propriedades aceitam texto, número e booleano. Não mande dados pessoais nelas, como nome, e-mail ou CPF.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## English
|
|
72
|
+
|
|
73
|
+
Server SDK for [Pegada](https://pegada.dev), cookie-free analytics. Send backend events (payments, sign-ups) that join the visitor's browser session. No dependencies, never throws.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { createPegada } from "pegada";
|
|
77
|
+
|
|
78
|
+
const pegada = createPegada({ key: process.env.PEGADA_KEY });
|
|
79
|
+
await pegada.track("payment_confirmed", { plan: "pro" }, { ip, userAgent });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Licença
|
|
83
|
+
|
|
84
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type Props = Record<string, string | number | boolean>;
|
|
2
|
+
export interface TrackContext {
|
|
3
|
+
/** IP do usuário final (ex.: requestContext.identity.sourceIp numa Lambda) */
|
|
4
|
+
ip?: string;
|
|
5
|
+
/** User agent do usuário final */
|
|
6
|
+
userAgent?: string;
|
|
7
|
+
/** Página relacionada, se houver */
|
|
8
|
+
path?: string;
|
|
9
|
+
/** Quando aconteceu (até 24 h atrás); padrão: agora */
|
|
10
|
+
at?: Date | string;
|
|
11
|
+
/** Código ISO do país, se você souber */
|
|
12
|
+
country?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PegadaOptions {
|
|
15
|
+
/** Chave secreta do site (pgd_sk_...) */
|
|
16
|
+
key: string | undefined;
|
|
17
|
+
/** Padrão: https://pegada.dev/api/track */
|
|
18
|
+
endpoint?: string;
|
|
19
|
+
/** Tempo máximo por envio; padrão 2 s */
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
onError?: (error: unknown) => void;
|
|
22
|
+
}
|
|
23
|
+
export declare function createPegada({ key, endpoint, timeoutMs, onError }: PegadaOptions): {
|
|
24
|
+
/** Um evento */
|
|
25
|
+
track(name: string, props?: Props, context?: TrackContext): Promise<void>;
|
|
26
|
+
/** Vários de uma vez (até 50) */
|
|
27
|
+
trackMany(events: {
|
|
28
|
+
name: string;
|
|
29
|
+
props?: Props;
|
|
30
|
+
context?: TrackContext;
|
|
31
|
+
}[]): Promise<void>;
|
|
32
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SDK de servidor do Pegada. Sem dependências: dá para copiar este arquivo para o projeto.
|
|
2
|
+
//
|
|
3
|
+
// const pegada = createPegada({ key: process.env.PEGADA_KEY });
|
|
4
|
+
// await pegada.track("partida_terminou", { resultado: "vitoria", lances: 34 }, { ip, userAgent });
|
|
5
|
+
//
|
|
6
|
+
// O IP e o user agent do usuário final servem só para o hash do visitante (o mesmo que o
|
|
7
|
+
// script do navegador gera), assim os eventos do servidor se juntam à visita dele. O Pegada
|
|
8
|
+
// não guarda nenhum dos dois. track nunca lança erro: analytics não pode derrubar o app.
|
|
9
|
+
export function createPegada({ key, endpoint = "https://pegada.dev/api/track", timeoutMs = 2000, onError }) {
|
|
10
|
+
async function send(body) {
|
|
11
|
+
if (!key)
|
|
12
|
+
return;
|
|
13
|
+
try {
|
|
14
|
+
const response = await fetch(endpoint, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
|
|
17
|
+
body: JSON.stringify(body),
|
|
18
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok)
|
|
21
|
+
onError?.(new Error(`Pegada respondeu ${response.status}: ${await response.text()}`));
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
onError?.(error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const event = (name, props = {}, context = {}) => ({
|
|
28
|
+
name,
|
|
29
|
+
props,
|
|
30
|
+
...context,
|
|
31
|
+
at: context.at instanceof Date ? context.at.toISOString() : context.at,
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
/** Um evento */
|
|
35
|
+
track(name, props, context) {
|
|
36
|
+
return send(event(name, props, context));
|
|
37
|
+
},
|
|
38
|
+
/** Vários de uma vez (até 50) */
|
|
39
|
+
trackMany(events) {
|
|
40
|
+
return send({ events: events.map((e) => event(e.name, e.props, e.context)) });
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pegada",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SDK de servidor do Pegada: eventos do backend no analytics sem cookies",
|
|
5
|
+
"keywords": ["analytics", "privacy", "lgpd", "events", "server", "pegada"],
|
|
6
|
+
"homepage": "https://pegada.dev",
|
|
7
|
+
"bugs": "mailto:suporte@pegada.dev",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"author": "Pegada <suporte@pegada.dev>",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"files": ["dist"],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"prepublishOnly": "pnpm run typecheck && pnpm run build"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@tsconfig/node24": "^24.0.5",
|
|
31
|
+
"@types/node": "^26.6.5",
|
|
32
|
+
"typescript": "^7.0.2"
|
|
33
|
+
}
|
|
34
|
+
}
|