-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
2,948 additions
and
1,253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
node_modules | ||
|
||
# Output | ||
.output | ||
.vercel | ||
/.svelte-kit | ||
/build | ||
|
||
# OS | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Env | ||
.env | ||
.env.* | ||
!.env.example | ||
!.env.test | ||
|
||
# Vite | ||
vite.config.js.timestamp-* | ||
vite.config.ts.timestamp-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
engine-strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Sveltekit Demo application for Vercel Web Analytics | ||
|
||
## Setup | ||
|
||
This application was created with the following commands: | ||
|
||
- `cd apps` | ||
- `pnpx sv create sveltekit` (answers: SvelteKit minimal, no Typescript, no additional install, pnpm) | ||
- `cd sveltekit` | ||
- add `src/+layout.js` to include `import { injectWebAnalytics } from '@vercel/analytics/sveltekit'; injectWebAnalytics();` | ||
- edit package.json to add `"@vercel/analytics": "workspace:*"` dependency and change `@sveltejs/adapter-auto` into `@sveltejs/adapter-vercel` | ||
- eddi `svelte.config.js` to change `@sveltejs/adapter-auto` into `@sveltejs/adapter-vercel` | ||
- `pnpm i` | ||
|
||
## Usage | ||
|
||
Start it with `cd apps/sveltekit` + `pnpm dev` and browse to [http://localhost:5173](http://localhost:5173) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": "./.svelte-kit/tsconfig.json", | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"checkJs": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"sourceMap": true, | ||
"strict": true, | ||
"moduleResolution": "bundler" | ||
} | ||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias and https://kit.svelte.dev/docs/configuration#files | ||
// | ||
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes | ||
// from the referenced tsconfig.json - TypeScript does not merge them in | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "sveltekit", | ||
"version": "0.0.1", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"build": "vite build", | ||
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json", | ||
"dev": "vite dev", | ||
"prepare": "svelte-kit sync", | ||
"preview": "vite preview" | ||
}, | ||
"devDependencies": { | ||
"@sveltejs/adapter-vercel": "latest", | ||
"@sveltejs/kit": "latest", | ||
"@sveltejs/vite-plugin-svelte": "latest", | ||
"@vercel/analytics": "workspace:*", | ||
"svelte": "latest", | ||
"svelte-check": "latest", | ||
"typescript": "latest", | ||
"vite": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%sveltekit.assets%/favicon.png" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
%sveltekit.head% | ||
</head> | ||
<body data-sveltekit-preload-data="hover"> | ||
<div style="display: contents">%sveltekit.body%</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { injectWebAnalytics } from '@vercel/analytics/sveltekit'; | ||
|
||
injectWebAnalytics(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Welcome to SvelteKit</h1> | ||
<p>Visit <a href="/bruno">this page</a> to know more...</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script> | ||
import { page } from '$app/stores'; | ||
import { track } from '@vercel/analytics/sveltekit'; | ||
</script> | ||
|
||
<h1>We don't talk about {$page.params.slug}</h1> | ||
|
||
<a href="/" onclick={() => track('go-back', { slug: $page.params.slug })} | ||
>Go back</a | ||
> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import adapter from '@sveltejs/adapter-vercel'; | ||
|
||
/** @type {import('@sveltejs/kit').Config} */ | ||
const config = { | ||
kit: { adapter: adapter() }, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { sveltekit } from '@sveltejs/kit/vite'; | ||
import { defineConfig } from 'vite'; | ||
|
||
export default defineConfig({ | ||
plugins: [sveltekit()], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { get } from 'svelte/store'; | ||
import { inject, track, type AnalyticsProps } from '../generic'; | ||
import { page } from '$app/stores'; | ||
import { browser } from '$app/environment'; | ||
import type {} from '@sveltejs/kit'; // don't remove, ensures ambient types for $app/* are loaded | ||
|
||
function injectWebAnalytics( | ||
props: Omit<AnalyticsProps, 'framework'> = {} | ||
): void { | ||
if (browser) { | ||
const webAnalytics = inject({ | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- route could be undefined in layout.js file | ||
route: get(page).route?.id, | ||
...props, | ||
framework: 'sveltekit', | ||
}); | ||
|
||
if (webAnalytics) { | ||
page.subscribe((value) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- route could be undefined in layout.js file | ||
if (value.route?.id) { | ||
webAnalytics.setRoute(value.route.id); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
export { injectWebAnalytics, track }; | ||
export type { AnalyticsProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.