Skip to content

Commit 624a624

Browse files
TCA-314 #comment This commit adds GTM to FCC w/env-specific accounts #time 15m
1 parent 8b40670 commit 624a624

File tree

8 files changed

+54
-3
lines changed

8 files changed

+54
-3
lines changed

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"react-dom": "16.14.0",
9797
"react-final-form": "6.5.9",
9898
"react-ga": "3.3.0",
99+
"react-gtm-module": "^2.0.11",
99100
"react-helmet": "6.1.0",
100101
"react-hotkeys": "2.0.0",
101102
"react-i18next": "11.16.9",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { FC } from 'react';
2+
import TagManager from 'react-gtm-module';
3+
4+
import {
5+
devTagManagerId,
6+
prodTagManagerId
7+
} from '../../../../config/analytics-settings';
8+
9+
import envData from '../../../../config/env.json';
10+
11+
/* eslint-disable @typescript-eslint/ban-types */
12+
const GoogleTagManager: FC<{}> = () => {
13+
// if we have an ID
14+
// then tags are supported in this environment,
15+
// so initialize them
16+
const segmentId =
17+
envData.deploymentEnv === 'staging' ? devTagManagerId : prodTagManagerId;
18+
if (segmentId) {
19+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
20+
/* eslint-disable @typescript-eslint/no-unsafe-call */
21+
TagManager.initialize({
22+
gtmId: segmentId
23+
});
24+
}
25+
26+
return null;
27+
};
28+
29+
export default GoogleTagManager;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as GoogleTagManager } from './GoogleTagManager';

client/src/analytics/segment/Segment.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ interface SegmentModel {
1414

1515
const segmentModel: SegmentModel = segment as unknown as SegmentModel;
1616

17-
const Segment: FC<null> = () => {
17+
/* eslint-disable @typescript-eslint/ban-types */
18+
const Segment: FC<{}> = () => {
1819
// if we have a key for this environment, load it
1920
const segmentId =
2021
envData.deploymentEnv === 'staging' ? devSegmentId : prodSegmentId;

client/src/templates/Challenges/classic/desktop-layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { useState, ReactElement } from 'react';
33
import { ReflexContainer, ReflexSplitter, ReflexElement } from 'react-reflex';
44
import { sortChallengeFiles } from '../../../../../utils/sort-challengefiles';
55
import { challengeTypes } from '../../../../utils/challenge-types';
6+
import { GoogleTagManager } from '../../../analytics/google-tag-manater';
67
import { Segment } from '../../../analytics/segment';
78
import {
89
ChallengeFile,
@@ -194,6 +195,7 @@ const DesktopLayout = (props: DesktopLayoutProps): JSX.Element => {
194195
</div>
195196

196197
<Segment />
198+
<GoogleTagManager />
197199
</>
198200
);
199201
};

client/src/templates/Challenges/classic/tc-layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { ReactElement } from 'react';
33
import { ReflexContainer, ReflexSplitter, ReflexElement } from 'react-reflex';
44

55
import { sortChallengeFiles } from '../../../../../utils/sort-challengefiles';
6+
import { GoogleTagManager } from '../../../analytics/google-tag-manater';
67
import Segment from '../../../analytics/segment/Segment';
78
import {
89
ChallengeFile,
@@ -132,6 +133,7 @@ const TcLayout = (props: TcLayoutProps): JSX.Element => {
132133
</div>
133134

134135
<Segment />
136+
<GoogleTagManager />
135137
</>
136138
);
137139
};

config/analytics-settings.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
exports.prodAnalyticsId = null;
2-
exports.prodSegmentId = '8fCbi94o3ruUUGxRRGxWu194t6iVq9LH';
3-
42
exports.devAnalyticsId = null;
3+
4+
exports.prodSegmentId = '8fCbi94o3ruUUGxRRGxWu194t6iVq9LH';
55
// TODO: TCA-371 set this to null so we're not tracking non-prod
66
exports.devSegmentId = '8fCbi94o3ruUUGxRRGxWu194t6iVq9LH';
7+
8+
exports.prodTagManagerId = 'GTM-MXXQHG8';
9+
exports.devTagManagerId = 'GTM-W7B537Z';

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)