@flare-engine/analytics 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 +33 -0
- package/dist/index.d.mts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +24 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Grzegorz Otto
|
|
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
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @flare-engine/analytics
|
|
2
|
+
|
|
3
|
+
Typed `AnalyticsProvider` interface + `NoopAnalyticsProvider` + React context. Stub-only at 0.1.0; concrete adapters (PostHog, Amplitude, Segment, Firebase) land at 0.2.0.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @flare-engine/analytics
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import {
|
|
15
|
+
AnalyticsContext,
|
|
16
|
+
useAnalytics,
|
|
17
|
+
NoopAnalyticsProvider,
|
|
18
|
+
} from '@flare-engine/analytics';
|
|
19
|
+
|
|
20
|
+
export function App() {
|
|
21
|
+
return (
|
|
22
|
+
<AnalyticsContext.Provider value={NoopAnalyticsProvider}>
|
|
23
|
+
{/* ... */}
|
|
24
|
+
</AnalyticsContext.Provider>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`useAnalytics()` returns the provider; call `track(event, props)`, `screen(name)`, `identify(userId, traits)` against the interface — swapping `NoopAnalyticsProvider` for a real adapter at 0.2.0 requires no consumer changes.
|
|
30
|
+
|
|
31
|
+
## Recipe — env-var-gated lazy load
|
|
32
|
+
|
|
33
|
+
When 0.2.0 adapters land (e.g. `@flare-engine/analytics-posthog`), wrap them behind an env-var gate so CI / unit tests / dev builds without API keys fall back to `NoopAnalyticsProvider` and never touch the native SDK. See [.github/skills/flare-tier2-stubs/SKILL.md § Lazy-SDK adapter recipe](../../.github/skills/flare-tier2-stubs/SKILL.md#lazy-sdk-adapter-recipe) for the full pattern; canonical implementation at [apps/pan-tvardowski/src/iap/provider.ts](../../apps/pan-tvardowski/src/iap/provider.ts) (RevenueCat / IAP — same shape).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/** Free-form event properties — adapters serialize as needed. */
|
|
4
|
+
type AnalyticsProps = Record<string, unknown>;
|
|
5
|
+
/** A single tracked event. */
|
|
6
|
+
interface AnalyticsEvent {
|
|
7
|
+
name: string;
|
|
8
|
+
props?: AnalyticsProps;
|
|
9
|
+
/** Unix ms when the event was produced. */
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Analytics provider interface. Consumers supply a concrete adapter (PostHog,
|
|
14
|
+
* Amplitude, Segment, Firebase Analytics) at the app boundary. Batching,
|
|
15
|
+
* sampling, and offline queueing are adapter concerns — the interface is
|
|
16
|
+
* deliberately thin so any SDK can back it.
|
|
17
|
+
*/
|
|
18
|
+
interface AnalyticsProvider {
|
|
19
|
+
track(event: string, props?: AnalyticsProps): Promise<void>;
|
|
20
|
+
identify(userId: string, traits?: AnalyticsProps): Promise<void>;
|
|
21
|
+
screen(name: string, props?: AnalyticsProps): Promise<void>;
|
|
22
|
+
flush(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/** Default no-op provider. Resolves immediately; retains nothing. */
|
|
25
|
+
declare const NoopAnalyticsProvider: AnalyticsProvider;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* React context carrying the active `AnalyticsProvider`. Defaults to
|
|
29
|
+
* `NoopAnalyticsProvider`.
|
|
30
|
+
*/
|
|
31
|
+
declare const AnalyticsContext: react.Context<AnalyticsProvider>;
|
|
32
|
+
/** Hook returning the current `AnalyticsProvider`. */
|
|
33
|
+
declare function useAnalytics(): AnalyticsProvider;
|
|
34
|
+
|
|
35
|
+
export { AnalyticsContext, type AnalyticsEvent, type AnalyticsProps, type AnalyticsProvider, NoopAnalyticsProvider, useAnalytics };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/** Free-form event properties — adapters serialize as needed. */
|
|
4
|
+
type AnalyticsProps = Record<string, unknown>;
|
|
5
|
+
/** A single tracked event. */
|
|
6
|
+
interface AnalyticsEvent {
|
|
7
|
+
name: string;
|
|
8
|
+
props?: AnalyticsProps;
|
|
9
|
+
/** Unix ms when the event was produced. */
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Analytics provider interface. Consumers supply a concrete adapter (PostHog,
|
|
14
|
+
* Amplitude, Segment, Firebase Analytics) at the app boundary. Batching,
|
|
15
|
+
* sampling, and offline queueing are adapter concerns — the interface is
|
|
16
|
+
* deliberately thin so any SDK can back it.
|
|
17
|
+
*/
|
|
18
|
+
interface AnalyticsProvider {
|
|
19
|
+
track(event: string, props?: AnalyticsProps): Promise<void>;
|
|
20
|
+
identify(userId: string, traits?: AnalyticsProps): Promise<void>;
|
|
21
|
+
screen(name: string, props?: AnalyticsProps): Promise<void>;
|
|
22
|
+
flush(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/** Default no-op provider. Resolves immediately; retains nothing. */
|
|
25
|
+
declare const NoopAnalyticsProvider: AnalyticsProvider;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* React context carrying the active `AnalyticsProvider`. Defaults to
|
|
29
|
+
* `NoopAnalyticsProvider`.
|
|
30
|
+
*/
|
|
31
|
+
declare const AnalyticsContext: react.Context<AnalyticsProvider>;
|
|
32
|
+
/** Hook returning the current `AnalyticsProvider`. */
|
|
33
|
+
declare function useAnalytics(): AnalyticsProvider;
|
|
34
|
+
|
|
35
|
+
export { AnalyticsContext, type AnalyticsEvent, type AnalyticsProps, type AnalyticsProvider, NoopAnalyticsProvider, useAnalytics };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AnalyticsContext: () => AnalyticsContext,
|
|
24
|
+
NoopAnalyticsProvider: () => NoopAnalyticsProvider,
|
|
25
|
+
useAnalytics: () => useAnalytics
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/provider.ts
|
|
30
|
+
var NoopAnalyticsProvider = {
|
|
31
|
+
async track() {
|
|
32
|
+
},
|
|
33
|
+
async identify() {
|
|
34
|
+
},
|
|
35
|
+
async screen() {
|
|
36
|
+
},
|
|
37
|
+
async flush() {
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/context.ts
|
|
42
|
+
var import_react = require("react");
|
|
43
|
+
var AnalyticsContext = (0, import_react.createContext)(NoopAnalyticsProvider);
|
|
44
|
+
function useAnalytics() {
|
|
45
|
+
return (0, import_react.useContext)(AnalyticsContext);
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
AnalyticsContext,
|
|
50
|
+
NoopAnalyticsProvider,
|
|
51
|
+
useAnalytics
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/provider.ts","../src/context.ts"],"sourcesContent":["export {\n NoopAnalyticsProvider,\n type AnalyticsEvent,\n type AnalyticsProps,\n type AnalyticsProvider,\n} from './provider.js';\nexport { AnalyticsContext, useAnalytics } from './context.js';\n","/** Free-form event properties — adapters serialize as needed. */\nexport type AnalyticsProps = Record<string, unknown>;\n\n/** A single tracked event. */\nexport interface AnalyticsEvent {\n name: string;\n props?: AnalyticsProps;\n /** Unix ms when the event was produced. */\n timestamp: number;\n}\n\n/**\n * Analytics provider interface. Consumers supply a concrete adapter (PostHog,\n * Amplitude, Segment, Firebase Analytics) at the app boundary. Batching,\n * sampling, and offline queueing are adapter concerns — the interface is\n * deliberately thin so any SDK can back it.\n */\nexport interface AnalyticsProvider {\n track(event: string, props?: AnalyticsProps): Promise<void>;\n identify(userId: string, traits?: AnalyticsProps): Promise<void>;\n screen(name: string, props?: AnalyticsProps): Promise<void>;\n flush(): Promise<void>;\n}\n\n/** Default no-op provider. Resolves immediately; retains nothing. */\nexport const NoopAnalyticsProvider: AnalyticsProvider = {\n async track(): Promise<void> {\n // no-op\n },\n async identify(): Promise<void> {\n // no-op\n },\n async screen(): Promise<void> {\n // no-op\n },\n async flush(): Promise<void> {\n // no-op\n },\n};\n","import { createContext, useContext } from 'react';\nimport { type AnalyticsProvider, NoopAnalyticsProvider } from './provider.js';\n\n/**\n * React context carrying the active `AnalyticsProvider`. Defaults to\n * `NoopAnalyticsProvider`.\n */\nexport const AnalyticsContext = createContext<AnalyticsProvider>(NoopAnalyticsProvider);\n\n/** Hook returning the current `AnalyticsProvider`. */\nexport function useAnalytics(): AnalyticsProvider {\n return useContext(AnalyticsContext);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACyBO,IAAM,wBAA2C;AAAA,EACtD,MAAM,QAAuB;AAAA,EAE7B;AAAA,EACA,MAAM,WAA0B;AAAA,EAEhC;AAAA,EACA,MAAM,SAAwB;AAAA,EAE9B;AAAA,EACA,MAAM,QAAuB;AAAA,EAE7B;AACF;;;ACtCA,mBAA0C;AAOnC,IAAM,uBAAmB,4BAAiC,qBAAqB;AAG/E,SAAS,eAAkC;AAChD,aAAO,yBAAW,gBAAgB;AACpC;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/provider.ts
|
|
2
|
+
var NoopAnalyticsProvider = {
|
|
3
|
+
async track() {
|
|
4
|
+
},
|
|
5
|
+
async identify() {
|
|
6
|
+
},
|
|
7
|
+
async screen() {
|
|
8
|
+
},
|
|
9
|
+
async flush() {
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/context.ts
|
|
14
|
+
import { createContext, useContext } from "react";
|
|
15
|
+
var AnalyticsContext = createContext(NoopAnalyticsProvider);
|
|
16
|
+
function useAnalytics() {
|
|
17
|
+
return useContext(AnalyticsContext);
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
AnalyticsContext,
|
|
21
|
+
NoopAnalyticsProvider,
|
|
22
|
+
useAnalytics
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider.ts","../src/context.ts"],"sourcesContent":["/** Free-form event properties — adapters serialize as needed. */\nexport type AnalyticsProps = Record<string, unknown>;\n\n/** A single tracked event. */\nexport interface AnalyticsEvent {\n name: string;\n props?: AnalyticsProps;\n /** Unix ms when the event was produced. */\n timestamp: number;\n}\n\n/**\n * Analytics provider interface. Consumers supply a concrete adapter (PostHog,\n * Amplitude, Segment, Firebase Analytics) at the app boundary. Batching,\n * sampling, and offline queueing are adapter concerns — the interface is\n * deliberately thin so any SDK can back it.\n */\nexport interface AnalyticsProvider {\n track(event: string, props?: AnalyticsProps): Promise<void>;\n identify(userId: string, traits?: AnalyticsProps): Promise<void>;\n screen(name: string, props?: AnalyticsProps): Promise<void>;\n flush(): Promise<void>;\n}\n\n/** Default no-op provider. Resolves immediately; retains nothing. */\nexport const NoopAnalyticsProvider: AnalyticsProvider = {\n async track(): Promise<void> {\n // no-op\n },\n async identify(): Promise<void> {\n // no-op\n },\n async screen(): Promise<void> {\n // no-op\n },\n async flush(): Promise<void> {\n // no-op\n },\n};\n","import { createContext, useContext } from 'react';\nimport { type AnalyticsProvider, NoopAnalyticsProvider } from './provider.js';\n\n/**\n * React context carrying the active `AnalyticsProvider`. Defaults to\n * `NoopAnalyticsProvider`.\n */\nexport const AnalyticsContext = createContext<AnalyticsProvider>(NoopAnalyticsProvider);\n\n/** Hook returning the current `AnalyticsProvider`. */\nexport function useAnalytics(): AnalyticsProvider {\n return useContext(AnalyticsContext);\n}\n"],"mappings":";AAyBO,IAAM,wBAA2C;AAAA,EACtD,MAAM,QAAuB;AAAA,EAE7B;AAAA,EACA,MAAM,WAA0B;AAAA,EAEhC;AAAA,EACA,MAAM,SAAwB;AAAA,EAE9B;AAAA,EACA,MAAM,QAAuB;AAAA,EAE7B;AACF;;;ACtCA,SAAS,eAAe,kBAAkB;AAOnC,IAAM,mBAAmB,cAAiC,qBAAqB;AAG/E,SAAS,eAAkC;AAChD,SAAO,WAAW,gBAAgB;AACpC;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flare-engine/analytics",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Analytics provider interface (consumer-supplied adapter)",
|
|
5
|
+
"keywords": ["flare-engine", "analytics", "provider", "interface"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Grzegorz Otto",
|
|
8
|
+
"homepage": "https://github.com/grzott/flare-engine#readme",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/grzott/flare-engine/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/grzott/flare-engine.git",
|
|
15
|
+
"directory": "packages/analytics"
|
|
16
|
+
},
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"require": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"test": "bun test",
|
|
31
|
+
"lint": "biome check src/",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/react": "^18.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": ">=18.0.0"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "restricted",
|
|
42
|
+
"registry": "https://registry.npmjs.org/"
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": false
|
|
45
|
+
}
|