mirror of
https://github.com/JonasunderscoreJones/blog.jonasjones.dev.git
synced 2025-10-22 16:29:19 +02:00
added analytics tracking
This commit is contained in:
parent
979b8ceb16
commit
778932e9db
16 changed files with 719 additions and 1004 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -22,3 +22,6 @@ dist-ssr
|
|||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
|
||||
.env
|
267
.svelte-kit/ambient.d.ts
vendored
Normal file
267
.svelte-kit/ambient.d.ts
vendored
Normal file
|
@ -0,0 +1,267 @@
|
|||
|
||||
// this file is generated — do not edit it
|
||||
|
||||
|
||||
/// <reference types="@sveltejs/kit" />
|
||||
|
||||
/**
|
||||
* Environment variables [loaded by Vite](https://vitejs.dev/guide/env-and-mode.html#env-files) from `.env` files and `process.env`. Like [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), this module cannot be imported into client-side code. This module only includes variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env) _and do_ start with [`config.kit.env.privatePrefix`](https://kit.svelte.dev/docs/configuration#env) (if configured).
|
||||
*
|
||||
* _Unlike_ [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), the values exported from this module are statically injected into your bundle at build time, enabling optimisations like dead code elimination.
|
||||
*
|
||||
* ```ts
|
||||
* import { API_KEY } from '$env/static/private';
|
||||
* ```
|
||||
*
|
||||
* Note that all environment variables referenced in your code should be declared (for example in an `.env` file), even if they don't have a value until the app is deployed:
|
||||
*
|
||||
* ```
|
||||
* MY_FEATURE_FLAG=""
|
||||
* ```
|
||||
*
|
||||
* You can override `.env` values from the command line like so:
|
||||
*
|
||||
* ```bash
|
||||
* MY_FEATURE_FLAG="enabled" npm run dev
|
||||
* ```
|
||||
*/
|
||||
declare module '$env/static/private' {
|
||||
export const SHELL: string;
|
||||
export const npm_command: string;
|
||||
export const LSCOLORS: string;
|
||||
export const SESSION_MANAGER: string;
|
||||
export const npm_config_userconfig: string;
|
||||
export const COLORTERM: string;
|
||||
export const npm_config_cache: string;
|
||||
export const npm_package_dev_optional: string;
|
||||
export const LESS: string;
|
||||
export const XDG_MENU_PREFIX: string;
|
||||
export const npm_package_integrity: string;
|
||||
export const _P9K_TTY: string;
|
||||
export const NODE: string;
|
||||
export const JAVA_HOME: string;
|
||||
export const SSH_AUTH_SOCK: string;
|
||||
export const P9K_TTY: string;
|
||||
export const MEMORY_PRESSURE_WRITE: string;
|
||||
export const COLOR: string;
|
||||
export const npm_config_local_prefix: string;
|
||||
export const SDKMAN_CANDIDATES_DIR: string;
|
||||
export const XMODIFIERS: string;
|
||||
export const DESKTOP_SESSION: string;
|
||||
export const npm_config_globalconfig: string;
|
||||
export const GPG_TTY: string;
|
||||
export const EDITOR: string;
|
||||
export const PWD: string;
|
||||
export const LOGNAME: string;
|
||||
export const XDG_SESSION_DESKTOP: string;
|
||||
export const QT_QPA_PLATFORMTHEME: string;
|
||||
export const XDG_SESSION_TYPE: string;
|
||||
export const MANPATH: string;
|
||||
export const npm_package_dev: string;
|
||||
export const npm_config_init_module: string;
|
||||
export const SYSTEMD_EXEC_PID: string;
|
||||
export const _: string;
|
||||
export const XAUTHORITY: string;
|
||||
export const GJS_DEBUG_TOPICS: string;
|
||||
export const MOTD_SHOWN: string;
|
||||
export const GDM_LANG: string;
|
||||
export const HOME: string;
|
||||
export const USERNAME: string;
|
||||
export const npm_package_peer: string;
|
||||
export const LANG: string;
|
||||
export const LS_COLORS: string;
|
||||
export const XDG_CURRENT_DESKTOP: string;
|
||||
export const npm_package_version: string;
|
||||
export const MEMORY_PRESSURE_WATCH: string;
|
||||
export const VTE_VERSION: string;
|
||||
export const WAYLAND_DISPLAY: string;
|
||||
export const npm_package_resolved: string;
|
||||
export const INVOCATION_ID: string;
|
||||
export const MANAGERPID: string;
|
||||
export const INIT_CWD: string;
|
||||
export const QT_QPA_PLATFORM: string;
|
||||
export const INFOPATH: string;
|
||||
export const npm_lifecycle_script: string;
|
||||
export const GJS_DEBUG_OUTPUT: string;
|
||||
export const GNOME_SETUP_DISPLAY: string;
|
||||
export const npm_package_optional: string;
|
||||
export const npm_config_npm_version: string;
|
||||
export const XDG_SESSION_CLASS: string;
|
||||
export const TERMINFO: string;
|
||||
export const TERM: string;
|
||||
export const npm_package_name: string;
|
||||
export const npm_config_prefix: string;
|
||||
export const USER: string;
|
||||
export const SDKMAN_DIR: string;
|
||||
export const DISPLAY: string;
|
||||
export const npm_lifecycle_event: string;
|
||||
export const SHLVL: string;
|
||||
export const PAGER: string;
|
||||
export const QT_IM_MODULE: string;
|
||||
export const _P9K_SSH_TTY: string;
|
||||
export const SDKMAN_CANDIDATES_API: string;
|
||||
export const npm_config_user_agent: string;
|
||||
export const npm_execpath: string;
|
||||
export const XDG_RUNTIME_DIR: string;
|
||||
export const npm_package_json: string;
|
||||
export const P9K_SSH: string;
|
||||
export const TREE_COLORS: string;
|
||||
export const JOURNAL_STREAM: string;
|
||||
export const XDG_DATA_DIRS: string;
|
||||
export const npm_config_noproxy: string;
|
||||
export const PATH: string;
|
||||
export const npm_config_node_gyp: string;
|
||||
export const GDMSESSION: string;
|
||||
export const DBUS_SESSION_BUS_ADDRESS: string;
|
||||
export const SDKMAN_PLATFORM: string;
|
||||
export const npm_config_global_prefix: string;
|
||||
export const MAIL: string;
|
||||
export const npm_node_execpath: string;
|
||||
export const OLDPWD: string;
|
||||
export const npm_package_engines_node: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to [`$env/static/private`](https://kit.svelte.dev/docs/modules#$env-static-private), except that it only includes environment variables that begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env) (which defaults to `PUBLIC_`), and can therefore safely be exposed to client-side code.
|
||||
*
|
||||
* Values are replaced statically at build time.
|
||||
*
|
||||
* ```ts
|
||||
* import { PUBLIC_BASE_URL } from '$env/static/public';
|
||||
* ```
|
||||
*/
|
||||
declare module '$env/static/public' {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This module provides access to runtime environment variables, as defined by the platform you're running on. For example if you're using [`adapter-node`](https://github.com/sveltejs/kit/tree/main/packages/adapter-node) (or running [`vite preview`](https://kit.svelte.dev/docs/cli)), this is equivalent to `process.env`. This module only includes variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env) _and do_ start with [`config.kit.env.privatePrefix`](https://kit.svelte.dev/docs/configuration#env) (if configured).
|
||||
*
|
||||
* This module cannot be imported into client-side code.
|
||||
*
|
||||
* Dynamic environment variables cannot be used during prerendering.
|
||||
*
|
||||
* ```ts
|
||||
* import { env } from '$env/dynamic/private';
|
||||
* console.log(env.DEPLOYMENT_SPECIFIC_VARIABLE);
|
||||
* ```
|
||||
*
|
||||
* > In `dev`, `$env/dynamic` always includes environment variables from `.env`. In `prod`, this behavior will depend on your adapter.
|
||||
*/
|
||||
declare module '$env/dynamic/private' {
|
||||
export const env: {
|
||||
SHELL: string;
|
||||
npm_command: string;
|
||||
LSCOLORS: string;
|
||||
SESSION_MANAGER: string;
|
||||
npm_config_userconfig: string;
|
||||
COLORTERM: string;
|
||||
npm_config_cache: string;
|
||||
npm_package_dev_optional: string;
|
||||
LESS: string;
|
||||
XDG_MENU_PREFIX: string;
|
||||
npm_package_integrity: string;
|
||||
_P9K_TTY: string;
|
||||
NODE: string;
|
||||
JAVA_HOME: string;
|
||||
SSH_AUTH_SOCK: string;
|
||||
P9K_TTY: string;
|
||||
MEMORY_PRESSURE_WRITE: string;
|
||||
COLOR: string;
|
||||
npm_config_local_prefix: string;
|
||||
SDKMAN_CANDIDATES_DIR: string;
|
||||
XMODIFIERS: string;
|
||||
DESKTOP_SESSION: string;
|
||||
npm_config_globalconfig: string;
|
||||
GPG_TTY: string;
|
||||
EDITOR: string;
|
||||
PWD: string;
|
||||
LOGNAME: string;
|
||||
XDG_SESSION_DESKTOP: string;
|
||||
QT_QPA_PLATFORMTHEME: string;
|
||||
XDG_SESSION_TYPE: string;
|
||||
MANPATH: string;
|
||||
npm_package_dev: string;
|
||||
npm_config_init_module: string;
|
||||
SYSTEMD_EXEC_PID: string;
|
||||
_: string;
|
||||
XAUTHORITY: string;
|
||||
GJS_DEBUG_TOPICS: string;
|
||||
MOTD_SHOWN: string;
|
||||
GDM_LANG: string;
|
||||
HOME: string;
|
||||
USERNAME: string;
|
||||
npm_package_peer: string;
|
||||
LANG: string;
|
||||
LS_COLORS: string;
|
||||
XDG_CURRENT_DESKTOP: string;
|
||||
npm_package_version: string;
|
||||
MEMORY_PRESSURE_WATCH: string;
|
||||
VTE_VERSION: string;
|
||||
WAYLAND_DISPLAY: string;
|
||||
npm_package_resolved: string;
|
||||
INVOCATION_ID: string;
|
||||
MANAGERPID: string;
|
||||
INIT_CWD: string;
|
||||
QT_QPA_PLATFORM: string;
|
||||
INFOPATH: string;
|
||||
npm_lifecycle_script: string;
|
||||
GJS_DEBUG_OUTPUT: string;
|
||||
GNOME_SETUP_DISPLAY: string;
|
||||
npm_package_optional: string;
|
||||
npm_config_npm_version: string;
|
||||
XDG_SESSION_CLASS: string;
|
||||
TERMINFO: string;
|
||||
TERM: string;
|
||||
npm_package_name: string;
|
||||
npm_config_prefix: string;
|
||||
USER: string;
|
||||
SDKMAN_DIR: string;
|
||||
DISPLAY: string;
|
||||
npm_lifecycle_event: string;
|
||||
SHLVL: string;
|
||||
PAGER: string;
|
||||
QT_IM_MODULE: string;
|
||||
_P9K_SSH_TTY: string;
|
||||
SDKMAN_CANDIDATES_API: string;
|
||||
npm_config_user_agent: string;
|
||||
npm_execpath: string;
|
||||
XDG_RUNTIME_DIR: string;
|
||||
npm_package_json: string;
|
||||
P9K_SSH: string;
|
||||
TREE_COLORS: string;
|
||||
JOURNAL_STREAM: string;
|
||||
XDG_DATA_DIRS: string;
|
||||
npm_config_noproxy: string;
|
||||
PATH: string;
|
||||
npm_config_node_gyp: string;
|
||||
GDMSESSION: string;
|
||||
DBUS_SESSION_BUS_ADDRESS: string;
|
||||
SDKMAN_PLATFORM: string;
|
||||
npm_config_global_prefix: string;
|
||||
MAIL: string;
|
||||
npm_node_execpath: string;
|
||||
OLDPWD: string;
|
||||
npm_package_engines_node: string;
|
||||
[key: `PUBLIC_${string}`]: undefined;
|
||||
[key: `${string}`]: string | undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), but only includes variables that begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env) (which defaults to `PUBLIC_`), and can therefore safely be exposed to client-side code.
|
||||
*
|
||||
* Note that public dynamic environment variables must all be sent from the server to the client, causing larger network requests — when possible, use `$env/static/public` instead.
|
||||
*
|
||||
* Dynamic environment variables cannot be used during prerendering.
|
||||
*
|
||||
* ```ts
|
||||
* import { env } from '$env/dynamic/public';
|
||||
* console.log(env.PUBLIC_DEPLOYMENT_SPECIFIC_VARIABLE);
|
||||
* ```
|
||||
*/
|
||||
declare module '$env/dynamic/public' {
|
||||
export const env: {
|
||||
[key: `PUBLIC_${string}`]: string | undefined;
|
||||
}
|
||||
}
|
20
.svelte-kit/generated/client/app.js
Normal file
20
.svelte-kit/generated/client/app.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
export { matchers } from './matchers.js';
|
||||
|
||||
export const nodes = [
|
||||
() => import('./nodes/0'),
|
||||
() => import('./nodes/1')
|
||||
];
|
||||
|
||||
export const server_loads = [];
|
||||
|
||||
export const dictionary = {
|
||||
|
||||
};
|
||||
|
||||
export const hooks = {
|
||||
handleError: (({ error }) => { console.error(error) }),
|
||||
|
||||
reroute: (() => {})
|
||||
};
|
||||
|
||||
export { default as root } from '../root.svelte';
|
1
.svelte-kit/generated/client/matchers.js
Normal file
1
.svelte-kit/generated/client/matchers.js
Normal file
|
@ -0,0 +1 @@
|
|||
export const matchers = {};
|
1
.svelte-kit/generated/client/nodes/0.js
Normal file
1
.svelte-kit/generated/client/nodes/0.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default as component } from "../../../../node_modules/@sveltejs/kit/src/runtime/components/layout.svelte";
|
1
.svelte-kit/generated/client/nodes/1.js
Normal file
1
.svelte-kit/generated/client/nodes/1.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default as component } from "../../../../src/routes/+error.svelte";
|
25
.svelte-kit/non-ambient.d.ts
vendored
Normal file
25
.svelte-kit/non-ambient.d.ts
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
// this file is generated — do not edit it
|
||||
|
||||
|
||||
declare module "svelte/elements" {
|
||||
export interface HTMLAttributes<T> {
|
||||
'data-sveltekit-keepfocus'?: true | '' | 'off' | undefined | null;
|
||||
'data-sveltekit-noscroll'?: true | '' | 'off' | undefined | null;
|
||||
'data-sveltekit-preload-code'?:
|
||||
| true
|
||||
| ''
|
||||
| 'eager'
|
||||
| 'viewport'
|
||||
| 'hover'
|
||||
| 'tap'
|
||||
| 'off'
|
||||
| undefined
|
||||
| null;
|
||||
'data-sveltekit-preload-data'?: true | '' | 'hover' | 'tap' | 'off' | undefined | null;
|
||||
'data-sveltekit-reload'?: true | '' | 'off' | undefined | null;
|
||||
'data-sveltekit-replacestate'?: true | '' | 'off' | undefined | null;
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
39
.svelte-kit/tsconfig.json
Normal file
39
.svelte-kit/tsconfig.json
Normal file
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"paths": {},
|
||||
"rootDirs": [
|
||||
"..",
|
||||
"./types"
|
||||
],
|
||||
"verbatimModuleSyntax": true,
|
||||
"isolatedModules": true,
|
||||
"lib": [
|
||||
"esnext",
|
||||
"DOM",
|
||||
"DOM.Iterable"
|
||||
],
|
||||
"moduleResolution": "bundler",
|
||||
"module": "esnext",
|
||||
"noEmit": true,
|
||||
"target": "esnext"
|
||||
},
|
||||
"include": [
|
||||
"ambient.d.ts",
|
||||
"non-ambient.d.ts",
|
||||
"./types/**/$types.d.ts",
|
||||
"../vite.config.js",
|
||||
"../vite.config.ts",
|
||||
"../src/**/*.js",
|
||||
"../src/**/*.ts",
|
||||
"../src/**/*.svelte",
|
||||
"../tests/**/*.js",
|
||||
"../tests/**/*.ts",
|
||||
"../tests/**/*.svelte"
|
||||
],
|
||||
"exclude": [
|
||||
"../node_modules/**",
|
||||
"../src/service-worker.js",
|
||||
"../src/service-worker.ts",
|
||||
"../src/service-worker.d.ts"
|
||||
]
|
||||
}
|
1300
package-lock.json
generated
1300
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -21,6 +21,7 @@
|
|||
"vite": "^5.2.12"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sveltejs/kit": "^2.5.22",
|
||||
"marked": "^12.0.2",
|
||||
"svelte-kit": "^1.2.0",
|
||||
"svelte-spa-router": "^4.0.0"
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<script>
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
||||
// Call the analytics function on initial page load and after each navigation
|
||||
let previousPath = '';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
let searchTerm = '';
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import { recordRequest } from './analytics';
|
||||
|
||||
const posts = writable([]);
|
||||
const selectedPost = writable({});
|
||||
|
@ -15,6 +16,7 @@
|
|||
let now = false;
|
||||
|
||||
onMount(async () => {
|
||||
recordRequest();
|
||||
try {
|
||||
const response = await fetch('https://cdn.jonasjones.dev/blog/index.json');
|
||||
const data = await response.json();
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<script lang="ts">
|
||||
export let errorCode: {status: number, message: string} = {status: 404, message: "Not Found"};
|
||||
|
||||
import { onMount } from 'svelte';
|
||||
import { recordRequest } from './analytics';
|
||||
|
||||
onMount(() => {
|
||||
recordRequest();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="error">
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<script lang="ts">
|
||||
import PostList from "../components/PostList.svelte";
|
||||
import { onMount } from "svelte";
|
||||
import { recordRequest } from "./analytics";
|
||||
|
||||
onMount(() => {
|
||||
recordRequest();
|
||||
});
|
||||
|
||||
export let searchquery: string = "";
|
||||
</script>
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
import { marked } from 'marked';
|
||||
import Loading from '../components/Loading.svelte';
|
||||
import NotFound from "./Error.svelte";
|
||||
import navigate from 'svelte-spa-router';
|
||||
import { parse } from "svelte/compiler";
|
||||
import { recordRequest } from './analytics';
|
||||
|
||||
export let params: {year: string, month: string, day: string, title: string} = {
|
||||
year: "",
|
||||
|
@ -31,7 +30,11 @@
|
|||
}
|
||||
|
||||
onMount(async () => {
|
||||
window.addEventListener('popstate', () => {
|
||||
location.reload()
|
||||
});
|
||||
redirectUrl()
|
||||
recordRequest();
|
||||
try {
|
||||
|
||||
if (params.month?.toString().length === 1) {
|
||||
|
@ -87,8 +90,10 @@
|
|||
async function redirectUrl() {
|
||||
while (true) {
|
||||
if (thisHref != location.href) {
|
||||
location.reload()
|
||||
console.log("reloading")
|
||||
if (location.href != "#/") {
|
||||
location.reload()
|
||||
console.log("reloading")
|
||||
}
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
|
|
34
src/routes/analytics.js
Normal file
34
src/routes/analytics.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Function to record the request with analytics
|
||||
export async function recordRequest() {
|
||||
|
||||
const analyticsData = {
|
||||
timestamp: Date.now(),
|
||||
domain: window.location.hostname,
|
||||
method: 'GET', // Assuming the request method is GET; adjust as necessary
|
||||
path: window.location.pathname,
|
||||
};
|
||||
|
||||
console.log('Recording request:', analyticsData);
|
||||
|
||||
const ANALYTICS_URL = 'https://analytics.jonasjones.dev/requests/record/ipunknown';
|
||||
const ANALYTICS_API_KEY = import.meta.env.VITE_ANALYTICS_API_KEY;
|
||||
|
||||
try {
|
||||
const response = await fetch(ANALYTICS_URL, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': ANALYTICS_API_KEY,
|
||||
},
|
||||
body: JSON.stringify(analyticsData),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
console.log('Request recorded successfully');
|
||||
} else {
|
||||
console.error('Failed to record request:', response.status, await response.text());
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error recording request:', error);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue