@devalon.dev/credits 1.0.0 → 1.0.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/LICENSE +21 -0
- package/README.md +26 -2
- package/dist/chunk-IJASKDEW.mjs +1 -0
- package/dist/chunk-PYZQVHOF.mjs +16 -0
- package/dist/chunk-RZ4S6JFB.mjs +11 -0
- package/dist/core/backlink.d.ts +21 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/next/index.d.ts +4 -0
- package/dist/next/index.js +9 -9
- package/dist/next/index.mjs +1 -1
- package/dist/next/source.d.ts +12 -0
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +19 -19
- package/dist/react/index.mjs +1 -1
- package/dist/signals/component.d.ts +16 -0
- package/dist/signals/config.d.ts +9 -0
- package/dist/signals/detect.d.ts +24 -0
- package/dist/signals/event.d.ts +13 -0
- package/dist/signals/index.d.ts +7 -0
- package/dist/signals/index.js +17 -0
- package/dist/signals/index.mjs +17 -0
- package/dist/signals/meta/index.d.ts +3 -0
- package/dist/signals/meta/pixel.d.ts +18 -0
- package/dist/signals/meta/types.d.ts +21 -0
- package/dist/signals/signal.d.ts +9 -0
- package/dist/signals/types.d.ts +26 -0
- package/dist/vite/index.js +23 -23
- package/dist/vite/index.mjs +4 -4
- package/dist/vite/plugin.d.ts +1 -1
- package/docs/nextjs/05-performance-checklist.md +1 -1
- package/docs/nextjs/06-backlink-component.md +50 -27
- package/docs/react/02-csr-vite.md +6 -0
- package/docs/react/03-i18n.md +8 -8
- package/docs/react/05-backlink-component.md +15 -10
- package/docs/react/08-validator.md +1 -1
- package/docs/signals/01-meta-pixel.md +203 -0
- package/package.json +11 -4
- package/scripts/backlink.test.mjs +178 -0
- package/scripts/signals.test.mjs +459 -0
- package/dist/chunk-QU6SEFG7.mjs +0 -16
- package/dist/chunk-YF7SVQTC.mjs +0 -11
|
@@ -28,35 +28,37 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
28
28
|
Rendered HTML:
|
|
29
29
|
|
|
30
30
|
```html
|
|
31
|
-
<span>
|
|
31
|
+
<span>Designed and built by
|
|
32
32
|
<a href="https://devalon.dev" target="_blank" rel="noopener" referrerpolicy="origin">Devalon</a>
|
|
33
33
|
</span>
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
No JavaScript, no image, no hydration. The link is in the static HTML, so crawlers see it without executing anything.
|
|
36
|
+
No JavaScript, no image, no hydration. The link is in the static HTML, so crawlers see it without executing anything. When a source is detected the `href` gains UTM parameters (see below); with no source it stays clean.
|
|
37
37
|
|
|
38
38
|
## Props
|
|
39
39
|
|
|
40
40
|
| Prop | Required | Notes |
|
|
41
41
|
| --- | --- | --- |
|
|
42
|
-
| `site_url` |
|
|
42
|
+
| `site_url` | no | Absolute http(s) URL of the client site. Only its hostname is used, for `utm_source`; `www.` is stripped. Auto-detected when omitted. Invalid explicit URLs throw a `TypeError`. |
|
|
43
43
|
| `locale` | no | One of `en`, `ro`, `ru`, `de`, `da`, `fr`, `es`. Selects the built-in sentence. Defaults to `en`. |
|
|
44
44
|
| `sentence` | no | Overrides the built-in sentence. Must not be empty. |
|
|
45
45
|
| `anchor` | no | Visible link text. Defaults to the brand name `Devalon`. Must not be empty. |
|
|
46
|
-
| `utm` | no | Appends `utm_source` / `utm_medium` / `utm_campaign`. Defaults to **
|
|
46
|
+
| `utm` | no | Appends `utm_source` / `utm_medium` / `utm_campaign`. Defaults to **true**. With no detectable source the link stays clean instead of throwing. Pass `false` to force a clean link. |
|
|
47
47
|
| `className` | no | Your own class for the wrapper `<span>`. The component ships no CSS. |
|
|
48
48
|
|
|
49
49
|
Built-in sentences:
|
|
50
50
|
|
|
51
51
|
| locale | sentence |
|
|
52
52
|
| --- | --- |
|
|
53
|
-
| `en` |
|
|
54
|
-
| `ro` |
|
|
55
|
-
| `ru` |
|
|
56
|
-
| `de` |
|
|
57
|
-
| `da` |
|
|
58
|
-
| `fr` |
|
|
59
|
-
| `es` |
|
|
53
|
+
| `en` | Designed and built by |
|
|
54
|
+
| `ro` | Proiectat și realizat de |
|
|
55
|
+
| `ru` | Дизайн и разработка от |
|
|
56
|
+
| `de` | Entworfen und entwickelt von |
|
|
57
|
+
| `da` | Designet og udviklet af |
|
|
58
|
+
| `fr` | Conçu et développé par |
|
|
59
|
+
| `es` | Diseñado y desarrollado por |
|
|
60
|
+
|
|
61
|
+
Prefer the longer wording? Pass it explicitly, e.g. `sentence="Acest site a fost proiectat și construit de"`.
|
|
60
62
|
|
|
61
63
|
## Any subset of the 7 languages
|
|
62
64
|
|
|
@@ -91,24 +93,44 @@ export default async function LocaleLayout({
|
|
|
91
93
|
}
|
|
92
94
|
```
|
|
93
95
|
|
|
94
|
-
`Locale` from your type guard is a subset of `devalon_locale`, so no cast is needed.
|
|
96
|
+
`Locale` from your type guard is a subset of `devalon_locale`, so no cast is needed. The auto-detected source is site-wide, so it is identical in all languages.
|
|
97
|
+
|
|
98
|
+
## UTM attribution (on by default)
|
|
99
|
+
|
|
100
|
+
`utm` defaults to `true`. The component reads the build-time environment and uses the **hostname only** as `utm_source`:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# .env.local / deployment env
|
|
104
|
+
NEXT_PUBLIC_SITE_URL=https://example.com
|
|
105
|
+
# -> https://devalon.dev/?utm_source=example.com&utm_medium=credit&utm_campaign=devalon-credits
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`NEXT_PUBLIC_SITE_URL` is recommended because Next.js inlines it into both the server and client bundles, so auto-detection never causes a hydration mismatch. The generic `SITE_URL` and platform variables (`VERCEL_PROJECT_PRODUCTION_URL`, `CF_PAGES_URL`, `VERCEL_URL`) are used by the Vite plugin and by HTML-string helpers. Bare hostnames are accepted; paths are ignored. Invalid values are skipped.
|
|
95
109
|
|
|
96
|
-
|
|
110
|
+
With **no** detectable source the link stays clean — `https://devalon.dev` — and nothing throws. Pass `utm={false}` to force a clean link even when a source exists. An explicit `site_url` always wins over detection. The parameters do not change the destination page and do not affect the value of the backlink.
|
|
97
111
|
|
|
98
|
-
|
|
112
|
+
### Live host detection (opt-in, makes the route dynamic)
|
|
99
113
|
|
|
100
|
-
|
|
114
|
+
If you need the request host rather than a build-time value, read it yourself and pass it in. This opts the layout into dynamic rendering, so only do it where that trade-off is acceptable:
|
|
101
115
|
|
|
102
116
|
```tsx
|
|
103
|
-
|
|
104
|
-
|
|
117
|
+
import { headers } from "next/headers";
|
|
118
|
+
import {
|
|
119
|
+
DevalonBacklink,
|
|
120
|
+
devalonBacklinkSiteUrlFromHeaders,
|
|
121
|
+
} from "@devalon.dev/credits/next";
|
|
122
|
+
|
|
123
|
+
export default async function Footer() {
|
|
124
|
+
const site_url = devalonBacklinkSiteUrlFromHeaders(await headers());
|
|
125
|
+
return <DevalonBacklink site_url={site_url} />;
|
|
126
|
+
}
|
|
105
127
|
```
|
|
106
128
|
|
|
107
|
-
The
|
|
129
|
+
The helper returns `undefined` when no usable host is present, which again yields a clean link.
|
|
108
130
|
|
|
109
131
|
## Combine it with the JSON-LD component
|
|
110
132
|
|
|
111
|
-
Use one source of truth for `site_url`
|
|
133
|
+
Use one source of truth for `site_url` in the JSON-LD; the visible credit detects its own source from the environment and stays in agreement:
|
|
112
134
|
|
|
113
135
|
```tsx
|
|
114
136
|
import { DevalonBacklink, DevalonJsonLd } from "@devalon.dev/credits/next";
|
|
@@ -130,7 +152,7 @@ const SITE_NAME = "Example Inc.";
|
|
|
130
152
|
</footer>
|
|
131
153
|
```
|
|
132
154
|
|
|
133
|
-
The JSON-LD renders a `<script>`; the backlink renders an `<a>`. They are independent and can live in different files.
|
|
155
|
+
The JSON-LD renders a `<script>`; the backlink renders an `<a>`. They are independent and can live in different files. Set `NEXT_PUBLIC_SITE_URL` to the same value so the detected backlink source agrees with `SITE_URL` (or pass `site_url={SITE_URL}` to the backlink explicitly).
|
|
134
156
|
|
|
135
157
|
## Pages Router
|
|
136
158
|
|
|
@@ -171,7 +193,7 @@ yarn check:credits https://client.com --deployed # after deployment
|
|
|
171
193
|
|
|
172
194
|
See [07 — Credit link validator](07-validator.md).
|
|
173
195
|
|
|
174
|
-
|
|
196
|
+
If no source is detectable and the link stays clean, create a GA4 **Custom channel group** named `Partner credits` with the rule *Session source matches regex* containing your client domains (`client1\.com|client2\.com|...`). Clean links, clean reporting.
|
|
175
197
|
|
|
176
198
|
## Performance rules
|
|
177
199
|
|
|
@@ -179,7 +201,7 @@ For measurement without UTM, create a GA4 **Custom channel group** named `Partne
|
|
|
179
201
|
- Do not add `"use client"` to the rendering file to style it — use `className`.
|
|
180
202
|
- Do not inject the link with `useEffect` / `document.createElement`; it must exist in the initial HTML.
|
|
181
203
|
- Do not load a remote logo image — that would add a request and a `remotePatterns` config. Text-only is intentional.
|
|
182
|
-
- The output is computed at render time from static props, so static generation bakes it into the HTML. Avoid `cookies()` / `headers()` in that layout.
|
|
204
|
+
- The output is computed at render time from static props plus build-time env, so static generation bakes it into the HTML. Avoid `cookies()` / `headers()` in that layout; the opt-in live-host helper above is the one exception and makes that route dynamic.
|
|
183
205
|
|
|
184
206
|
## Common mistakes
|
|
185
207
|
|
|
@@ -188,16 +210,17 @@ For measurement without UTM, create a GA4 **Custom channel group** named `Partne
|
|
|
188
210
|
| `rel="noopener noreferrer"` | `rel="noopener"` only — `noreferrer` kills referral data. |
|
|
189
211
|
| `rel="nofollow"` / `rel="sponsored"` for a genuine credit | Leave it a follow link. |
|
|
190
212
|
| `display:none`, `font-size:1px`, white-on-white | Keep the text visibly readable. |
|
|
191
|
-
|
|
|
192
|
-
| Pass a relative URL like `/despre` as `site_url` | Pass an absolute `https://...` URL. |
|
|
213
|
+
| Expect UTM with no environment source set | Set `NEXT_PUBLIC_SITE_URL`, or accept the clean link. |
|
|
214
|
+
| Pass a relative URL like `/despre` as `site_url` | Pass an absolute `https://...` URL, or let detection supply it. |
|
|
193
215
|
| Put the credit on a staging or `noindex` site | Run the validator first. |
|
|
194
216
|
|
|
195
217
|
## Verify
|
|
196
218
|
|
|
197
219
|
```bash
|
|
198
220
|
yarn build
|
|
199
|
-
curl -s http://localhost:3000/ | grep -o 'https://devalon.dev' # expect 1 clean link
|
|
200
221
|
curl -s http://localhost:3000/ | grep -o 'rel="noopener"'
|
|
201
|
-
curl -s http://localhost:3000/ro | grep -o '
|
|
202
|
-
curl -s http://localhost:3000/ru | grep -o '
|
|
222
|
+
curl -s http://localhost:3000/ro | grep -o 'Proiectat și realizat de'
|
|
223
|
+
curl -s http://localhost:3000/ru | grep -o 'Дизайн и разработка от'
|
|
224
|
+
# With NEXT_PUBLIC_SITE_URL set, expect an attributed link:
|
|
225
|
+
curl -s http://localhost:3000/ | grep -o 'utm_source=example.com'
|
|
203
226
|
```
|
|
@@ -73,6 +73,12 @@ dist/_headers ← Devalon response headers for Netlify / Cloudflare Pages
|
|
|
73
73
|
|
|
74
74
|
The plugin is **idempotent**: marked blocks are replaced on every build, so repeated builds never duplicate credits. `source` in `agentFilesConfig` is the client's own `llms.txt` text; the Devalon block is merged into it. Existing `_headers` / `vercel.json` content is preserved — see [06 — Server headers](06-server-headers.md).
|
|
75
75
|
|
|
76
|
+
### Backlink source detection
|
|
77
|
+
|
|
78
|
+
UTM attribution is on by default for the injected backlink. The plugin reads the build environment and uses the **hostname only** as `utm_source`. Keys are checked in this order: `NEXT_PUBLIC_SITE_URL`, `SITE_URL`, `VITE_SITE_URL`, `VERCEL_PROJECT_PRODUCTION_URL`, `CF_PAGES_URL`, `VERCEL_URL`. Bare hostnames are accepted, paths and ports are ignored, and invalid values are skipped. With no usable value the link stays clean — no build failure.
|
|
79
|
+
|
|
80
|
+
An explicit `backlink.site_url` always wins over detection, and `backlink: { utm: false }` still forces a clean link. Detection happens at build time, so the output stays a single static HTML document.
|
|
81
|
+
|
|
76
82
|
## Without the plugin
|
|
77
83
|
|
|
78
84
|
`@devalon.dev/credits/react` exposes the pure transform if you prefer to wire your own build step:
|
package/docs/react/03-i18n.md
CHANGED
|
@@ -57,7 +57,7 @@ import { DevalonBacklink } from "@devalon.dev/credits/react";
|
|
|
57
57
|
<DevalonBacklink locale={locale} />
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
The detected source is site-wide and identical in every language — only the hostname becomes `utm_source`, so a different root would split your referral data. If you pass `site_url` explicitly, keep it identical across locales.
|
|
61
61
|
|
|
62
62
|
## Per-request headers
|
|
63
63
|
|
|
@@ -84,13 +84,13 @@ See [06 — Server headers](06-server-headers.md) for Express / CDN variants.
|
|
|
84
84
|
|
|
85
85
|
| locale | sentence |
|
|
86
86
|
| --- | --- |
|
|
87
|
-
| `en` |
|
|
88
|
-
| `ro` |
|
|
89
|
-
| `ru` |
|
|
90
|
-
| `de` |
|
|
91
|
-
| `da` |
|
|
92
|
-
| `fr` |
|
|
93
|
-
| `es` |
|
|
87
|
+
| `en` | Designed and built by |
|
|
88
|
+
| `ro` | Proiectat și realizat de |
|
|
89
|
+
| `ru` | Дизайн и разработка от |
|
|
90
|
+
| `de` | Entworfen und entwickelt von |
|
|
91
|
+
| `da` | Designet og udviklet af |
|
|
92
|
+
| `fr` | Conçu et développé par |
|
|
93
|
+
| `es` | Diseñado y desarrollado por |
|
|
94
94
|
|
|
95
95
|
Override any of them with `sentence`, or pass `anchor` to change the link text.
|
|
96
96
|
|
|
@@ -21,7 +21,7 @@ export function Footer() {
|
|
|
21
21
|
Rendered HTML:
|
|
22
22
|
|
|
23
23
|
```html
|
|
24
|
-
<span>
|
|
24
|
+
<span>Proiectat și realizat de
|
|
25
25
|
<a href="https://devalon.dev" target="_blank" rel="noopener" referrerpolicy="origin">Devalon</a>
|
|
26
26
|
</span>
|
|
27
27
|
```
|
|
@@ -36,7 +36,7 @@ When the body of your document is assembled as a string (custom SSR template, st
|
|
|
36
36
|
import { devalonBacklinkHtml } from "@devalon.dev/credits/react";
|
|
37
37
|
|
|
38
38
|
const credit = devalonBacklinkHtml({ locale: "ro", className: "credit" });
|
|
39
|
-
// <span class="credit">
|
|
39
|
+
// <span class="credit">Proiectat și realizat de <a href="https://devalon.dev" ...>Devalon</a></span>
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
Or inject it automatically with `devalonInjectHtml(html, { ..., backlink: { locale: "ro" } })` — see [01 — SSR setup](01-ssr-setup.md) and [02 — CSR / Vite](02-csr-vite.md).
|
|
@@ -45,21 +45,26 @@ Or inject it automatically with `devalonInjectHtml(html, { ..., backlink: { loca
|
|
|
45
45
|
|
|
46
46
|
| Prop | Required | Notes |
|
|
47
47
|
| --- | --- | --- |
|
|
48
|
-
| `site_url` |
|
|
48
|
+
| `site_url` | no | Absolute http(s) URL of the client site. Only its hostname is used, for `utm_source`; `www.` is stripped. Auto-detected when omitted. Invalid explicit URLs throw a `TypeError`. |
|
|
49
49
|
| `locale` | no | One of `en`, `ro`, `ru`, `de`, `da`, `fr`, `es`. Selects the built-in sentence. Defaults to `en`. |
|
|
50
50
|
| `sentence` | no | Overrides the built-in sentence. Must not be empty. |
|
|
51
51
|
| `anchor` | no | Visible link text. Defaults to `Devalon`. Must not be empty. |
|
|
52
|
-
| `utm` | no | Appends `utm_source` / `utm_medium` / `utm_campaign`. Defaults to **
|
|
52
|
+
| `utm` | no | Appends `utm_source` / `utm_medium` / `utm_campaign`. Defaults to **true**. With no detectable source the link stays clean instead of throwing. Pass `false` to force a clean link. |
|
|
53
53
|
| `className` | no | Your class for the wrapper `<span>`. The component ships no CSS. |
|
|
54
54
|
|
|
55
|
-
##
|
|
55
|
+
## UTM attribution (on by default)
|
|
56
|
+
|
|
57
|
+
`utm` defaults to `true`. In Node SSR and HTML-string helpers the source is detected from `process.env`; in the browser there is no server environment, so the Vite plugin bakes the source into the HTML at build time. Only the hostname is used:
|
|
56
58
|
|
|
57
59
|
```tsx
|
|
58
|
-
<DevalonBacklink
|
|
60
|
+
<DevalonBacklink />
|
|
61
|
+
// with SITE_URL=https://example.com/ro in the build environment:
|
|
59
62
|
// https://devalon.dev/?utm_source=example.com&utm_medium=credit&utm_campaign=devalon-credits
|
|
60
63
|
```
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
Env keys, in priority order: `NEXT_PUBLIC_SITE_URL`, `SITE_URL`, `VITE_SITE_URL`, `VERCEL_PROJECT_PRODUCTION_URL`, `CF_PAGES_URL`, `VERCEL_URL`. Bare hostnames are accepted, paths are ignored, invalid values are skipped. An explicit `site_url` wins over detection. With no detectable source the link stays clean. UTM does not change the destination page or the value of the backlink.
|
|
66
|
+
|
|
67
|
+
Use `detect_site_url(env)` from either entrypoint to inspect what would be detected for a given env object.
|
|
63
68
|
|
|
64
69
|
## Quality rules
|
|
65
70
|
|
|
@@ -76,14 +81,14 @@ UTM does not change the destination page and does not affect the value of the ba
|
|
|
76
81
|
| `rel="noopener noreferrer"` | `rel="noopener"` only — `noreferrer` kills referral data. |
|
|
77
82
|
| `rel="nofollow"` for a genuine credit | Leave it a follow link. |
|
|
78
83
|
| `display:none`, white-on-white | Keep the text visibly readable. |
|
|
79
|
-
|
|
|
80
|
-
| Pass a relative `site_url` | Pass an absolute `https://...` URL. |
|
|
84
|
+
| Expect UTM with no environment source set | Set a build-time env var, or accept the clean link. |
|
|
85
|
+
| Pass a relative `site_url` | Pass an absolute `https://...` URL, or let detection supply it. |
|
|
81
86
|
| Put the credit on a `noindex` staging site | Run the validator first — [08 — Validator](08-validator.md). |
|
|
82
87
|
|
|
83
88
|
## Verify
|
|
84
89
|
|
|
85
90
|
```bash
|
|
86
91
|
curl -s http://localhost:3000/ | grep -o 'rel="noopener"'
|
|
87
|
-
curl -s http://localhost:3000/ro | grep -o '
|
|
92
|
+
curl -s http://localhost:3000/ro | grep -o 'Proiectat și realizat de'
|
|
88
93
|
curl -s http://localhost:3000/ | grep -o 'https://devalon.dev' | wc -l # expect 1 in the body credit
|
|
89
94
|
```
|
|
@@ -42,7 +42,7 @@ Only put the credit on sites that are live, indexed and have real traffic. A cre
|
|
|
42
42
|
|
|
43
43
|
- Keep one canonical `site_url` per client across all integrations (JSON-LD, headers, `llms.txt`, backlink UTM).
|
|
44
44
|
- Re-run the validator after each deployment.
|
|
45
|
-
-
|
|
45
|
+
- With UTM on by default, create a GA4 **Custom channel group** named `Partner credits` with *Session source matches regex* containing your client domains (`client1\.com|client2\.com|...`). If no source was detectable and the link stayed clean, the default referral report is enough.
|
|
46
46
|
|
|
47
47
|
## Common failures
|
|
48
48
|
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# Signals — Meta Pixel usage guide
|
|
2
|
+
|
|
3
|
+
`@devalon.dev/credits/signals` loads the Meta Pixel into a website and lets you
|
|
4
|
+
track user actions with one function. It works in Next.js, React and Vite.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @devalon.dev/credits
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 1. Load the pixel once
|
|
13
|
+
|
|
14
|
+
Get the numeric Pixel ID from **Meta Events Manager → Data Sources → your Pixel
|
|
15
|
+
→ Settings** (for example `1683475309995701`).
|
|
16
|
+
|
|
17
|
+
### Next.js App Router
|
|
18
|
+
|
|
19
|
+
Put it once in the root layout:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
// app/layout.tsx
|
|
23
|
+
import { DevalonSignal } from "@devalon.dev/credits/signals";
|
|
24
|
+
|
|
25
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
26
|
+
return (
|
|
27
|
+
<html lang="en">
|
|
28
|
+
<body>
|
|
29
|
+
{children}
|
|
30
|
+
<DevalonSignal pixelId="1683475309995701" />
|
|
31
|
+
</body>
|
|
32
|
+
</html>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
No `"use client"` needed here. The initial `PageView` is sent automatically.
|
|
38
|
+
|
|
39
|
+
### Next.js Pages Router
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
// pages/_app.tsx
|
|
43
|
+
import { DevalonSignal } from "@devalon.dev/credits/signals";
|
|
44
|
+
|
|
45
|
+
export default function App({ Component, pageProps }) {
|
|
46
|
+
return (
|
|
47
|
+
<>
|
|
48
|
+
<Component {...pageProps} />
|
|
49
|
+
<DevalonSignal pixelId="1683475309995701" />
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### React with SSR
|
|
56
|
+
|
|
57
|
+
Render `<DevalonSignal pixelId="1683475309995701" />` once in your document
|
|
58
|
+
template.
|
|
59
|
+
|
|
60
|
+
### Vite (client-only)
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
// src/main.tsx
|
|
64
|
+
import { loadMetaPixel } from "@devalon.dev/credits/signals";
|
|
65
|
+
|
|
66
|
+
loadMetaPixel("1683475309995701");
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Call it once before rendering the app.
|
|
70
|
+
|
|
71
|
+
### Strict CSP
|
|
72
|
+
|
|
73
|
+
Pass the same nonce you use for other inline scripts:
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
<DevalonSignal pixelId="1683475309995701" nonce={nonce} />
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 2. Track actions
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
"use client";
|
|
83
|
+
import { signal } from "@devalon.dev/credits/signals";
|
|
84
|
+
|
|
85
|
+
export function TrackButton() {
|
|
86
|
+
return (
|
|
87
|
+
<button onClick={() => signal("HeroCtaClick", { button_id: "hero" }, { debug: true })}>
|
|
88
|
+
Try it free
|
|
89
|
+
</button>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Other common uses:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
signal("Lead", { source: "contact-form" }); // form submit
|
|
98
|
+
signal("Purchase", { value: 29.99, currency: "USD", content_ids: ["sku_1"] });
|
|
99
|
+
signal("VideoPlay", { video_id: "intro" }); // custom event
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`signal()` returns an object you can use for server-side tracking:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
{ event_name: "Purchase", event_id: "…", params: { … }, emitted_at: "…" }
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Options (third argument)
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
signal("Purchase", { value: 29.99 }, {
|
|
112
|
+
debug: true, // console logs — use in development
|
|
113
|
+
eventId: "saved-id", // reuse an id (e.g. after a redirect)
|
|
114
|
+
pixelId: "1683475309995701", // override the configured pixel
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## 3. Event names
|
|
119
|
+
|
|
120
|
+
**Meta standard events** (use these for conversion reporting):
|
|
121
|
+
|
|
122
|
+
`PageView`, `ViewContent`, `Search`, `AddToCart`, `AddToWishlist`,
|
|
123
|
+
`InitiateCheckout`, `AddPaymentInfo`, `Purchase`, `Lead`,
|
|
124
|
+
`CompleteRegistration`, `Contact`, `CustomizeProduct`, `Donate`, `FindLocation`,
|
|
125
|
+
`Schedule`, `StartTrial`, `SubmitApplication`, `Subscribe`.
|
|
126
|
+
|
|
127
|
+
For `Purchase`, `AddToCart`, `Donate`, `Subscribe`, `StartTrial` and similar,
|
|
128
|
+
always send `value` and `currency` together. `ViewContent` expects
|
|
129
|
+
`content_ids`; `Search` expects `search_string`.
|
|
130
|
+
|
|
131
|
+
**Custom events** — use the shared catalog for common names:
|
|
132
|
+
|
|
133
|
+
`HeroCtaClick`, `ButtonClick`, `FormSubmit`, `DemoRequest`, `NewsletterSignup`,
|
|
134
|
+
`ProductView`, `VideoPlay`, `PhoneClick`, `EmailClick`, `LoginSuccess`,
|
|
135
|
+
`ApiError`, `PopupView`, and 110+ more in `DEVALON_CUSTOM_EVENT_NAMES`.
|
|
136
|
+
|
|
137
|
+
Any other string works too — you are not limited to the catalog:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
signal("MyNewAction", { step: 1 });
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 4. Debug logs
|
|
144
|
+
|
|
145
|
+
Add `{ debug: true }` while developing. Each event logs one of these:
|
|
146
|
+
|
|
147
|
+
| Log | Meaning | What to do |
|
|
148
|
+
| --- | --- | --- |
|
|
149
|
+
| `✓ Pixel <id>` | Event accepted by Meta | Nothing |
|
|
150
|
+
| `BLOCKED ✗ … send via CAPI` | Pixel script blocked (ad blocker, filter) | Send the reported `event_id` through CAPI |
|
|
151
|
+
| `MISSING ✗ … send via CAPI` | Pixel not loaded at all | Check the setup above and CSP |
|
|
152
|
+
| `no Devalon pixel id configured` | Pixel ID unknown in the browser | Render `DevalonSignal` or call `loadMetaPixel()` first |
|
|
153
|
+
| `⚠ missing recommended params` | Standard event lacks `value`/`currency` etc. (event is still sent) | Add the expected params |
|
|
154
|
+
|
|
155
|
+
Without `debug: true`, `signal()` is silent.
|
|
156
|
+
|
|
157
|
+
## 5. CAPI deduplication (quick version)
|
|
158
|
+
|
|
159
|
+
If you also send the event from your server, use the **same `event_name` and
|
|
160
|
+
`event_id`** in both places — Meta then counts one conversion, not two.
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
"use client";
|
|
164
|
+
import { signal } from "@devalon.dev/credits/signals";
|
|
165
|
+
|
|
166
|
+
async function onPurchase() {
|
|
167
|
+
const event = signal("Purchase", { value: 29.99, currency: "USD" }, { debug: true });
|
|
168
|
+
|
|
169
|
+
await fetch("/api/capi", {
|
|
170
|
+
method: "POST",
|
|
171
|
+
headers: { "content-type": "application/json" },
|
|
172
|
+
body: JSON.stringify(event), // forward event_id to your server
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Your endpoint posts to Meta with `event_name: event.event_name`,
|
|
178
|
+
`event_id: event.event_id`, `event_time`, `action_source: "website"` and hashed
|
|
179
|
+
`user_data`. Never put the CAPI access token in browser code.
|
|
180
|
+
|
|
181
|
+
## 6. Tips and common mistakes
|
|
182
|
+
|
|
183
|
+
- Mount the loader **once per page load**. Two mounts send two `PageView`s.
|
|
184
|
+
- Do **not** also install the same Pixel through GTM or another tag manager.
|
|
185
|
+
- Calls to `signal()` belong in event handlers, effects or Client Components —
|
|
186
|
+
never in a Server Component.
|
|
187
|
+
- Use `pixelId` only when overriding; normally the ID is already configured.
|
|
188
|
+
- Events are scoped to Devalon's Pixel, even when other Meta Pixels are on the
|
|
189
|
+
page — do not add manual `fbq('track', …)` calls for the same actions.
|
|
190
|
+
- If the Pixel is blocked for a user, the debug log gives you the `event_id` to
|
|
191
|
+
send through CAPI — keep that path in place for conversions that matter.
|
|
192
|
+
- Verify with **Meta Events Manager → Test Events** before going live.
|
|
193
|
+
|
|
194
|
+
## Quick reference
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import {
|
|
198
|
+
DevalonSignal, // loader component (server-rendered)
|
|
199
|
+
loadMetaPixel, // loader for Vite CSR
|
|
200
|
+
signal, // send an event
|
|
201
|
+
DEVALON_CUSTOM_EVENT_NAMES, // custom event name list
|
|
202
|
+
} from "@devalon.dev/credits/signals";
|
|
203
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devalon.dev/credits",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Devalon technology-partner attribution for Next.js, React and Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -27,6 +27,11 @@
|
|
|
27
27
|
"types": "./dist/vite/index.d.ts",
|
|
28
28
|
"import": "./dist/vite/index.mjs",
|
|
29
29
|
"require": "./dist/vite/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./signals": {
|
|
32
|
+
"types": "./dist/signals/index.d.ts",
|
|
33
|
+
"import": "./dist/signals/index.mjs",
|
|
34
|
+
"require": "./dist/signals/index.js"
|
|
30
35
|
}
|
|
31
36
|
},
|
|
32
37
|
"files": [
|
|
@@ -34,17 +39,19 @@
|
|
|
34
39
|
"README.md",
|
|
35
40
|
"docs/nextjs",
|
|
36
41
|
"docs/react",
|
|
42
|
+
"docs/signals",
|
|
37
43
|
"scripts",
|
|
38
44
|
"!.env",
|
|
39
45
|
"!.env.*"
|
|
40
46
|
],
|
|
41
47
|
"bin": {
|
|
42
|
-
"devalon-check": "
|
|
48
|
+
"devalon-check": "scripts/check-devalon-credits.mjs"
|
|
43
49
|
},
|
|
44
50
|
"scripts": {
|
|
45
|
-
"build": "tsup src/index.ts src/next/index.ts src/react/index.ts src/vite/index.ts --format esm,cjs --clean --minify && tsc --emitDeclarationOnly --declarationMap false --outDir dist && rm -rf dist/src",
|
|
46
|
-
"dev": "tsup src/index.ts src/next/index.ts src/react/index.ts src/vite/index.ts --format esm,cjs --watch",
|
|
51
|
+
"build": "tsup src/index.ts src/next/index.ts src/react/index.ts src/vite/index.ts src/signals/index.ts --format esm,cjs --clean --minify && tsc --emitDeclarationOnly --declarationMap false --outDir dist && rm -rf dist/src",
|
|
52
|
+
"dev": "tsup src/index.ts src/next/index.ts src/react/index.ts src/vite/index.ts src/signals/index.ts --format esm,cjs --watch",
|
|
47
53
|
"check:credits": "node scripts/check-devalon-credits.mjs",
|
|
54
|
+
"test": "yarn build && node --test scripts/*.test.mjs",
|
|
48
55
|
"prepublishOnly": "yarn build"
|
|
49
56
|
},
|
|
50
57
|
"peerDependencies": {
|