Skip to content

Commit

Permalink
feat: added utm params to button
Browse files Browse the repository at this point in the history
  • Loading branch information
Mim1991 committed Jan 12, 2024
1 parent 63b84a1 commit d62bda4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/boot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ export default (element: HTMLDivElement, hub: Hub) => {

let settings: any = {
id: element.id,
height: parseInt(element.getAttribute("data-height") || "auto", 10)
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;
settings.language = exercise.language;
settings.lang_version = exercise.lang_version;
settings.pre_exercise_code =
getPackages(exercise.packages, exercise.language) + exercise.pre_exercise_code;
getPackages(exercise.packages, exercise.language) +
exercise.pre_exercise_code;
settings.sample_code = exercise.sample || exercise.sample_code;
settings.sct = exercise.sct;
settings.solution = exercise.solution;
Expand Down Expand Up @@ -72,13 +76,15 @@ export default (element: HTMLDivElement, hub: Hub) => {
lang_version: element.getAttribute("data-lang-version"),
packages: element.getAttribute("data-packages"),
pre_exercise_code:
getPackages(element.getAttribute("data-packages"), element.getAttribute("data-lang")) +
getText("pre-exercise-code"),
getPackages(
element.getAttribute("data-packages"),
element.getAttribute("data-lang")
) + getText("pre-exercise-code"),
sample_code: getText("sample-code"),
sct: getText("sct"),
solution: getText("solution"),
showRunButton: showRunButton,
noLazyLoad: noLazyLoad
noLazyLoad: noLazyLoad,
});
}

Expand All @@ -102,7 +108,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
11 changes: 10 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,11 @@ 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 +127,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 d62bda4

Please sign in to comment.