Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PUBLIC_GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX
5 changes: 5 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"socials.facebook.cta": "Facebook",
"socials.facebook.href": "https://www.facebook.com/SeattleCommNet",

"cookieBanner.message": "We use cookies to improve your experience.<br /> By clicking \"Accept\", you consent to the use of analytics cookies.",
"cookieBanner.accept": "Accept",
"cookieBanner.deny": "Deny",
"cookieBanner.settings": "Cookie Settings",


"=== PAGES HOME ===" : "comment",

Expand Down
116 changes: 116 additions & 0 deletions src/lib/components/Analytics.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<script>
import { onMount } from "svelte";
import { fly } from "svelte/transition";

import { PUBLIC_GOOGLE_ANALYTICS_ID } from "$env/static/public";

import { m } from '$lib/paraglide/messages.js';

import Button from "./Button.svelte";

let showBanner = $state(false);

onMount(() => {
const consentStatus = localStorage.getItem("consent_status");

if (consentStatus === null) {
showBanner = true;
} else if (consentStatus === "granted") {
window.gtag("consent", "update", {
analytics_storage: "granted",
ad_storage: "granted",
ad_user_data: "granted",
ad_personalization: "granted",
});
}
});

function handleAccept() {
showBanner = false;
localStorage.setItem("consent_status", "granted");

window.gtag("consent", "update", {
analytics_storage: "granted",
ad_storage: "granted",
ad_user_data: "granted",
ad_personalization: "granted",
});
}

function handleDeny() {
showBanner = false;
localStorage.setItem("consent_status", "denied");
}

export function reopenBanner() {
showBanner = true;
localStorage.removeItem("consent_status");
}
</script>

<svelte:head>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}

window.gtag = gtag;

gtag("consent", "default", {
analytics_storage: "denied",
ad_storage: "denied",
ad_user_data: "denied",
ad_personalization: "denied",
});
</script>

<script async src={`https://www.googletagmanager.com/gtag/js?id=${PUBLIC_GOOGLE_ANALYTICS_ID}`}></script>
<script>
gtag("js", new Date());
gtag("config", "{PUBLIC_GOOGLE_ANALYTICS_ID}");
</script>
</svelte:head>

{#if showBanner}
<div transition:fly="{{ x: 20, duration: 300 }}" class="banner">
<p>
{@html m["cookieBanner.message"]() }
</p>

<div class="buttons">
<Button type="medium" onclick={handleAccept}>{ m["cookieBanner.accept"]() }</Button>
<Button type="medium" onclick={handleDeny}>{ m["cookieBanner.deny"]() }</Button>
</div>
</div>
{/if}

<style lang="postcss">
.banner {
position: fixed;
bottom: 1em;
right: 0;
width: 370px;

background-color: #fff;

padding: 1rem;

border: solid 1px #ccc;
border-right-width:0;
border-top-left-radius: 0.6em;
border-bottom-left-radius: 0.6em;
box-shadow: 0 0 1em #0004;

p {
margin: 0 0 1em;
font-size: 1em;
}
}

.buttons {
display: flex;
gap: 0.5em;
}
</style>
24 changes: 17 additions & 7 deletions src/lib/components/Button.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script lang="ts">
let {
href,
href = null,
children,
type = null,
arrow = null,
dataTest = null,
onclick = null
} = $props();

let cssClass = $state("button");
Expand All @@ -20,12 +21,21 @@
}
</script>

<a href={href} class={cssClass} data-test={dataTest}>
{@render children()}
{#if arrow}
{/if}
</a>
{#if href}
<a href={href} class={cssClass} data-test={dataTest}>
{@render children()}
{#if arrow}
{/if}
</a>
{:else}
<button class={cssClass} data-test={dataTest} onclick={onclick}>
{@render children()}
{#if arrow}
{/if}
</button>
{/if}

<style>
.button {
Expand Down
15 changes: 13 additions & 2 deletions src/lib/components/Footer.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script>
import { m } from '$lib/paraglide/messages.js';
// import { setLocale } from '$lib/paraglide/runtime';
import Button from './Button.svelte';
import Socials from './Socials.svelte';
import Wrapper from './Wrapper.svelte';
import Analytics from './Analytics.svelte';

let analytics;

const buttons = [
{
Expand Down Expand Up @@ -33,14 +35,22 @@
<Button {href} type="medium">{cta}</Button>
</div>
{/each}

<div>
<Button type="medium" onclick={() => analytics?.reopenBanner()}>
{m["cookieBanner.settings"]()}
</Button>
</div>
</div>

<!-- <button onclick={() => setLocale('en')}>en</button> -->
</footer>
</Wrapper>
</div>

<style>
<Analytics bind:this={analytics} />

<style lang="postcss">
.footer {
background-color: var(--color-brand-primary);

Expand All @@ -57,6 +67,7 @@
margin: 0;
}
}

footer {
display: flex;
flex-direction: column;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ a {
color: var(--color-link);
}

button {
color: var(--color-text);
border: none;
cursor: pointer;
}

section {
margin: var(--layout-section-vertical) 0;
}
Expand Down
4 changes: 4 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import Header from '$lib/components/Header.svelte';
import Footer from '$lib/components/Footer.svelte';
import Metatags from '$lib/components/Metatags.svelte';
import Analytics from '$lib/components/Analytics.svelte';

let { children } = $props();
</script>


<Metatags />

<Header />
Expand All @@ -18,6 +20,8 @@

<Footer/>

<Analytics />

<style lang="postcss">

</style>