Skip to content

Commit

Permalink
Add partytown settings for Google Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
prototypa committed Aug 11, 2023
1 parent 8dbdaf8 commit 03af96f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .vscode/astrowind/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@
"properties": {
"id": {
"type": "string"
},
"partytown": {
"type": "boolean",
"default": true
}
},
"required": ["id"]
Expand Down
4 changes: 2 additions & 2 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SITE_CONFIG, ANALYTICS_CONFIG } from './src/utils/config.ts';
const __dirname = path.dirname(fileURLToPath(import.meta.url));

const whenExternalScripts = (items = []) =>
ANALYTICS_CONFIG.vendors.googleAnalytics.id
ANALYTICS_CONFIG.vendors.googleAnalytics.id && ANALYTICS_CONFIG.vendors.googleAnalytics.partytown
? Array.isArray(items)
? items.map((item) => item())
: [items()]
Expand All @@ -33,7 +33,7 @@ export default defineConfig({

integrations: [
tailwind({
applyBaseStyles: false
applyBaseStyles: false,
}),
sitemap(),
image({
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/Analytics.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { ANALYTICS_CONFIG } from '~/utils/config';

{
ANALYTICS_CONFIG?.vendors?.googleAnalytics?.id ? (
<GoogleAnalytics id={String(ANALYTICS_CONFIG.vendors.googleAnalytics.id)} partytown={true} />
<GoogleAnalytics id={String(ANALYTICS_CONFIG.vendors.googleAnalytics.id)} partytown={ANALYTICS_CONFIG?.vendors?.googleAnalytics?.partytown} />
) : null
}
8 changes: 4 additions & 4 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import yaml from 'js-yaml';
import merge from 'lodash.merge';

import type { MetaSEO } from '~/types';
import type { MetaData } from '~/types';

export interface SiteConfig {
name: string;
Expand All @@ -11,7 +11,7 @@ export interface SiteConfig {
trailingSlash?: boolean;
googleSiteVerificationId?: string;
}
export interface MetaDataConfig extends Omit<MetaSEO, 'title'> {
export interface MetaDataConfig extends Omit<MetaData, 'title'> {
title?: {
default: string;
template: string;
Expand Down Expand Up @@ -61,8 +61,8 @@ export interface AppBlogConfig {
export interface AnalyticsConfig {
vendors: {
googleAnalytics: {
isEnabled?: boolean;
id?: string;
partytown?: boolean;
};
};
}
Expand Down Expand Up @@ -187,8 +187,8 @@ const getAnalytics = () => {
const _default = {
vendors: {
googleAnalytics: {
isEnabled: false,
id: undefined,
partytown: true,
},
},
};
Expand Down

0 comments on commit 03af96f

Please sign in to comment.