Skip to content

Commit

Permalink
Merge pull request #838 from digirati-co-uk/hotfix/add-GABlock-back
Browse files Browse the repository at this point in the history
reinstate GA block
  • Loading branch information
Heather0K authored Jan 7, 2025
2 parents f78ad20 + 677f11c commit 99dc1a8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import simpleHtmlBlock from './simple-html-block/simple-html-block';
import currentManifest from './current-manifest-snippet-block';
import simpleMarkdownBlock from './simple-markdown-block/simple-markdown-block';
import { EmbedItem } from '../../frontend/site/blocks/EmbedItem';
import { GABlock } from '../../frontend/shared/atoms/GABlock';

export function getDefaultPageBlockDefinitions(): PageBlockDefinition<any, any, any, any>[] {
return [
Expand All @@ -21,6 +22,7 @@ export function getDefaultPageBlockDefinitions(): PageBlockDefinition<any, any,
(SingleCollection as any)[Symbol.for('slot-model')] as any,
(FeaturedItem as any)[Symbol.for('slot-model')] as any,
(EmbedItem as any)[Symbol.for('slot-model')] as any,
(GABlock as any)[Symbol.for('slot-model')] as any,
simpleMarkdownBlock,
];
}
32 changes: 32 additions & 0 deletions services/madoc-ts/src/frontend/shared/atoms/GABlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { blockEditorFor } from '../../../extensions/page-blocks/block-editor-for';
import { Helmet as _Helmet } from 'react-helmet';
export const GABlock: React.FC<{ gtag: string }> = ({ gtag }) => {
const Helmet = _Helmet as any;
if (gtag && gtag !== '') {
return (
<Helmet>
{/* Global site tag (gtag.js) - Google Analytics */}
<script async src={`https://www.googletagmanager.com/gtag/js?id=${gtag}`}></script>
<script>
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', "${gtag}");
`}
</script>
</Helmet>
);
}

return null;
};
blockEditorFor(GABlock, {
label: 'Google analytics basic',
type: 'default.GABlock',
defaultProps: { gtag: '' },
editor: {
gtag: { type: 'text-field', label: 'Paste Measurement Id ' },
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { useApi, useIsApiRestarting } from '../../../shared/hooks/use-api';
import { AutoSlotLoader } from '../../../shared/page-blocks/auto-slot-loader';
import { Slot } from '../../../shared/page-blocks/slot';
import { GlobalMenuStack } from '../../blocks/GlobalMenuStack';
import { GABlock } from '../../../shared/atoms/GABlock';
import { AvailableBlocks } from '../../../shared/page-blocks/available-blocks';

export const GlobalSiteHeader: React.FC<{ menu?: any }> = () => {
const api = useApi();
Expand All @@ -23,6 +25,9 @@ export const GlobalSiteHeader: React.FC<{ menu?: any }> = () => {
<GlobalMenuStack />
<FlexSpacer />
<GlobalSearch />
<AvailableBlocks>
<GABlock gtag="" />
</AvailableBlocks>
</Slot>
</SiteHeader>
</SiteHeaderBackground>
Expand Down

0 comments on commit 99dc1a8

Please sign in to comment.