Skip to content

Commit

Permalink
Make another responsibility more explicit in the analytics shared com…
Browse files Browse the repository at this point in the history
…ponent #3329
  • Loading branch information
davidcmoulton committed May 8, 2024
1 parent f4c224f commit c4d41e0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
17 changes: 0 additions & 17 deletions src/read-side/html-pages/shared-components/analytics/analytics.ts
Expand Up @@ -56,13 +56,6 @@ const renderTagManagerScript = (userId: O.Option<UserId>) => (tagManagerId: stri
</script>
`;

const renderTagManagerNoScript = (tagManagerId: string) => `
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=${tagManagerId}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
`;

export const googleTagManager = (userId: O.Option<UserId>): HtmlFragment => pipe(
process.env.GOOGLE_TAG_MANAGER_ID,
O.fromNullable,
Expand All @@ -72,13 +65,3 @@ export const googleTagManager = (userId: O.Option<UserId>): HtmlFragment => pipe
),
toHtmlFragment,
);

export const googleTagManagerNoScript = (): HtmlFragment => pipe(
process.env.GOOGLE_TAG_MANAGER_ID,
O.fromNullable,
O.match(
constant(''),
renderTagManagerNoScript,
),
toHtmlFragment,
);
@@ -0,0 +1,20 @@
import * as O from 'fp-ts/Option';
import { constant, pipe } from 'fp-ts/function';
import { HtmlFragment, toHtmlFragment } from '../../../../types/html-fragment';

const renderTagManagerNoScript = (tagManagerId: string) => `
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=${tagManagerId}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
`;

export const googleTagManagerNoScript = (): HtmlFragment => pipe(
process.env.GOOGLE_TAG_MANAGER_ID,
O.fromNullable,
O.match(
constant(''),
renderTagManagerNoScript,
),
toHtmlFragment,
);
@@ -1,2 +1,3 @@
export { googleTagManager, googleTagManagerNoScript } from './analytics';
export { fathom } from './fathom';
export { googleTagManager } from './analytics';
export { googleTagManagerNoScript } from './google-tag-manager-no-script';

1 comment on commit c4d41e0

@davidcmoulton
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relates to ticket #3229 (not 3329 as mentioned in the commit message).

Please sign in to comment.