Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 7aa4510

Browse files
committed
Add utm_campaign to the hosting links
According to where in the app the link was clicked
1 parent dc0eff3 commit 7aa4510

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

src/components/structures/GroupView.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Promise from 'bluebird';
2121
import MatrixClientPeg from '../../MatrixClientPeg';
2222
import sdk from '../../index';
2323
import dis from '../../dispatcher';
24-
import SdkConfig from '../../SdkConfig';
24+
import { getHostingLink } from '../../utils/HostingLink';
2525
import { sanitizedHtmlNode } from '../../HtmlUtils';
2626
import { _t, _td } from '../../languageHandler';
2727
import AccessibleButton from '../views/elements/AccessibleButton';
@@ -818,7 +818,7 @@ export default React.createClass({
818818

819819
const header = this.state.editing ? <h2> { _t('Community Settings') } </h2> : <div />;
820820

821-
const hostingSignupLink = SdkConfig.get().hosting_signup_link;
821+
const hostingSignupLink = getHostingLink('community-settings');
822822
let hostingSignup = null;
823823
if (hostingSignupLink) {
824824
hostingSignup = <div className="mx_GroupView_hostingSignup">

src/components/views/context_menus/TopLeftMenu.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { _t } from '../../../languageHandler';
2121
import LogoutDialog from "../dialogs/LogoutDialog";
2222
import Modal from "../../../Modal";
2323
import SdkConfig from '../../../SdkConfig';
24+
import { getHostingLink } from '../../../utils/HostingLink';
2425
import MatrixClientPeg from '../../../MatrixClientPeg';
2526

2627
export class TopLeftMenu extends React.Component {
@@ -53,7 +54,7 @@ export class TopLeftMenu extends React.Component {
5354
render() {
5455
const isGuest = MatrixClientPeg.get().isGuest();
5556

56-
const hostingSignupLink = SdkConfig.get().hosting_signup_link;
57+
const hostingSignupLink = getHostingLink('user-context-menu');
5758
let hostingSignup = null;
5859
if (hostingSignupLink) {
5960
hostingSignup = <div className="mx_TopLeftMenu_upgradeLink">

src/components/views/settings/ProfileSettings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Field from "../elements/Field";
2121
import AccessibleButton from "../elements/AccessibleButton";
2222
import classNames from 'classnames';
2323
import {User} from "matrix-js-sdk";
24-
import SdkConfig from '../../../SdkConfig';
24+
import { getHostingLink } from '../../../utils/HostingLink';
2525

2626
export default class ProfileSettings extends React.Component {
2727
constructor() {
@@ -131,7 +131,7 @@ export default class ProfileSettings extends React.Component {
131131
</div>
132132
);
133133

134-
const hostingSignupLink = SdkConfig.get().hosting_signup_link;
134+
const hostingSignupLink = getHostingLink('user-settings');
135135
let hostingSignup = null;
136136
if (hostingSignupLink) {
137137
hostingSignup = <span className="mx_ProfileSettings_hostingSignup">

src/utils/HostingLink.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2019 New Vector Ltd.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import url from 'url';
18+
import qs from 'qs';
19+
20+
import SdkConfig from '../SdkConfig';
21+
22+
export function getHostingLink(campaign) {
23+
const hostingLink = SdkConfig.get().hosting_signup_link;
24+
if (!hostingLink) return null;
25+
if (!campaign) return hostingLink;
26+
27+
try {
28+
const hostingUrl = url.parse(hostingLink);
29+
const params = qs.parse(hostingUrl.query);
30+
params.utm_campaign = campaign;
31+
hostingUrl.search = undefined;
32+
hostingUrl.query = params;
33+
return hostingUrl.format();
34+
} catch (e) {
35+
return hostingLink;
36+
}
37+
}

0 commit comments

Comments
 (0)