Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 39a44a3

Browse files
committed
feat: track page analytics and page titles
1 parent 3f1d9cb commit 39a44a3

File tree

7 files changed

+57
-28
lines changed

7 files changed

+57
-28
lines changed

src/components/LayoutContainer/index.jsx

-18
This file was deleted.

src/components/Page/index.jsx

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Page
3+
*
4+
* Handles common stuff for pages.
5+
* Should wrap each page.
6+
*/
7+
import React, { useEffect } from "react";
8+
import PT from "prop-types";
9+
import "./styles.module.scss";
10+
import { formatPageTitle } from "utils/format";
11+
12+
const Page = ({ children, title }) => {
13+
// set page title and triggering analytics
14+
useEffect(() => {
15+
// we set title manually like this instead of using `react-helmet` because of the issue:
16+
// https://github.com/nfl/react-helmet/issues/189
17+
document.title = formatPageTitle(title);
18+
19+
// call analytics if the parent Frame app initialized it
20+
if (window.analytics && typeof window.analytics.page === "function") {
21+
window.analytics.page();
22+
}
23+
}, [title]);
24+
25+
return <div styleName="page">{children}</div>;
26+
};
27+
28+
Page.propTypes = {
29+
children: PT.node,
30+
title: PT.string,
31+
};
32+
33+
export default Page;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.container {
1+
.page {
22
padding: 0 35px 32px;
33
}

src/routes/MyTeamsDetails/index.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import React from "react";
88
import PT from "prop-types";
9-
import LayoutContainer from "components/LayoutContainer";
9+
import Page from "components/Page";
1010
import PageHeader from "components/PageHeader";
1111
import { useData } from "hooks/useData";
1212
import { getTeamById } from "services/teams";
@@ -21,7 +21,7 @@ const MyTeamsDetails = ({ teamId }) => {
2121
const [team, loadingError] = useData(getTeamById, teamId);
2222

2323
return (
24-
<LayoutContainer>
24+
<Page title="Team Details">
2525
{!team ? (
2626
<LoadingIndicator error={loadingError} />
2727
) : (
@@ -32,7 +32,7 @@ const MyTeamsDetails = ({ teamId }) => {
3232
<TeamPositions positions={team.jobs || []} teamId={teamId} />
3333
</>
3434
)}
35-
</LayoutContainer>
35+
</Page>
3636
);
3737
};
3838

src/routes/MyTeamsList/index.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import React, { useCallback, useState, useEffect } from "react";
77
import _ from "lodash";
8-
import LayoutContainer from "components/LayoutContainer";
8+
import Page from "components/Page";
99
import PageHeader from "components/PageHeader";
1010
import Input from "components/Input";
1111
import Pagination from "components/Pagination";
@@ -60,7 +60,7 @@ const MyTeamsList = () => {
6060
);
6161

6262
return (
63-
<LayoutContainer>
63+
<Page title="My Teams">
6464
<PageHeader
6565
title="My Teams"
6666
aside={
@@ -95,7 +95,7 @@ const MyTeamsList = () => {
9595
)}
9696
</>
9797
)}
98-
</LayoutContainer>
98+
</Page>
9999
);
100100
};
101101

src/routes/PositionDetails/index.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import React, { useCallback, useState } from "react";
77
import PT from "prop-types";
8-
import LayoutContainer from "components/LayoutContainer";
8+
import Page from "components/Page";
99
import LoadingIndicator from "components/LoadingIndicator";
1010
import PageHeader from "components/PageHeader";
1111
import { CANDIDATE_STATUS } from "constants";
@@ -30,7 +30,7 @@ const PositionDetails = ({ teamId, positionId }) => {
3030
);
3131

3232
return (
33-
<LayoutContainer>
33+
<Page title="Job Details">
3434
{!position ? (
3535
<LoadingIndicator error={error} />
3636
) : (
@@ -53,7 +53,7 @@ const PositionDetails = ({ teamId, positionId }) => {
5353
/>
5454
</>
5555
)}
56-
</LayoutContainer>
56+
</Page>
5757
);
5858
};
5959

src/utils/format.js

+14
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,17 @@ export const formatDateRange = (startDate, endDate) => {
149149

150150
return `${startDateStr} - ${endDateStr}`;
151151
};
152+
153+
/**
154+
* Format page title to show in the browser header.
155+
*
156+
* @param {string} pageTitle page title
157+
*/
158+
export const formatPageTitle = (pageTitle) => {
159+
let formattedPageTitle = "TaaS | Topcoder";
160+
if (pageTitle) {
161+
formattedPageTitle = pageTitle + " | " + formattedPageTitle;
162+
}
163+
164+
return formattedPageTitle;
165+
};

0 commit comments

Comments
 (0)