Skip to content

Commit

Permalink
Merge pull request #45 from felix-berlin/42-support-astro-viewtransit…
Browse files Browse the repository at this point in the history
…ions

Add SPA and PWA support
  • Loading branch information
felix-berlin authored Feb 2, 2025
2 parents 7d94723 + 9b12fd6 commit 8b15b0f
Show file tree
Hide file tree
Showing 11 changed files with 1,789 additions and 151 deletions.
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ yarn add astro-matomo

## Options

| Options | Type | Description |
| ------------------ | --------- | --------------------------------------------------------- |
| `enabled` | `boolean` | Controls if the matomo script should be loaded |
| `host` | `string` | Url to your matomo installation |
| `siteId` | `number` | Matomo site id. |
| `heartBeatTimer?` | `number` | If set the heart beat timer will be enabled |
| `disableCookies?` | `boolean` | If set cookies will be disabled |
| `preconnect?` | `boolean` | Will create a preconnect link pointing to the matomo host |
| `setCookieDomain?` | `string` | Share the tracking cookie across multiple domains |
| `trackerUrl?` | `string` | Defaults to matomo.php |
| `srcUrl?` | `string` | Defaults to matomo.js |
| `debug?` | `boolean` | Activate debug mode |
| `partytown?` | `boolean` | Adds [Partytown](https://partytown.builder.io/) support. Matomo added as: `<script type="text/partytown">...</script>` |
| `crossOrigin?` | `string` | Set `crossorigin` attribute |
| Options | Type | Description |
| ------------------ | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `enabled` | `boolean` | Controls if the matomo script should be loaded |
| `host` | `string` | Url to your matomo installation |
| `siteId` | `number` | Matomo site id. |
| `heartBeatTimer?` | `number` | If set the heart beat timer will be enabled |
| `disableCookies?` | `boolean` | If set cookies will be disabled |
| `preconnect?` | `boolean` | Will create a preconnect link pointing to the matomo host |
| `setCookieDomain?` | `string` | Share the tracking cookie across multiple domains |
| `trackerUrl?` | `string` | Defaults to matomo.php |
| `srcUrl?` | `string` | Defaults to matomo.js |
| `debug?` | `boolean` | Activate debug mode |
| `partytown?` | `boolean` | Adds [Partytown](https://partytown.builder.io/) support. Matomo added as: `<script type="text/partytown">...</script>` |
| `crossOrigin?` | `string` | Set `crossorigin` attribute |
| `viewTransition?` | `boolean or { contentElement: string }` | If true Matomo works in "SPA Mode" and will track every page visit after `astro:page-load`. When you pass a selector to `contentElement` Matomo is able to track new media files, forms and content |

## Example usage

Expand All @@ -54,6 +55,9 @@ export default defineConfig({
heartBeatTimer: 5,
disableCookies: true,
debug: false,
viewTransition: {
contentElement: "main"
}
}),
]
});
Expand All @@ -62,20 +66,18 @@ export default defineConfig({

## Development

Make the package available in your local environment:
Go to demo directory:

```bash
pnpm link .

npm link
cd demo
```

Go to the demo project and link the package:
Go to the demo project and install the dev package:

```bash
pnpm link astro-matomo
pnpm install

npm link astro-matomo
npm install
```

Start the dev server:
Expand Down
3 changes: 2 additions & 1 deletion demo/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export default defineConfig({
host: "https://analytics.webshaped.de/",
setCookieDomain: "*.localhost",
siteId: 9,
debug: true,
debug: false,
heartBeatTimer: 5,
preconnect: true,
viewTransition: true,
}),
],
});
4 changes: 2 additions & 2 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"preinstall": "npx only-allow pnpm"
},
"dependencies": {
"astro": "^5.0.2",
"astro-matomo": "^1.6.0"
"astro": "^5.2.3",
"astro-matomo": "file:.."
}
}
68 changes: 39 additions & 29 deletions demo/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
---
import { ClientRouter } from "astro:transitions";
export interface Props {
title: string;
title: string;
}
const { title } = Astro.props;
---

<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
</head>
<body>
<slot />
</body>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>

