Skip to content

Commit

Permalink
add google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
steve8708 committed May 5, 2024
1 parent 232205e commit 85bfbfd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"devDependencies": {
"@builder.io/mitosis": "latest",
"@builder.io/partytown": "^0.8.1",
"@builder.io/qwik": "^1.5.2",
"@builder.io/qwik-city": "^1.5.2",
"@builder.io/qwik-labs-canary": "^0.0.1",
Expand Down
18 changes: 18 additions & 0 deletions packages/docs/src/components/partytown/partytown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { PartytownConfig, partytownSnippet } from '@builder.io/partytown/integration';

/**
* Props for `<QwikPartytown/>`, which extends the Partytown Config.
*
* https://github.com/BuilderIO/partytown#config
*
* @public
*/
export interface PartytownProps extends PartytownConfig {}

/**
* @public
* You can pass setting with props
*/
export const QwikPartytown = (props: PartytownProps): any => {
return <script dangerouslySetInnerHTML={partytownSnippet(props)} />;
};
16 changes: 16 additions & 0 deletions packages/docs/src/components/router-head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ export const RouterHead = component$(() => {
{head.scripts.map((s) => (
<script key={s.key} {...s.props} dangerouslySetInnerHTML={s.script} />
))}

<script
type="text/partytown"
async
src="https://www.googletagmanager.com/gtag/js?id=G-P6ZRY0ZT14"
></script>
<script
type="text/partytown"
dangerouslySetInnerHTML={`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-P6ZRY0ZT14');
`}
/>
</>
);
});
6 changes: 3 additions & 3 deletions packages/docs/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
* This is the base config for vite.
* When building, the adapter config is used which loads this file and extends it.
*/
import { partytownVite } from '@builder.io/partytown/utils';
import { qwikCity } from '@builder.io/qwik-city/vite';
import { qwikInsights } from '@builder.io/qwik-labs-canary/vite';
import { qwikVite } from '@builder.io/qwik/optimizer';
import { join } from 'path';
import { defineConfig, type UserConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { replaceCodePlugin } from 'vite-plugin-replace';
import tsconfigPaths from 'vite-tsconfig-paths';
import pkg from './package.json';

const { dependencies = {}, devDependencies = {} } = pkg as any as {
dependencies: Record<string, string>;
devDependencies: Record<string, string>;
[key: string]: unknown;
};

/**
* Note that Vite normally starts from `index.html` but the qwikCity plugin makes start at `src/entry.ssr.tsx` instead.
*/
Expand All @@ -33,7 +33,6 @@ export default defineConfig(({ command, mode }): UserConfig => {
qwikInsights({
publicApiKey: '22gsbhtjcyv',
}),

replaceCodePlugin({
replacements: [
{
Expand All @@ -42,6 +41,7 @@ export default defineConfig(({ command, mode }): UserConfig => {
},
],
}),
partytownVite({ dest: join(__dirname, 'dist', '~partytown') }),
],
// This tells Vite which dependencies to pre-build in dev mode.
optimizeDeps: {
Expand Down

0 comments on commit 85bfbfd

Please sign in to comment.