nana800-analytics 1.0.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.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Platform types supported by the SDK
3
+ */
4
+ export declare enum PlatformType {
5
+ BROWSER = "BROWSER",
6
+ REACT_NATIVE = "REACT_NATIVE",
7
+ NODE = "NODE",
8
+ ELECTRON = "ELECTRON",
9
+ UNKNOWN = "UNKNOWN"
10
+ }
11
+ /**
12
+ * Detects the current platform
13
+ */
14
+ export declare const detectPlatform: () => PlatformType;
@@ -0,0 +1,15 @@
1
+ import { StorageAdapter, Nana800AnalyticsEvent, Nana800AnalyticsUserIdentity } from '../types';
2
+ import { PlatformType } from '../platform/PlatformDetector';
3
+ /**
4
+ * Manages storage operations across different platforms
5
+ */
6
+ export declare class StorageManager {
7
+ private storageAdapter;
8
+ constructor(platformType: PlatformType, customAdapter?: StorageAdapter, disableStorage?: boolean);
9
+ private initializeDefaultStorage;
10
+ isAvailable(): boolean;
11
+ saveEvents(events: Nana800AnalyticsEvent[]): void;
12
+ saveUserProps(userProps: Nana800AnalyticsUserIdentity[]): void;
13
+ loadEvents(): Promise<Nana800AnalyticsEvent[]>;
14
+ loadUserProps(): Promise<Nana800AnalyticsUserIdentity[]>;
15
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Custom analytics event properties type
3
+ */
4
+ export type Nana800AnalyticsEventProperties = Record<string, string>;
5
+ /**
6
+ * Analytics event interface
7
+ */
8
+ export interface Nana800AnalyticsEvent {
9
+ /**
10
+ * Name of the tracked event
11
+ */
12
+ analytics_event_name: string;
13
+ /**
14
+ * User identifier (optional, can be null for anonymous users)
15
+ */
16
+ user_id: string | null;
17
+ /**
18
+ * Custom event properties as key-value pairs
19
+ */
20
+ properties: Nana800AnalyticsEventProperties;
21
+ /**
22
+ * Event timestamp
23
+ */
24
+ event_time: Date;
25
+ }
26
+ /**
27
+ * User identification properties
28
+ */
29
+ export interface Nana800AnalyticsUserIdentity {
30
+ /**
31
+ * User identifier
32
+ */
33
+ user_id: string;
34
+ /**
35
+ * User properties to update
36
+ */
37
+ properties: Nana800AnalyticsEventProperties;
38
+ }
39
+ /**
40
+ * Storage adapter interface for cross-platform storage support
41
+ * Implement this interface to provide custom storage for different platforms
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // React Native with AsyncStorage
46
+ * import AsyncStorage from '@react-native-async-storage/async-storage';
47
+ *
48
+ * const analytics = new Nana800Analytics({
49
+ * apiKey: 'your-api-key',
50
+ * appProjectId: 'your-project-id',
51
+ * storageAdapter: AsyncStorage
52
+ * });
53
+ * ```
54
+ */
55
+ export interface StorageAdapter {
56
+ setItem(key: string, value: string): Promise<void> | void;
57
+ getItem(key: string): Promise<string | null> | string | null;
58
+ removeItem(key: string): Promise<void> | void;
59
+ }
60
+ /**
61
+ * Configuration for initializing Nana800Analytics
62
+ */
63
+ export interface Nana800AnalyticsConfig {
64
+ /**
65
+ * API key for authentication
66
+ */
67
+ apiKey: string;
68
+ /**
69
+ * Analytics project identifier
70
+ */
71
+ appProjectId: string;
72
+ /**
73
+ * Base URL for the analytics API (optional, defaults to https://api.analytics.nana800.io)
74
+ */
75
+ baseUrl?: string;
76
+ /**
77
+ * Interval in milliseconds for automatic event flushing (default: 20000ms / 20s)
78
+ */
79
+ flushIntervalMs?: number;
80
+ /**
81
+ * Maximum number of events to include in a single batch (default: 100)
82
+ */
83
+ maxBatchSize?: number;
84
+ /**
85
+ * Enable automatic flushing on interval (default: true)
86
+ */
87
+ enableAutoFlush?: boolean;
88
+ /**
89
+ * Custom storage adapter for non-browser environments (optional)
90
+ * Use this to provide AsyncStorage for React Native or custom storage
91
+ */
92
+ storageAdapter?: StorageAdapter;
93
+ /**
94
+ * Disable persistent storage (events will only be kept in memory)
95
+ */
96
+ disableStorage?: boolean;
97
+ /**
98
+ * Enable debug mode with detailed logging (default: false)
99
+ */
100
+ debug?: boolean;
101
+ }
102
+ /**
103
+ * API response from the backend
104
+ */
105
+ export interface Nana800AnalyticsApiResponse {
106
+ success: boolean;
107
+ message?: string;
108
+ }
109
+ /**
110
+ * Request body for tracking events
111
+ */
112
+ export interface TrackEventsRequestBody {
113
+ events: Array<{
114
+ analytics_event_name: string;
115
+ user_id: string | null;
116
+ properties: Nana800AnalyticsEventProperties;
117
+ event_time?: Date;
118
+ }>;
119
+ app_project_id: string;
120
+ api_key: string;
121
+ }
122
+ /**
123
+ * Request body for identifying users
124
+ */
125
+ export interface IdentifyUsersRequestBody {
126
+ list: Array<{
127
+ user_id: string;
128
+ properties: Nana800AnalyticsEventProperties;
129
+ }>;
130
+ app_project_id: string;
131
+ api_key: string;
132
+ }
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "nana800-analytics",
3
+ "version": "1.0.0",
4
+ "files": [
5
+ "dist"
6
+ ],
7
+ "main": "./dist/main.cjs.js",
8
+ "module": "./dist/main.esm.js",
9
+ "exports": {
10
+ ".": {
11
+ "require": "./dist/main.cjs.js",
12
+ "import": "./dist/main.esm.js",
13
+ "types": "./dist/main.d.ts"
14
+ }
15
+ },
16
+ "types": "dist/main.d.ts",
17
+ "scripts": {
18
+ "build": "tsc --emitDeclarationOnly && node scripts/build.js",
19
+ "build:cdn": "node scripts/build-cdn.js",
20
+ "build:all": "yarn build && yarn build:cdn",
21
+ "release": "yarn build:all && npm publish --access public"
22
+ },
23
+ "devDependencies": {
24
+ "@types/lodash": "^4.17.10",
25
+ "@types/node": "^24.7.0",
26
+ "@typescript-eslint/eslint-plugin": "^6.14.0",
27
+ "@typescript-eslint/parser": "^6.14.0",
28
+ "esbuild": "^0.18.1",
29
+ "eslint": "^8.56.0",
30
+ "eslint-config-prettier": "^9.1.0",
31
+ "eslint-plugin-prettier": "^5.0.1",
32
+ "prettier": "^3.1.1",
33
+ "ts-node": "^10.9.2",
34
+ "typescript": "^5.1.3"
35
+ },
36
+ "dependencies": {
37
+ "axios": "1.7.7",
38
+ "lodash": "^4.17.21"
39
+ },
40
+ "keywords": [
41
+ "analytics",
42
+ "nana800",
43
+ "telemetry",
44
+ "tracking",
45
+ "events",
46
+ "amplitude",
47
+ "web analytics",
48
+ "user tracking",
49
+ "event tracking",
50
+ "nana800 analytics",
51
+ "react native",
52
+ "react-native",
53
+ "electron",
54
+ "nodejs",
55
+ "next.js",
56
+ "nextjs",
57
+ "cross-platform",
58
+ "mobile analytics",
59
+ "desktop analytics"
60
+ ]
61
+ }