<ClientRouter />
</head>
<body>
<slot />
</body>
</html>
<style is:global>
:root {
--accent: 124, 58, 237;
--accent-gradient: linear-gradient(
45deg,
rgb(var(--accent)),
#da62c4 30%,
white 60%
);
}
html {
font-family: system-ui, sans-serif;
background-color: #f6f6f6;
}
code {
font-family: Menlo, Monaco, Lucida Console, Liberation Mono,
DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace;
}
:root {
--accent: 124, 58, 237;
--accent-gradient: linear-gradient(
45deg,
rgb(var(--accent)),
#da62c4 30%,
white 60%
);
}
html {
font-family: system-ui, sans-serif;
background-color: #f6f6f6;
}
code {
font-family:
Menlo,
Monaco,
Lucida Console,
Liberation Mono,
DejaVu Sans Mono,
Bitstream Vera Sans Mono,
Courier New,
monospace;
}
</style>
147 changes: 74 additions & 73 deletions demo/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,81 +1,82 @@
---
import Layout from '../layouts/Layout.astro';
import Card from '../components/Card.astro';
import Layout from "../layouts/Layout.astro";
import Card from "../components/Card.astro";
---

<Layout title="Welcome to Astro.">
<main>
<h1>Welcome to <span class="text-gradient">Astro</span></h1>
<p class="instructions">
To get started, open the directory <code>src/pages</code> in your project.<br />
<strong>Code Challenge:</strong> Tweak the "Welcome to Astro" message above.
</p>
<ul role="list" class="link-card-grid">
<Card
href="https://docs.astro.build/"
title="Documentation"
body="Learn how Astro works and explore the official API docs."
/>
<Card
href="https://astro.build/integrations/"
title="Integrations"
body="Supercharge your project with new frameworks and libraries."
/>
<Card
href="https://astro.build/themes/"
title="Themes"
body="Explore a galaxy of community-built starter themes."
/>
<Card
href="https://astro.build/chat/"
title="Community"
body="Come say hi to our amazing Discord community. ❤️"
/>
</ul>
</main>
<main>
<h1>Welcome to <span class="text-gradient">Astro</span></h1>
<p class="instructions">
To get started, open the directory <code>src/pages</code> in your project.<br
/>
<strong>Code Challenge:</strong> Tweak the "Welcome to Astro" message above.
</p>
<ul role="list" class="link-card-grid">
<Card
href="/page-1"
title="Page 1"
body="Learn how Astro works and explore the official API docs."
/>
<Card
href="/page-2"
title="Page 2"
body="Supercharge your project with new frameworks and libraries."
/>
<Card
href="/"
title="Index"
body="Explore a galaxy of community-built starter themes."
/>
<Card
href="https://astro.build/chat/"
title="Community"
body="Come say hi to our amazing Discord community. ❤️"
/>
</ul>
</main>
</Layout>

<style>
main {
margin: auto;
padding: 1.5rem;
max-width: 60ch;
}
h1 {
font-size: 3rem;
font-weight: 800;
margin: 0;
}
.text-gradient {
background-image: var(--accent-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-size: 400%;
background-position: 0%;
}
.instructions {
line-height: 1.6;
margin: 1rem 0;
border: 1px solid rgba(var(--accent), 25%);
background-color: white;
padding: 1rem;
border-radius: 0.4rem;
}
.instructions code {
font-size: 0.875em;
font-weight: bold;
background: rgba(var(--accent), 12%);
color: rgb(var(--accent));
border-radius: 4px;
padding: 0.3em 0.45em;
}
.instructions strong {
color: rgb(var(--accent));
}
.link-card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(24ch, 1fr));
gap: 1rem;
padding: 0;
}
main {
margin: auto;
padding: 1.5rem;
max-width: 60ch;
}
h1 {
font-size: 3rem;
font-weight: 800;
margin: 0;
}
.text-gradient {
background-image: var(--accent-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-size: 400%;
background-position: 0%;
}
.instructions {
line-height: 1.6;
margin: 1rem 0;
border: 1px solid rgba(var(--accent), 25%);
background-color: white;
padding: 1rem;
border-radius: 0.4rem;
}
.instructions code {
font-size: 0.875em;
font-weight: bold;
background: rgba(var(--accent), 12%);
color: rgb(var(--accent));
border-radius: 4px;
padding: 0.3em 0.45em;
}
.instructions strong {
color: rgb(var(--accent));
}
.link-card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(24ch, 1fr));
gap: 1rem;
padding: 0;
}
</style>
Loading

0 comments on commit 8b15b0f

Please sign in to comment.