Add utm_campaign to the hosting links

According to where in the app the link was clicked
This commit is contained in:
David Baker 2019-03-05 16:42:22 +00:00
parent b68a71b294
commit 0244990731
4 changed files with 43 additions and 5 deletions

View file

@ -21,7 +21,7 @@ import Promise from 'bluebird';
import MatrixClientPeg from '../../MatrixClientPeg';
import sdk from '../../index';
import dis from '../../dispatcher';
import SdkConfig from '../../SdkConfig';
import { getHostingLink } from '../../utils/HostingLink';
import { sanitizedHtmlNode } from '../../HtmlUtils';
import { _t, _td } from '../../languageHandler';
import AccessibleButton from '../views/elements/AccessibleButton';
@ -818,7 +818,7 @@ export default React.createClass({
const header = this.state.editing ? <h2> { _t('Community Settings') } </h2> : <div />;
const hostingSignupLink = SdkConfig.get().hosting_signup_link;
const hostingSignupLink = getHostingLink('community-settings');
let hostingSignup = null;
if (hostingSignupLink) {
hostingSignup = <div className="mx_GroupView_hostingSignup">

View file

@ -21,6 +21,7 @@ import { _t } from '../../../languageHandler';
import LogoutDialog from "../dialogs/LogoutDialog";
import Modal from "../../../Modal";
import SdkConfig from '../../../SdkConfig';
import { getHostingLink } from '../../../utils/HostingLink';
import MatrixClientPeg from '../../../MatrixClientPeg';
export class TopLeftMenu extends React.Component {
@ -53,7 +54,7 @@ export class TopLeftMenu extends React.Component {
render() {
const isGuest = MatrixClientPeg.get().isGuest();
const hostingSignupLink = SdkConfig.get().hosting_signup_link;
const hostingSignupLink = getHostingLink('user-context-menu');
let hostingSignup = null;
if (hostingSignupLink) {
hostingSignup = <div className="mx_TopLeftMenu_upgradeLink">

View file

@ -21,7 +21,7 @@ import Field from "../elements/Field";
import AccessibleButton from "../elements/AccessibleButton";
import classNames from 'classnames';
import {User} from "matrix-js-sdk";
import SdkConfig from '../../../SdkConfig';
import { getHostingLink } from '../../../utils/HostingLink';
export default class ProfileSettings extends React.Component {
constructor() {
@ -138,7 +138,7 @@ export default class ProfileSettings extends React.Component {
</div>
);
const hostingSignupLink = SdkConfig.get().hosting_signup_link;
const hostingSignupLink = getHostingLink('user-settings');
let hostingSignup = null;
if (hostingSignupLink) {
hostingSignup = <span className="mx_ProfileSettings_hostingSignup">

37
src/utils/HostingLink.js Normal file
View file

@ -0,0 +1,37 @@
/*
Copyright 2019 New Vector Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import url from 'url';
import qs from 'qs';
import SdkConfig from '../SdkConfig';
export function getHostingLink(campaign) {
const hostingLink = SdkConfig.get().hosting_signup_link;
if (!hostingLink) return null;
if (!campaign) return hostingLink;
try {
const hostingUrl = url.parse(hostingLink);
const params = qs.parse(hostingUrl.query);
params.utm_campaign = campaign;
hostingUrl.search = undefined;
hostingUrl.query = params;
return hostingUrl.format();
} catch (e) {
return hostingLink;
}
}