Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Initial commit

Blaumaus1a8ff7a59104
diff --git a/.gitignore b/.gitignore
index 67045665d..53c804d9d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -102,3 +102,4 @@ dist
# TernJS port file
.tern-port
+package-lock.json
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 000000000..109ab8b1c
--- /dev/null
+++ b/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "analytics_script",
+ "version": "1.0.0",
+ "description": "",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/Blaumaus/analytics_script.git"
+ },
+ "author": "Blaumaus <[email protected]>",
+ "license": "Apache-2.0",
+ "bugs": {
+ "url": "https://github.com/Blaumaus/analytics_script/issues"
+ },
+ "homepage": "https://github.com/Blaumaus/analytics_script#readme",
+ "dependencies": {
+ "@types/node": "^14.14.41",
+ "typescript": "^4.2.4"
+ }
+}
diff --git a/src/Lib.ts b/src/Lib.ts
new file mode 100644
index 000000000..2cc7450ee
--- /dev/null
+++ b/src/Lib.ts
@@ -0,0 +1,45 @@
+export interface LibOptions {
+ // When set to `true`, all libraries logs (including possible errors) will be
+ // printed to console and localhost events will be sent to server.
+ debug?: boolean
+
+ // When set to `true`, the tracking library won't send any data to server.
+ // Useful for development purposes when this value is set based on `.env` var.
+ disabled?: boolean
+
+ // By setting this flag to `true`, we will not collect ANY kind of data about the user
+ // with the DNT setting.
+ respectDNT?: boolean
+}
+
+export interface TrackEventOptions {
+
+}
+
+export interface PageViewsOptions {
+
+}
+
+const defaultOptions: LibOptions = {
+ debug: false,
+ disabled: false,
+ respectDNT: false,
+}
+
+export class Lib {
+ constructor(private pid: string, private options?: LibOptions) {
+
+ }
+
+ // Tracks a custom event
+ track(event: TrackEventOptions) {
+
+ }
+
+ // Tracks page views
+ trackPageViews(options?: PageViewsOptions) {
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
new file mode 100644
index 000000000..7be38303b
--- /dev/null
+++ b/src/index.ts
@@ -0,0 +1,26 @@
+import { Lib, LibOptions, TrackEventOptions, PageViewsOptions } from './Lib'
+
+export let LIB_INSTANCE: Lib | null = null
+
+// Initialise the tracking library instance (other methods won't work if the library
+// is not initialised)
+export function init (pid: string, options?: LibOptions): Lib {
+ if (!LIB_INSTANCE) {
+ LIB_INSTANCE = new Lib(pid, options)
+ }
+
+ return LIB_INSTANCE
+}
+
+// Tracks custom events
+export function track (event: TrackEventOptions): void {
+ if (!LIB_INSTANCE) return
+
+ LIB_INSTANCE.track(event)
+}
+
+export function trackViews (options?: PageViewsOptions): void {
+ if (!LIB_INSTANCE) return
+
+ LIB_INSTANCE.trackPageViews(options)
+}
\ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
new file mode 100644
index 000000000..c09c361cd
--- /dev/null
+++ b/tsconfig.json
@@ -0,0 +1,17 @@
+{
+ "compilerOptions": {
+ "moduleResolution": "node",
+ "target": "es5",
+ "module": "es2015",
+ "lib": ["es2015", "es2016", "es2017", "dom"],
+ "strict": true,
+ "allowSyntheticDefaultImports": true,
+ "experimentalDecorators": true,
+ "emitDecoratorMetadata": true,
+ "sourceMap": true,
+ "declaration": false,
+ "outDir": "dist/lib",
+ "typeRoots": ["node_modules/@types"]
+ },
+ "include": ["src"]
+}
\ No newline at end of file