Skip to content

Commit

Permalink
Merge pull request #217 from datacamp/add-utm-parameters
Browse files Browse the repository at this point in the history
[WL-3239] feat: add utmSource and utmCampaign parameters
  • Loading branch information
jdmunro authored Jan 12, 2024
2 parents 8ca9787 + 6621d13 commit ec4abe8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/boot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default (element: HTMLDivElement, hub: Hub) => {
height: parseInt(element.getAttribute("data-height") || "auto", 10),
};

const utmSource = element.getAttribute("data-utm-source") || undefined;
const utmCampaign = element.getAttribute("data-utm-campaign") || undefined;

if (element.getAttribute("data-encoded")) {
const exercise = JSON.parse(atob(decodeURIComponent(element.textContent)));
settings.hint = exercise.hint;
Expand Down Expand Up @@ -95,7 +98,12 @@ export default (element: HTMLDivElement, hub: Hub) => {
return (
<AppContainer>
<Provider store={store}>
<App height={settings.height} language={settings.language} />
<App
height={settings.height}
language={settings.language}
utmSource={utmSource}
utmCampaign={utmCampaign}
/>
</Provider>
</AppContainer>
);
Expand Down
4 changes: 4 additions & 0 deletions src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export interface IAppProps extends React.Props<App> {
language?: string;
height?: number;
nPlots?: number;
utmSource?: string;
utmCampaign?: string;
}

interface IAppState {
Expand Down Expand Up @@ -317,6 +319,8 @@ export class App extends React.Component<IAppProps, IAppState> {
<Footer
onShowSolution={this.showSolutionTab}
showSolutionButton={this.state.solutionButtonVisible}
utmSource={this.props.utmSource}
utmCampaign={this.props.utmCampaign}
/>
</div>
</Provider>
Expand Down
10 changes: 9 additions & 1 deletion src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface IFooterProps extends React.Props<Footer> {
showRunButton?: boolean;
sct?: string;
language?: string;
utmSource?: string;
utmCampaign?: string;
}

interface IFooterState {
Expand All @@ -37,6 +39,8 @@ export class Footer extends React.PureComponent<IFooterProps, IFooterState> {
isSessionBusy: false,
showSolutionButton: false,
showRunButton: false,
utmSource: "datacamp_light",
utmCampaign: "powered_by_datacamp",
};

public displayName: string = "Footer";
Expand Down Expand Up @@ -72,6 +76,10 @@ export class Footer extends React.PureComponent<IFooterProps, IFooterState> {
}

public render() {
const { utmSource, utmCampaign } = this.props;
const baseUrl = "https://www.datacamp.com/";
const queryParams = `utm_source=${utmSource}&utm_campaign=${utmCampaign}`;
const datacampUrl = `${baseUrl}?${queryParams}`;
return (
<div className={styles.footer}>
{this.props.hint ? (
Expand Down Expand Up @@ -118,7 +126,7 @@ export class Footer extends React.PureComponent<IFooterProps, IFooterState> {
className={styles.restart}
/>
<a
href="https://www.datacamp.com/?utm_source=datacamp_light&utm_campaign=powered_by_datacamp"
href={datacampUrl}
className={styles.logo}
title="Powered by DataCamp"
target="_blank"
Expand Down

0 comments on commit ec4abe8

Please sign in to comment.