@intlayer/analytics 9.0.0-canary.16
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/README.md +330 -0
- package/dist/cjs/core/AnalyticsClient.cjs +182 -0
- package/dist/cjs/core/AnalyticsClient.cjs.map +1 -0
- package/dist/cjs/core/abTesting.cjs +44 -0
- package/dist/cjs/core/abTesting.cjs.map +1 -0
- package/dist/cjs/core/eventBuffer.cjs +68 -0
- package/dist/cjs/core/eventBuffer.cjs.map +1 -0
- package/dist/cjs/core/globalManager.cjs +63 -0
- package/dist/cjs/core/globalManager.cjs.map +1 -0
- package/dist/cjs/core/index.cjs +26 -0
- package/dist/cjs/core/initAnalyticsClient.cjs +51 -0
- package/dist/cjs/core/initAnalyticsClient.cjs.map +1 -0
- package/dist/cjs/core/sampling.cjs +28 -0
- package/dist/cjs/core/sampling.cjs.map +1 -0
- package/dist/cjs/core/session.cjs +42 -0
- package/dist/cjs/core/session.cjs.map +1 -0
- package/dist/cjs/core/transport.cjs +47 -0
- package/dist/cjs/core/transport.cjs.map +1 -0
- package/dist/cjs/core/types.cjs +0 -0
- package/dist/cjs/events/contentExposure.cjs +39 -0
- package/dist/cjs/events/contentExposure.cjs.map +1 -0
- package/dist/cjs/index.cjs +29 -0
- package/dist/cjs/isEnabled.cjs +29 -0
- package/dist/cjs/isEnabled.cjs.map +1 -0
- package/dist/cjs/utils/hash.cjs +26 -0
- package/dist/cjs/utils/hash.cjs.map +1 -0
- package/dist/cjs/utils/idle.cjs +26 -0
- package/dist/cjs/utils/idle.cjs.map +1 -0
- package/dist/esm/core/AnalyticsClient.mjs +177 -0
- package/dist/esm/core/AnalyticsClient.mjs.map +1 -0
- package/dist/esm/core/abTesting.mjs +43 -0
- package/dist/esm/core/abTesting.mjs.map +1 -0
- package/dist/esm/core/eventBuffer.mjs +66 -0
- package/dist/esm/core/eventBuffer.mjs.map +1 -0
- package/dist/esm/core/globalManager.mjs +58 -0
- package/dist/esm/core/globalManager.mjs.map +1 -0
- package/dist/esm/core/index.mjs +10 -0
- package/dist/esm/core/initAnalyticsClient.mjs +49 -0
- package/dist/esm/core/initAnalyticsClient.mjs.map +1 -0
- package/dist/esm/core/sampling.mjs +27 -0
- package/dist/esm/core/sampling.mjs.map +1 -0
- package/dist/esm/core/session.mjs +40 -0
- package/dist/esm/core/session.mjs.map +1 -0
- package/dist/esm/core/transport.mjs +45 -0
- package/dist/esm/core/transport.mjs.map +1 -0
- package/dist/esm/core/types.mjs +0 -0
- package/dist/esm/events/contentExposure.mjs +36 -0
- package/dist/esm/events/contentExposure.mjs.map +1 -0
- package/dist/esm/index.mjs +11 -0
- package/dist/esm/isEnabled.mjs +28 -0
- package/dist/esm/isEnabled.mjs.map +1 -0
- package/dist/esm/utils/hash.mjs +24 -0
- package/dist/esm/utils/hash.mjs.map +1 -0
- package/dist/esm/utils/idle.mjs +24 -0
- package/dist/esm/utils/idle.mjs.map +1 -0
- package/dist/types/core/AnalyticsClient.d.ts +51 -0
- package/dist/types/core/AnalyticsClient.d.ts.map +1 -0
- package/dist/types/core/abTesting.d.ts +23 -0
- package/dist/types/core/abTesting.d.ts.map +1 -0
- package/dist/types/core/eventBuffer.d.ts +35 -0
- package/dist/types/core/eventBuffer.d.ts.map +1 -0
- package/dist/types/core/globalManager.d.ts +28 -0
- package/dist/types/core/globalManager.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +10 -0
- package/dist/types/core/initAnalyticsClient.d.ts +28 -0
- package/dist/types/core/initAnalyticsClient.d.ts.map +1 -0
- package/dist/types/core/sampling.d.ts +20 -0
- package/dist/types/core/sampling.d.ts.map +1 -0
- package/dist/types/core/session.d.ts +17 -0
- package/dist/types/core/session.d.ts.map +1 -0
- package/dist/types/core/transport.d.ts +31 -0
- package/dist/types/core/transport.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +87 -0
- package/dist/types/core/types.d.ts.map +1 -0
- package/dist/types/events/contentExposure.d.ts +38 -0
- package/dist/types/events/contentExposure.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/isEnabled.d.ts +18 -0
- package/dist/types/isEnabled.d.ts.map +1 -0
- package/dist/types/utils/hash.d.ts +16 -0
- package/dist/types/utils/hash.d.ts.map +1 -0
- package/dist/types/utils/idle.d.ts +15 -0
- package/dist/types/utils/idle.d.ts.map +1 -0
- package/package.json +100 -0
package/README.md
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://intlayer.org" rel="">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/aymericzip/intlayer/main/docs/assets/cover.png" width="60%" alt="Intlayer Logo" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">
|
|
8
|
+
<strong>Per-component i18n</strong>
|
|
9
|
+
</h1>
|
|
10
|
+
|
|
11
|
+
<h2 align="center">
|
|
12
|
+
<strong>AI-powered translation. Visual Editor. Multilingual CMS.</strong>
|
|
13
|
+
</h2>
|
|
14
|
+
|
|
15
|
+
<br />
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">Docs</a> •
|
|
19
|
+
<a href="https://intlayer.org/doc/environment/nextjs" rel="">Next.js</a> •
|
|
20
|
+
<a href="https://intlayer.org/doc/environment/vite-and-react" rel="">React + Vite</a> •
|
|
21
|
+
<a href="https://intlayer.org/doc/concept/cms" rel="">CMS</a> •
|
|
22
|
+
<a href="https://discord.gg/7uxamYVeCk" rel="noopener noreferrer nofollow">Discord</a>
|
|
23
|
+
</p>
|
|
24
|
+
<p align="center" style="margin-top:15px;">
|
|
25
|
+
<a href="https://www.npmjs.com/package/intlayer" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/npm/v/intlayer?style=for-the-badge&labelColor=FFFFFF&color=000000&logoColor=FFFFFF" alt="npm version" height="24"/></a>
|
|
26
|
+
<a href="https://github.com/aymericzip/intlayer/stargazers" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/stars/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logo=github&logoColor=FFD700" alt="GitHub Stars" height="24"/></a>
|
|
27
|
+
<a href="https://www.npmjs.org/package/intlayer" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/npm/dm/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="monthly downloads" height="24"/></a>
|
|
28
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/LICENSE" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/license/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="license"/></a>
|
|
29
|
+
<a href="https://github.com/aymericzip/intlayer/commits/main" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/last-commit/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="last commit"/>
|
|
30
|
+
</a>
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">
|
|
36
|
+
<img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
|
|
37
|
+
</a>
|
|
38
|
+
|
|
39
|
+
## What is Intlayer?
|
|
40
|
+
|
|
41
|
+
Most i18n libraries are either too complex, too rigid, or not built for modern frameworks.
|
|
42
|
+
|
|
43
|
+
Intlayer is a **modern i18n solution** for web and mobile apps.
|
|
44
|
+
It’s framework-agnostic, **AI-powered**, and includes a free **CMS & visual editor**.
|
|
45
|
+
|
|
46
|
+
With **per-locale content files**, **TypeScript autocompletion**, **tree-shakable dictionaries**, and **CI/CD integration**, Intlayer makes internationalization **faster, cleaner, and smarter**.
|
|
47
|
+
|
|
48
|
+
## Keys benefits of Intlayer:
|
|
49
|
+
|
|
50
|
+
| Feature | Description |
|
|
51
|
+
| --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/frameworks.png?raw=true" alt="Feature" width="700"> | **Cross-Frameworks Support**<br><br>Intlayer is compatible with all major frameworks and libraries, including Next.js, React, Vite, Vue.js, Nuxt, Preact, Express, and more. |
|
|
53
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/javascript_content_management.jpg?raw=true" alt="Feature" width="700"> | **JavaScript-Powered Content Management**<br><br>Harness the flexibility of JavaScript to define and manage your content efficiently. <br><br> - [Content declaration](https://intlayer.org/doc/concept/content) |
|
|
54
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/per_locale_content_declaration_file.png?raw=true" alt="Feature" width="700"> | **Per-Locale Content Declaration File**<br><br>Speed up your development by declaring your content once, before auto generation.<br><br> - [Per-Locale Content Declaration File](https://intlayer.org/doc/concept/per-locale-file) |
|
|
55
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/compiler.jpg?raw=true" alt="Feature" width="700"> | **Compiler**<br><br>The Intlayer Compiler extract automatically the content from the components and generate the dictionary files.<br><br> - [Compiler](https://intlayer.org/doc/compiler) |
|
|
56
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/autocompletion.png?raw=true" alt="Feature" width="700"> | **Type-Safe Environment**<br><br>Leverage TypeScript to ensure your content definitions and code are error-free, while also benefiting from IDE autocompletion.<br><br> - [TypeScript configuration](https://intlayer.org/doc/environment/vite-and-react#configure-typescript) |
|
|
57
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/config_file.png?raw=true" alt="Feature" width="700"> | **Simplified Setup**<br><br>Get up and running quickly with minimal configuration. Adjust settings for internationalization, routing, AI, build, and content handling with ease. <br><br> - [Explore Next.js integration](https://intlayer.org/doc/environment/nextjs) |
|
|
58
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/content_retrieval.png?raw=true" alt="Feature" width="700"> | **Simplified Content Retrieval**<br><br>No need to call your `t` function for each piece of content. Retrieve all your content directly using a single hook.<br><br> - [React integration](https://intlayer.org/doc/environment/create-react-app) |
|
|
59
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/server_component.png?raw=true" alt="Feature" width="700"> | **Consistent Server Component Implementation**<br><br>Perfectly suited for Next.js server components, use the same implementation for both client and server components, no need to pass your `t` function across each server component. <br><br> - [Server Components](https://intlayer.org/doc/environment/nextjs#step-7-utilize-content-in-your-code) |
|
|
60
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/file_tree.png?raw=true" alt="Feature" width="700"> | **Organized Codebase**<br><br>Keep your codebase more organized: 1 component = 1 dictionary in the same folder. Translations close to their respective components, enhance maintainability and clarity. <br><br> - [How Intlayer works](https://intlayer.org/doc/concept/how-works-intlayer) |
|
|
61
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/url_routing.png?raw=true" alt="Feature" width="700"> | **Enhanced Routing**<br><br>Full support of app routing, adapting seamlessly to complex application structures, for Next.js, React, Vite, Vue.js, etc.<br><br> - [Explore Next.js integration](https://intlayer.org/doc/environment/nextjs) |
|
|
62
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/markdown.png?raw=true" alt="Feature" width="700"> | **Markdown Support**<br><br>Import and interpret, locale files and remote Markdown for multilingual content like privacy policies, documentation, etc. Interpret and make Markdown metadata accessible in your code.<br><br> - [Content files](https://intlayer.org/doc/concept/content/file) |
|
|
63
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/visual_editor.png?raw=true" alt="Feature" width="700"> | **Free Visual Editor & CMS**<br><br>A free visual editor and CMS are available for content writers, removing the need for a localization platform. Keep your content synchronized using Git, or externalize it totally or partially with the CMS.<br><br> - [Intlayer Editor](https://intlayer.org/doc/concept/editor) <br> - [Intlayer CMS](https://intlayer.org/doc/concept/cms) |
|
|
64
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/bundle.png?raw=true" alt="Feature" width="700"> | **Tree-shakable Content**<br><br>Tree-shakable content, reducing the size of the final bundle. Loads content per component, excluding any unused content from your bundle. Supports lazy loading to enhance app loading efficiency. <br><br> - [App build optimization](https://intlayer.org/doc/concept/how-works-intlayer#app-build-optimization) |
|
|
65
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/static_rendering.png?raw=true" alt="Feature" width="700"> | **Static Rendering**<br><br>Doesn't block Static Rendering. <br><br> - [Next.js integration](https://intlayer.org/doc/environment/nextjs) |
|
|
66
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/AI_translation.png?raw=true" alt="Feature" width="700"> | **AI-Powered Translation**<br><br>Transform your website into 231 languages with just one click using Intlayer's advanced AI-powered translation tools using your own AI provider / API key. <br><br> - [CI/CD integration](https://intlayer.org/doc/concept/ci-cd) <br> - [Intlayer CLI](https://intlayer.org/doc/concept/cli) <br> - [Auto fill](https://intlayer.org/doc/concept/auto-fill) |
|
|
67
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/mcp.png?raw=true" alt="Feature" width="700"> | **MCP Server Integration**<br><br>Provides an MCP (Model Context Protocol) server for IDE automation, enabling seamless content management and i18n workflows directly within your development environment. <br><br> - [MCP Server](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/mcp_server.md) |
|
|
68
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/vscode_extension.png?raw=true" alt="Feature" width="700"> | **VSCode Extension**<br><br>Intlayer provides a VSCode extension to help you manage your content and translations, building your dictionaries, translating your content, and more. <br><br> - [VSCode Extension](https://intlayer.org/doc/vs-code-extension) |
|
|
69
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/interoperability.png?raw=true" alt="Feature" width="700"> | **Interoperability**<br><br>Allow interoperability with react-i18next, next-i18next, next-intl, react-intl, vue-i18n. <br><br> - [Intlayer and react-intl](https://intlayer.org/blog/intlayer-with-react-intl) <br> - [Intlayer and next-intl](https://intlayer.org/blog/intlayer-with-next-intl) <br> - [Intlayer and next-i18next](https://intlayer.org/blog/intlayer-with-next-i18next) <br> - [Intlayer and vue-i18n](https://intlayer.org/blog/intlayer-with-vue-i18n) |
|
|
70
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/benchmark.png?raw=true" alt="Feature" width="700"> | **Performances & Benchmark**<br><br>Uses advanced tree-shaking and dynamic loading to boost performances and keep the solution as light as possible. <br><br> - [Performances & Benchmark](https://intlayer.org/doc/benchmark) |
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 📦 Installation
|
|
75
|
+
|
|
76
|
+
Start your journey with Intlayer today and experience a smoother, more powerful approach to internationalization.
|
|
77
|
+
|
|
78
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">
|
|
79
|
+
<img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
|
|
80
|
+
</a>
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm install intlayer react-intlayer
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
⚡ Quick Start (Next.js)
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
// intlayer.config.ts
|
|
90
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
91
|
+
|
|
92
|
+
const config: IntlayerConfig = {
|
|
93
|
+
internationalization: {
|
|
94
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
95
|
+
defaultLocale: Locales.ENGLISH,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export default config;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
// app/home.content.ts
|
|
104
|
+
import { t, type Dictionary } from "intlayer";
|
|
105
|
+
|
|
106
|
+
const content = {
|
|
107
|
+
key: "home",
|
|
108
|
+
content: {
|
|
109
|
+
title: t({
|
|
110
|
+
en: "Home",
|
|
111
|
+
fr: "Accueil",
|
|
112
|
+
es: "Inicio",
|
|
113
|
+
}),
|
|
114
|
+
},
|
|
115
|
+
} satisfies Dictionary;
|
|
116
|
+
|
|
117
|
+
export default content;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
// app/page.tsx
|
|
122
|
+
import { useIntlayer } from "react-intlayer";
|
|
123
|
+
|
|
124
|
+
const HomePage = () => {
|
|
125
|
+
const { title } = useIntlayer("home");
|
|
126
|
+
|
|
127
|
+
return <h1>{title}</h1>;
|
|
128
|
+
};
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
<a href="https://intlayer.org/doc/environment/nextjs"> Get the full guide → </a>
|
|
132
|
+
|
|
133
|
+
## 🎥 Live tutorial on YouTube
|
|
134
|
+
|
|
135
|
+
[](https://youtu.be/e_PPG7PTqGU?si=GyU_KpVhr61razRw)
|
|
136
|
+
|
|
137
|
+
<a href="https://intlayer.org/doc/concept/content" rel="">
|
|
138
|
+
<img src="https://img.shields.io/badge/Get_Started-FFFFFF?style=for-the-badge&logo=rocket&logoColor=black" />
|
|
139
|
+
</a>
|
|
140
|
+
|
|
141
|
+
## Table of Contents
|
|
142
|
+
|
|
143
|
+
Explore our comprehensive documentation to get started with Intlayer and learn how to integrate it into your projects.
|
|
144
|
+
|
|
145
|
+
<details open>
|
|
146
|
+
<summary style="font-size:16px; font-weight:bold;">📘 Get Started</summary>
|
|
147
|
+
<ul>
|
|
148
|
+
<li><a href="https://intlayer.org/doc/why" rel=''>Why Intlayer?</a></li>
|
|
149
|
+
<li><a href="https://intlayer.org/doc" rel=''>Introduction</a></li>
|
|
150
|
+
</ul>
|
|
151
|
+
</details>
|
|
152
|
+
|
|
153
|
+
<details>
|
|
154
|
+
<summary style="font-size:16px; font-weight:bold;">⚙️ Concept</summary>
|
|
155
|
+
<ul>
|
|
156
|
+
<li><a href="https://intlayer.org/doc/concept/how-works-intlayer" rel=''>How Intlayer Works</a></li>
|
|
157
|
+
<li><a href="https://intlayer.org/doc/concept/configuration" rel=''>Configuration</a></li>
|
|
158
|
+
<li><a href="https://intlayer.org/doc/concept/cli" rel=''>Intlayer CLI</a></li>
|
|
159
|
+
<li><a href="https://intlayer.org/doc/compiler" rel=''>Compiler</a></li>
|
|
160
|
+
|
|
161
|
+
<li><a href="https://intlayer.org/doc/concept/editor" rel=''>Intlayer Editor</a></li>
|
|
162
|
+
<li><a href="https://intlayer.org/doc/concept/cms" rel=''>Intlayer CMS</a></li>
|
|
163
|
+
<li><a href="https://intlayer.org/doc/concept/content" rel=''>Dictionary</a>
|
|
164
|
+
<ul>
|
|
165
|
+
<li><a href="https://intlayer.org/doc/concept/content/per-locale-file" rel=''>Per-Locale Content Declaration File</a></li>
|
|
166
|
+
<li><a href="https://intlayer.org/doc/concept/content/translation" rel=''>Translation</a></li>
|
|
167
|
+
<li><a href="https://intlayer.org/doc/concept/content/enumeration" rel=''>Enumeration</a></li>
|
|
168
|
+
<li><a href="https://intlayer.org/doc/concept/content/condition" rel=''>Condition</a></li>
|
|
169
|
+
<li><a href="https://intlayer.org/doc/concept/content/nesting" rel=''>Nesting</a></li>
|
|
170
|
+
<li><a href="https://intlayer.org/doc/concept/content/markdown" rel=''>Markdown</a></li>
|
|
171
|
+
<li><a href="https://intlayer.org/doc/concept/content/function-fetching" rel=''>Function Fetching</a></li>
|
|
172
|
+
<li><a href="https://intlayer.org/doc/concept/content/insertion" rel=''>Insertion</a></li>
|
|
173
|
+
<li><a href="https://intlayer.org/doc/concept/content/file" rel=''>File</a></li>
|
|
174
|
+
</ul>
|
|
175
|
+
</li>
|
|
176
|
+
</ul>
|
|
177
|
+
</details>
|
|
178
|
+
|
|
179
|
+
<details open>
|
|
180
|
+
<summary style="font-size:16px; font-weight:bold;">🌐 Environment</summary>
|
|
181
|
+
<ul>
|
|
182
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs" rel=''>Intlayer with Next.js 16</a>
|
|
183
|
+
<ul>
|
|
184
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs/15" rel=''>Next.js 15</a></li>
|
|
185
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs/14" rel=''>Next.js 14 (App Router)</a></li>
|
|
186
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs/next-with-Page-Router" rel=''>Next.js Page Router</a></li>
|
|
187
|
+
<li><a href="https://intlayer.org/doc/environment/nextjs/compiler" rel=''>Next.js using Compiler</a></li>
|
|
188
|
+
</ul>
|
|
189
|
+
</li>
|
|
190
|
+
<li><a href="https://intlayer.org/doc/environment/create-react-app" rel=''>React CRA</a></li>
|
|
191
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-react" rel=''>Vite + React</a></li>
|
|
192
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-react" rel=''>Vite + React using Compiler</a></li>
|
|
193
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-react/compiler" rel=''>React-router-v7</a></li>
|
|
194
|
+
<li><a href="https://intlayer.org/doc/environment/tanstack-start" rel=''>Tanstack start</a>
|
|
195
|
+
<ul>
|
|
196
|
+
<li><a href="https://intlayer.org/doc/environment/tanstack-start/solid" rel=''>Solid</a></li>
|
|
197
|
+
</ul>
|
|
198
|
+
</li>
|
|
199
|
+
<li><a href="https://intlayer.org/doc/environment/astro" rel=''>Astro</a>
|
|
200
|
+
<ul>
|
|
201
|
+
<li><a href="https://intlayer.org/doc/environment/astro/react" rel=''>React</a></li>
|
|
202
|
+
<li><a href="https://intlayer.org/doc/environment/astro/vue" rel=''>Vue</a></li>
|
|
203
|
+
<li><a href="https://intlayer.org/doc/environment/astro/svelte" rel=''>Svelte</a></li>
|
|
204
|
+
<li><a href="https://intlayer.org/doc/environment/astro/solid" rel=''>Solid</a></li>
|
|
205
|
+
<li><a href="https://intlayer.org/doc/environment/astro/vanilla" rel=''>Vanilla JS</a></li>
|
|
206
|
+
<li><a href="https://intlayer.org/doc/environment/astro/lit" rel=''>Lit</a></li>
|
|
207
|
+
</ul>
|
|
208
|
+
</li>
|
|
209
|
+
|
|
210
|
+
<li><a href="https://intlayer.org/doc/environment/react-native-and-expo" rel=''>React Native</a></li>
|
|
211
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-svelte" rel=''>Vite + Svelte</a></li>
|
|
212
|
+
<li><a href="https://intlayer.org/doc/environment/sveltekit" rel=''>SvelteKit</a></li>
|
|
213
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-preact" rel=''>Vite + Preact</a></li>
|
|
214
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-vue" rel=''>Vite + Vue</a></li>
|
|
215
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-nuxt" rel=''>Vite + Nuxt</a></li>
|
|
216
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-solid" rel=''>Vite + Solid</a></li>
|
|
217
|
+
<li><a href="https://intlayer.org/doc/environment/angular" rel=''>Angular</a></li>
|
|
218
|
+
<li>
|
|
219
|
+
<a href="https://intlayer.org/doc/environment/express" rel=''>Backend</a>
|
|
220
|
+
<ul>
|
|
221
|
+
<li><a href="https://intlayer.org/doc/environment/express" rel=''>Express</a></li>
|
|
222
|
+
<li><a href="https://intlayer.org/doc/environment/nest" rel=''>NestJS</a></li>
|
|
223
|
+
<li><a href="https://intlayer.org/doc/environment/fastify" rel=''>Fastify</a></li>
|
|
224
|
+
<li><a href="https://intlayer.org/doc/environment/adonisjs" rel=''>AdonisJS</a></li>
|
|
225
|
+
<li><a href="https://intlayer.org/doc/environment/hono" rel=''>Hono</a></li>
|
|
226
|
+
</ul>
|
|
227
|
+
</li>
|
|
228
|
+
</ul>
|
|
229
|
+
</details>
|
|
230
|
+
|
|
231
|
+
<details>
|
|
232
|
+
<summary style="font-size:16px; font-weight:bold;">📊 Benchmark</summary>
|
|
233
|
+
<ul>
|
|
234
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/nextjs.md" rel=''>Next.js</a></li>
|
|
235
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/tanstack.md" rel=''>TanStack Start</a></li>
|
|
236
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/vue.md" rel=''>Vue</a></li>
|
|
237
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/solid.md" rel=''>Solid</a></li>
|
|
238
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/benchmark/svelte.md" rel=''>Svelte</a></li>
|
|
239
|
+
</ul>
|
|
240
|
+
</details>
|
|
241
|
+
|
|
242
|
+
<details>
|
|
243
|
+
<summary style="font-size:16px; font-weight:bold;">📰 Blog</summary>
|
|
244
|
+
<ul>
|
|
245
|
+
<li><a href="https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/what_is_internationalization.md" rel=''>What is i18n</a></li>
|
|
246
|
+
<li><a href="https://intlayer.org/blog/SEO-and-i18n" rel=''>i18n and SEO</a></li>
|
|
247
|
+
<li><a href="https://intlayer.org/blog/intlayer-with-next-i18next" rel=''>Intlayer and i18next</a></li>
|
|
248
|
+
<li><a href="https://intlayer.org/blog/intlayer-with-react-i18next" rel=''>Intlayer and react-intl</a></li>
|
|
249
|
+
<li><a href="https://intlayer.org/blog/intlayer-with-next-intl" rel=''>Intlayer and next-intl</a></li>
|
|
250
|
+
</ul>
|
|
251
|
+
</details>
|
|
252
|
+
|
|
253
|
+
## Multilingual content management system
|
|
254
|
+
|
|
255
|
+
More than an i18n library, Intlayer is a complete **multilingual content management system**. A full CMS is available for free at [app.intlayer.org](https://app.intlayer.org).
|
|
256
|
+
|
|
257
|
+
Intlayer connects **developers**, **copywriters**, and **AI agents** in one workflow for creating and maintaining multilingual websites effortlessly.Intlayer replaces the following stack in a single solution:
|
|
258
|
+
|
|
259
|
+
- i18n solutions (e.g. `i18next`, `next-intl`, `vue-i18n`)
|
|
260
|
+
- TMSs (Translation Management Systems) (e.g. Crowdin, Phrase, Lokalise)
|
|
261
|
+
- Feature flags
|
|
262
|
+
- Headless CMSs (e.g. Contentful, Strapi, Sanity)
|
|
263
|
+
|
|
264
|
+

|
|
265
|
+
|
|
266
|
+
## 🌐 Readme in other languages
|
|
267
|
+
|
|
268
|
+
<p align="center">
|
|
269
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/readme.md">English</a> •
|
|
270
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/readme.md">简体中文</a> •
|
|
271
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ru/readme.md">Русский</a> •
|
|
272
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/readme.md">日本語</a> •
|
|
273
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/readme.md">Français</a> •
|
|
274
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ko/readme.md">한국어</a> •
|
|
275
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/readme.md">Español</a> •
|
|
276
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/readme.md">Deutsch</a> •
|
|
277
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/ar/readme.md">العربية</a> •
|
|
278
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/readme.md">Italiano</a> •
|
|
279
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/readme.md">English (UK)</a> •
|
|
280
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/readme.md">Português</a> •
|
|
281
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/hi/readme.md">हिन्दी</a> •
|
|
282
|
+
<a href="https://github.com/aymericzip/intlayer/blob/main/docs/docs/tr/readme.md">Türkçe</a>
|
|
283
|
+
</p>
|
|
284
|
+
|
|
285
|
+
## 🤝 Community
|
|
286
|
+
|
|
287
|
+
Intlayer is built with and for the community and we’d love your input!
|
|
288
|
+
|
|
289
|
+
- Have a suggestion? [Open an issue](https://github.com/aymericzip/intlayer/issues)
|
|
290
|
+
- Found a bug or improvement? [Submit a PR](https://github.com/aymericzip/intlayer/pulls)
|
|
291
|
+
- Need help or want to connect? [Join our Discord](https://discord.gg/7uxamYVeCk)
|
|
292
|
+
|
|
293
|
+
You can also follow us on :
|
|
294
|
+
|
|
295
|
+
<div>
|
|
296
|
+
<br/>
|
|
297
|
+
<p align="center">
|
|
298
|
+
<a href="https://discord.gg/528mBV4N" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
299
|
+
src="https://img.shields.io/badge/discord-5865F2.svg?style=for-the-badge&logo=discord&logoColor=white"
|
|
300
|
+
alt="Intlayer Discord" height="30"/></a>
|
|
301
|
+
<a href="https://www.linkedin.com/company/intlayerorg" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
302
|
+
src="https://img.shields.io/badge/linkedin-%231DA1F2.svg?style=for-the-badge&logo=linkedin&logoColor=white"
|
|
303
|
+
alt="Intlayer LinkedIn" height="30"/></a>
|
|
304
|
+
<a href="https://www.instagram.com/intlayer/" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
305
|
+
src="https://img.shields.io/badge/instagram-%23E4405F.svg?style=for-the-badge&logo=Instagram&logoColor=white"
|
|
306
|
+
alt="Intlayer Instagram" height="30"/></a>
|
|
307
|
+
<a href="https://x.com/Intlayer183096" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
308
|
+
src="https://img.shields.io/badge/x-1DA1F2.svg?style=for-the-badge&logo=x&logoColor=white"
|
|
309
|
+
alt="Intlayer X" height="30"/></a>
|
|
310
|
+
<a href="https://www.youtube.com/@intlayer" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
311
|
+
src="https://img.shields.io/badge/youtube-FF0000.svg?style=for-the-badge&logo=youtube&logoColor=white"
|
|
312
|
+
alt="Intlayer YouTube" height="30"/></a>
|
|
313
|
+
<a href="https://www.tiktok.com/@intlayer" target="blank" rel='noopener noreferrer nofollow'><img align="center"
|
|
314
|
+
src="https://img.shields.io/badge/tiktok-000000.svg?style=for-the-badge&logo=tiktok&logoColor=white"
|
|
315
|
+
alt="Intlayer TikTok" height="30"/></a>
|
|
316
|
+
<br>
|
|
317
|
+
</p>
|
|
318
|
+
</div>
|
|
319
|
+
|
|
320
|
+
### Contribution
|
|
321
|
+
|
|
322
|
+
For more detailed guidelines on contributing to this project, please refer to the [`CONTRIBUTING.md`](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md) file. It contains essential information on our development process, commit message conventions, and release procedures. Your contributions are valuable to us, and we appreciate your efforts in making this project better!
|
|
323
|
+
|
|
324
|
+
Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https://gitlab.com/ay.pineau/intlayer), or [Bitbucket](https://bitbucket.org/intlayer/intlayer/).
|
|
325
|
+
|
|
326
|
+
### Thank You for the Support
|
|
327
|
+
|
|
328
|
+
If you like Intlayer, give us a ⭐ on GitHub. It helps others discover the project! [See why GitHub Stars matter](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md#why-github-stars-matter-).
|
|
329
|
+
|
|
330
|
+
[](https://star-history.com/#aymericzip/intlayer&Date)
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_utils_idle = require('../utils/idle.cjs');
|
|
3
|
+
const require_core_abTesting = require('./abTesting.cjs');
|
|
4
|
+
const require_core_eventBuffer = require('./eventBuffer.cjs');
|
|
5
|
+
const require_core_sampling = require('./sampling.cjs');
|
|
6
|
+
const require_core_session = require('./session.cjs');
|
|
7
|
+
const require_core_transport = require('./transport.cjs');
|
|
8
|
+
|
|
9
|
+
//#region src/core/AnalyticsClient.ts
|
|
10
|
+
/** Default flush cadence — one network request per 20 seconds. */
|
|
11
|
+
const DEFAULT_FLUSH_INTERVAL = 2e4;
|
|
12
|
+
/** Default cap on distinct buffered events before an early flush. */
|
|
13
|
+
const DEFAULT_MAX_BUFFER_SIZE = 500;
|
|
14
|
+
/** Default sampling — keep every session. */
|
|
15
|
+
const DEFAULT_SAMPLE_RATE = 1;
|
|
16
|
+
/**
|
|
17
|
+
* Maximum events per network request. `sendBeacon` and `fetch(keepalive)`
|
|
18
|
+
* reject bodies over ~64KB, so large batches are split into multiple sends.
|
|
19
|
+
*/
|
|
20
|
+
const MAX_EVENTS_PER_SEND = 200;
|
|
21
|
+
/** Identifies the producing SDK in the ingest envelope. */
|
|
22
|
+
const SDK_VERSION = "intlayer-analytics/1";
|
|
23
|
+
/**
|
|
24
|
+
* Reads the current page pathname. Search params are intentionally excluded to
|
|
25
|
+
* avoid capturing anything sensitive.
|
|
26
|
+
*/
|
|
27
|
+
const currentUrl = () => {
|
|
28
|
+
if (typeof window === "undefined" || !window.location) return "";
|
|
29
|
+
return window.location.pathname;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Reduces the referrer to its host — never the full URL — for privacy.
|
|
33
|
+
*/
|
|
34
|
+
const referrerHost = () => {
|
|
35
|
+
if (typeof document === "undefined" || !document.referrer) return void 0;
|
|
36
|
+
try {
|
|
37
|
+
return new URL(document.referrer).host;
|
|
38
|
+
} catch {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Creates an analytics client. Prefer {@link initAnalyticsClient} in application
|
|
44
|
+
* code — it manages a shared singleton so there is only ever one flush timer.
|
|
45
|
+
*
|
|
46
|
+
* @param config - Resolved client configuration.
|
|
47
|
+
* @returns A started-on-demand {@link AnalyticsClient}.
|
|
48
|
+
*/
|
|
49
|
+
const createAnalyticsClient = (config) => {
|
|
50
|
+
const sessionId = require_core_session.getSessionId();
|
|
51
|
+
const sampledIn = require_core_sampling.isSampledIn(sessionId, config.sampleRate);
|
|
52
|
+
const buffer = require_core_eventBuffer.createEventBuffer({ max: config.maxBufferSize });
|
|
53
|
+
const endpoint = `${config.backendURL.replace(/\/$/, "")}/api/analytics/events`;
|
|
54
|
+
let ambientLocale = "";
|
|
55
|
+
let flushTimer = null;
|
|
56
|
+
let started = false;
|
|
57
|
+
let detachListeners = null;
|
|
58
|
+
let seenExposureKeys = /* @__PURE__ */ new Set();
|
|
59
|
+
const flush = (useBeacon = false) => {
|
|
60
|
+
const events = buffer.drain();
|
|
61
|
+
for (let start = 0; start < events.length; start += 200) require_core_transport.sendEvents(endpoint, {
|
|
62
|
+
clientId: config.clientId,
|
|
63
|
+
sessionId,
|
|
64
|
+
sdkVersion: SDK_VERSION,
|
|
65
|
+
events: events.slice(start, start + 200)
|
|
66
|
+
}, { useBeacon });
|
|
67
|
+
};
|
|
68
|
+
/** Pushes an event and triggers an early flush if the buffer is full. */
|
|
69
|
+
const enqueue = (event) => {
|
|
70
|
+
if (buffer.push(event) >= config.maxBufferSize) flush();
|
|
71
|
+
};
|
|
72
|
+
const setLocale = (locale) => {
|
|
73
|
+
ambientLocale = locale;
|
|
74
|
+
};
|
|
75
|
+
const trackPageView = (event = {}) => {
|
|
76
|
+
if (!sampledIn) return;
|
|
77
|
+
seenExposureKeys = /* @__PURE__ */ new Set();
|
|
78
|
+
enqueue({
|
|
79
|
+
type: "page_view",
|
|
80
|
+
t: Date.now(),
|
|
81
|
+
url: event.url ?? currentUrl(),
|
|
82
|
+
locale: event.locale ?? ambientLocale,
|
|
83
|
+
ref: event.ref ?? referrerHost(),
|
|
84
|
+
vw: event.vw ?? (typeof window !== "undefined" ? window.innerWidth : void 0),
|
|
85
|
+
vh: event.vh ?? (typeof window !== "undefined" ? window.innerHeight : void 0),
|
|
86
|
+
reason: event.reason ?? "initial"
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
const trackContentExposure = (event) => {
|
|
90
|
+
if (!sampledIn) return;
|
|
91
|
+
const locale = event.locale ?? ambientLocale;
|
|
92
|
+
const exposureKey = [
|
|
93
|
+
event.dictionaryKey,
|
|
94
|
+
event.keyPath,
|
|
95
|
+
locale,
|
|
96
|
+
event.experimentKey ?? "",
|
|
97
|
+
event.variant ?? ""
|
|
98
|
+
].join("");
|
|
99
|
+
if (seenExposureKeys.has(exposureKey)) return;
|
|
100
|
+
seenExposureKeys.add(exposureKey);
|
|
101
|
+
enqueue({
|
|
102
|
+
...event,
|
|
103
|
+
type: "content_exposure",
|
|
104
|
+
t: Date.now(),
|
|
105
|
+
url: currentUrl(),
|
|
106
|
+
locale
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const trackConversion = (event) => {
|
|
110
|
+
enqueue({
|
|
111
|
+
...event,
|
|
112
|
+
type: "conversion",
|
|
113
|
+
t: Date.now(),
|
|
114
|
+
url: currentUrl(),
|
|
115
|
+
locale: event.locale ?? ambientLocale
|
|
116
|
+
});
|
|
117
|
+
flush();
|
|
118
|
+
};
|
|
119
|
+
const getVariant = (experimentKey, variants, weights) => require_core_abTesting.assignVariant(sessionId, experimentKey, variants, weights);
|
|
120
|
+
/** Attaches lifecycle + SPA-navigation listeners without blocking render. */
|
|
121
|
+
const attachListeners = () => {
|
|
122
|
+
if (typeof window === "undefined") return;
|
|
123
|
+
const onHidden = () => {
|
|
124
|
+
if (document.visibilityState === "hidden") flush(true);
|
|
125
|
+
};
|
|
126
|
+
const onPageHide = () => flush(true);
|
|
127
|
+
const onPopState = () => trackPageView({ reason: "route_change" });
|
|
128
|
+
document.addEventListener("visibilitychange", onHidden);
|
|
129
|
+
window.addEventListener("pagehide", onPageHide, { capture: true });
|
|
130
|
+
window.addEventListener("popstate", onPopState);
|
|
131
|
+
const history = window.history;
|
|
132
|
+
const originalPush = history.pushState;
|
|
133
|
+
const patchedPushState = function patchedPush(...args) {
|
|
134
|
+
const result = originalPush.apply(this, args);
|
|
135
|
+
trackPageView({ reason: "route_change" });
|
|
136
|
+
return result;
|
|
137
|
+
};
|
|
138
|
+
history.pushState = patchedPushState;
|
|
139
|
+
detachListeners = () => {
|
|
140
|
+
document.removeEventListener("visibilitychange", onHidden);
|
|
141
|
+
window.removeEventListener("pagehide", onPageHide, { capture: true });
|
|
142
|
+
window.removeEventListener("popstate", onPopState);
|
|
143
|
+
if (history.pushState === patchedPushState) history.pushState = originalPush;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
const start = () => {
|
|
147
|
+
if (started) return;
|
|
148
|
+
started = true;
|
|
149
|
+
flushTimer = setInterval(flush, config.flushInterval);
|
|
150
|
+
flushTimer?.unref?.();
|
|
151
|
+
require_utils_idle.onIdle(attachListeners);
|
|
152
|
+
};
|
|
153
|
+
const stop = () => {
|
|
154
|
+
if (!started) return;
|
|
155
|
+
started = false;
|
|
156
|
+
if (flushTimer) {
|
|
157
|
+
clearInterval(flushTimer);
|
|
158
|
+
flushTimer = null;
|
|
159
|
+
}
|
|
160
|
+
detachListeners?.();
|
|
161
|
+
detachListeners = null;
|
|
162
|
+
flush(true);
|
|
163
|
+
};
|
|
164
|
+
return {
|
|
165
|
+
setLocale,
|
|
166
|
+
trackPageView,
|
|
167
|
+
trackContentExposure,
|
|
168
|
+
trackConversion,
|
|
169
|
+
getVariant,
|
|
170
|
+
flush,
|
|
171
|
+
start,
|
|
172
|
+
stop
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
//#endregion
|
|
177
|
+
exports.DEFAULT_FLUSH_INTERVAL = DEFAULT_FLUSH_INTERVAL;
|
|
178
|
+
exports.DEFAULT_MAX_BUFFER_SIZE = DEFAULT_MAX_BUFFER_SIZE;
|
|
179
|
+
exports.DEFAULT_SAMPLE_RATE = DEFAULT_SAMPLE_RATE;
|
|
180
|
+
exports.MAX_EVENTS_PER_SEND = MAX_EVENTS_PER_SEND;
|
|
181
|
+
exports.createAnalyticsClient = createAnalyticsClient;
|
|
182
|
+
//# sourceMappingURL=AnalyticsClient.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnalyticsClient.cjs","names":["getSessionId","isSampledIn","createEventBuffer","assignVariant"],"sources":["../../../src/core/AnalyticsClient.ts"],"sourcesContent":["import { onIdle } from '../utils/idle';\nimport { assignVariant } from './abTesting';\nimport { createEventBuffer, type EventBuffer } from './eventBuffer';\nimport { isSampledIn } from './sampling';\nimport { getSessionId } from './session';\nimport { sendEvents } from './transport';\nimport type {\n AnalyticsClientConfig,\n AnalyticsEvent,\n ContentExposureEvent,\n ConversionEvent,\n PageViewEvent,\n TrackableEvent,\n} from './types';\n\n/**\n * Caller-supplied fields for a page view. Everything is optional — the client\n * fills `url`, `locale`, viewport, and referrer from the environment when omitted.\n */\nexport type PageViewInput = {\n /** Explicit pathname / screen name (native runtimes have no `location`). */\n url?: string;\n /** Explicit locale; falls back to the client's ambient locale. */\n locale?: string;\n /** Referrer host override. */\n ref?: string;\n /** Viewport width override. */\n vw?: number;\n /** Viewport height override. */\n vh?: number;\n /** Why the view was recorded. */\n reason?: PageViewEvent['reason'];\n};\n\n/** Default flush cadence — one network request per 20 seconds. */\nexport const DEFAULT_FLUSH_INTERVAL = 20_000;\n/** Default cap on distinct buffered events before an early flush. */\nexport const DEFAULT_MAX_BUFFER_SIZE = 500;\n/** Default sampling — keep every session. */\nexport const DEFAULT_SAMPLE_RATE = 1;\n/**\n * Maximum events per network request. `sendBeacon` and `fetch(keepalive)`\n * reject bodies over ~64KB, so large batches are split into multiple sends.\n */\nexport const MAX_EVENTS_PER_SEND = 200;\n/** Identifies the producing SDK in the ingest envelope. */\nconst SDK_VERSION = 'intlayer-analytics/1';\n\n/**\n * The public surface of the analytics client singleton. Framework bindings hold\n * a reference to this and forward provider/node/conversion signals into it.\n */\nexport type AnalyticsClient = {\n /** Sets the ambient locale stamped onto subsequent events. */\n setLocale: (locale: string) => void;\n /** Records a page/locale view (provider level). */\n trackPageView: (event?: PageViewInput) => void;\n /** Records a content exposure (node level). Sampled + deduped per page view. */\n trackContentExposure: (\n event: Omit<TrackableEvent<ContentExposureEvent>, 'type'>\n ) => void;\n /** Records a conversion tied to an experiment variant. */\n trackConversion: (\n event: Omit<TrackableEvent<ConversionEvent>, 'type'>\n ) => void;\n /** Deterministically resolves this session's variant for an experiment. */\n getVariant: (\n experimentKey: string,\n variants: string[],\n weights?: number[]\n ) => string;\n /** Sends the buffered batch now. */\n flush: (useBeacon?: boolean) => void;\n /** Starts the flush loop and lifecycle listeners (idempotent). */\n start: () => void;\n /** Stops timers/listeners and flushes any remaining events. */\n stop: () => void;\n};\n\n/**\n * Reads the current page pathname. Search params are intentionally excluded to\n * avoid capturing anything sensitive.\n */\nconst currentUrl = (): string => {\n if (typeof window === 'undefined' || !window.location) return '';\n return window.location.pathname;\n};\n\n/**\n * Reduces the referrer to its host — never the full URL — for privacy.\n */\nconst referrerHost = (): string | undefined => {\n if (typeof document === 'undefined' || !document.referrer) return undefined;\n try {\n return new URL(document.referrer).host;\n } catch {\n return undefined;\n }\n};\n\n/**\n * Creates an analytics client. Prefer {@link initAnalyticsClient} in application\n * code — it manages a shared singleton so there is only ever one flush timer.\n *\n * @param config - Resolved client configuration.\n * @returns A started-on-demand {@link AnalyticsClient}.\n */\nexport const createAnalyticsClient = (\n config: AnalyticsClientConfig\n): AnalyticsClient => {\n const sessionId = getSessionId();\n const sampledIn = isSampledIn(sessionId, config.sampleRate);\n const buffer: EventBuffer = createEventBuffer({ max: config.maxBufferSize });\n const endpoint = `${config.backendURL.replace(/\\/$/, '')}/api/analytics/events`;\n\n let ambientLocale = '';\n let flushTimer: ReturnType<typeof setInterval> | null = null;\n let started = false;\n let detachListeners: (() => void) | null = null;\n\n // Exposure keys already recorded for the current page view. React (and other\n // frameworks) resolve content nodes on every re-render; without this gate a\n // component re-rendering 60×/s would count 60 exposures per second. The set\n // is cleared on each page view so the recorded semantic is \"shown at least\n // once during this page view\".\n let seenExposureKeys = new Set<string>();\n\n const flush = (useBeacon = false): void => {\n const events = buffer.drain();\n\n // Split into bounded chunks so no single request exceeds transport limits.\n for (let start = 0; start < events.length; start += MAX_EVENTS_PER_SEND) {\n sendEvents(\n endpoint,\n {\n clientId: config.clientId,\n sessionId,\n sdkVersion: SDK_VERSION,\n events: events.slice(start, start + MAX_EVENTS_PER_SEND),\n },\n { useBeacon }\n );\n }\n };\n\n /** Pushes an event and triggers an early flush if the buffer is full. */\n const enqueue = (event: AnalyticsEvent): void => {\n const size = buffer.push(event);\n if (size >= config.maxBufferSize) flush();\n };\n\n const setLocale = (locale: string): void => {\n ambientLocale = locale;\n };\n\n const trackPageView: AnalyticsClient['trackPageView'] = (event = {}) => {\n if (!sampledIn) return;\n\n // A new page view starts a fresh exposure window.\n seenExposureKeys = new Set<string>();\n\n enqueue({\n type: 'page_view',\n t: Date.now(),\n url: event.url ?? currentUrl(),\n locale: event.locale ?? ambientLocale,\n ref: event.ref ?? referrerHost(),\n vw:\n event.vw ??\n (typeof window !== 'undefined' ? window.innerWidth : undefined),\n vh:\n event.vh ??\n (typeof window !== 'undefined' ? window.innerHeight : undefined),\n reason: event.reason ?? 'initial',\n });\n };\n\n const trackContentExposure: AnalyticsClient['trackContentExposure'] = (\n event\n ) => {\n if (!sampledIn) return;\n\n const locale = event.locale ?? ambientLocale;\n // Joined with \\x01 (never present in content keys) so parts cannot collide.\n const exposureKey = [\n event.dictionaryKey,\n event.keyPath,\n locale,\n event.experimentKey ?? '',\n event.variant ?? '',\n ].join('\u0001');\n\n // Deduplicate within the current page view (see `seenExposureKeys`).\n if (seenExposureKeys.has(exposureKey)) return;\n seenExposureKeys.add(exposureKey);\n\n enqueue({\n ...event,\n type: 'content_exposure',\n t: Date.now(),\n url: currentUrl(),\n locale,\n });\n };\n\n const trackConversion: AnalyticsClient['trackConversion'] = (event) => {\n // Conversions are never sampled out — they are rare and decisive for A/B.\n enqueue({\n ...event,\n type: 'conversion',\n t: Date.now(),\n url: currentUrl(),\n locale: event.locale ?? ambientLocale,\n });\n // Flush conversions promptly so they are not lost on immediate navigation.\n flush();\n };\n\n const getVariant: AnalyticsClient['getVariant'] = (\n experimentKey,\n variants,\n weights\n ) => assignVariant(sessionId, experimentKey, variants, weights);\n\n /** Attaches lifecycle + SPA-navigation listeners without blocking render. */\n const attachListeners = (): void => {\n if (typeof window === 'undefined') return;\n\n const onHidden = (): void => {\n if (document.visibilityState === 'hidden') flush(true);\n };\n const onPageHide = (): void => flush(true);\n const onPopState = (): void => trackPageView({ reason: 'route_change' });\n\n document.addEventListener('visibilitychange', onHidden);\n window.addEventListener('pagehide', onPageHide, { capture: true });\n window.addEventListener('popstate', onPopState);\n\n // Patch history.pushState so client-side route changes emit a page view.\n // `replaceState` is intentionally left untouched: routers use it for\n // same-page URL sync (scroll, params), which is not a navigation.\n const history = window.history;\n const originalPush = history.pushState;\n\n const patchedPushState = function patchedPush(\n this: History,\n ...args: Parameters<History['pushState']>\n ) {\n const result = originalPush.apply(this, args);\n trackPageView({ reason: 'route_change' });\n return result;\n };\n history.pushState = patchedPushState;\n\n detachListeners = (): void => {\n document.removeEventListener('visibilitychange', onHidden);\n window.removeEventListener('pagehide', onPageHide, { capture: true });\n window.removeEventListener('popstate', onPopState);\n // Only restore if nothing else re-patched pushState after us; restoring\n // blindly would clobber another library's wrapper.\n if (history.pushState === patchedPushState) {\n history.pushState = originalPush;\n }\n };\n };\n\n const start = (): void => {\n if (started) return;\n started = true;\n\n flushTimer = setInterval(flush, config.flushInterval);\n // Some runtimes (Node during SSR) keep the process alive on timers.\n (flushTimer as { unref?: () => void })?.unref?.();\n\n onIdle(attachListeners);\n };\n\n const stop = (): void => {\n if (!started) return;\n started = false;\n\n if (flushTimer) {\n clearInterval(flushTimer);\n flushTimer = null;\n }\n detachListeners?.();\n detachListeners = null;\n flush(true);\n };\n\n return {\n setLocale,\n trackPageView,\n trackContentExposure,\n trackConversion,\n getVariant,\n flush,\n start,\n stop,\n };\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_utils_hash = require('../utils/hash.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/core/abTesting.ts
|
|
5
|
+
/**
|
|
6
|
+
* Deterministically assigns a variant to a session for a given experiment.
|
|
7
|
+
*
|
|
8
|
+
* The assignment is a pure function of `sessionId` + `experimentKey`, so it is
|
|
9
|
+
* stable for the whole session and requires **no** server round-trip before the
|
|
10
|
+
* first render — avoiding layout shift / content flicker. Optional `weights`
|
|
11
|
+
* bias the split (e.g. `[0.9, 0.1]` for a 90/10 rollout).
|
|
12
|
+
*
|
|
13
|
+
* @param sessionId - The current anonymous session id.
|
|
14
|
+
* @param experimentKey - Unique key identifying the experiment.
|
|
15
|
+
* @param variants - The candidate variant names (at least one).
|
|
16
|
+
* @param weights - Optional relative weights, one per variant.
|
|
17
|
+
* @returns The variant assigned to this session.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* assignVariant('sid-1', 'homepage-hero', ['a', 'b']); // stable 'a' | 'b'
|
|
21
|
+
* assignVariant('sid-1', 'homepage-hero', ['a', 'b'], [9, 1]); // ~90% 'a'
|
|
22
|
+
*/
|
|
23
|
+
const assignVariant = (sessionId, experimentKey, variants, weights) => {
|
|
24
|
+
if (variants.length === 0) throw new Error("assignVariant requires at least one variant");
|
|
25
|
+
if (variants.length === 1) return variants[0];
|
|
26
|
+
const bucket = require_utils_hash.hashString(`${sessionId}:${experimentKey}`) / 4294967296;
|
|
27
|
+
if (!weights || weights.length !== variants.length) {
|
|
28
|
+
const index = Math.floor(bucket * variants.length);
|
|
29
|
+
return variants[Math.min(index, variants.length - 1)];
|
|
30
|
+
}
|
|
31
|
+
const totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
|
|
32
|
+
if (totalWeight <= 0) return variants[Math.floor(bucket * variants.length)];
|
|
33
|
+
let cumulative = 0;
|
|
34
|
+
const target = bucket * totalWeight;
|
|
35
|
+
for (let index = 0; index < variants.length; index++) {
|
|
36
|
+
cumulative += weights[index];
|
|
37
|
+
if (target < cumulative) return variants[index];
|
|
38
|
+
}
|
|
39
|
+
return variants[variants.length - 1];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.assignVariant = assignVariant;
|
|
44
|
+
//# sourceMappingURL=abTesting.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abTesting.cjs","names":["hashString"],"sources":["../../../src/core/abTesting.ts"],"sourcesContent":["import { hashString } from '../utils/hash';\n\n/**\n * Deterministically assigns a variant to a session for a given experiment.\n *\n * The assignment is a pure function of `sessionId` + `experimentKey`, so it is\n * stable for the whole session and requires **no** server round-trip before the\n * first render — avoiding layout shift / content flicker. Optional `weights`\n * bias the split (e.g. `[0.9, 0.1]` for a 90/10 rollout).\n *\n * @param sessionId - The current anonymous session id.\n * @param experimentKey - Unique key identifying the experiment.\n * @param variants - The candidate variant names (at least one).\n * @param weights - Optional relative weights, one per variant.\n * @returns The variant assigned to this session.\n *\n * @example\n * assignVariant('sid-1', 'homepage-hero', ['a', 'b']); // stable 'a' | 'b'\n * assignVariant('sid-1', 'homepage-hero', ['a', 'b'], [9, 1]); // ~90% 'a'\n */\nexport const assignVariant = (\n sessionId: string,\n experimentKey: string,\n variants: string[],\n weights?: number[]\n): string => {\n if (variants.length === 0) {\n throw new Error('assignVariant requires at least one variant');\n }\n if (variants.length === 1) return variants[0]!;\n\n // Uniform bucket in [0, 1) derived from the session + experiment.\n const bucket = hashString(`${sessionId}:${experimentKey}`) / 0x100000000;\n\n if (!weights || weights.length !== variants.length) {\n const index = Math.floor(bucket * variants.length);\n return variants[Math.min(index, variants.length - 1)];\n }\n\n const totalWeight = weights.reduce((sum, weight) => sum + weight, 0);\n if (totalWeight <= 0) {\n return variants[Math.floor(bucket * variants.length)];\n }\n\n let cumulative = 0;\n const target = bucket * totalWeight;\n for (let index = 0; index < variants.length; index++) {\n cumulative += weights[index];\n if (target < cumulative) return variants[index];\n }\n\n return variants[variants.length - 1];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,iBACX,WACA,eACA,UACA,YACW;AACX,KAAI,SAAS,WAAW,EACtB,OAAM,IAAI,MAAM,8CAA8C;AAEhE,KAAI,SAAS,WAAW,EAAG,QAAO,SAAS;CAG3C,MAAM,SAASA,8BAAW,GAAG,UAAU,GAAG,gBAAgB,GAAG;AAE7D,KAAI,CAAC,WAAW,QAAQ,WAAW,SAAS,QAAQ;EAClD,MAAM,QAAQ,KAAK,MAAM,SAAS,SAAS,OAAO;AAClD,SAAO,SAAS,KAAK,IAAI,OAAO,SAAS,SAAS,EAAE;;CAGtD,MAAM,cAAc,QAAQ,QAAQ,KAAK,WAAW,MAAM,QAAQ,EAAE;AACpE,KAAI,eAAe,EACjB,QAAO,SAAS,KAAK,MAAM,SAAS,SAAS,OAAO;CAGtD,IAAI,aAAa;CACjB,MAAM,SAAS,SAAS;AACxB,MAAK,IAAI,QAAQ,GAAG,QAAQ,SAAS,QAAQ,SAAS;AACpD,gBAAc,QAAQ;AACtB,MAAI,SAAS,WAAY,QAAO,SAAS;;AAG3C,QAAO,SAAS,SAAS,SAAS"}
|