mirror of https://github.com/vector-im/riot-web
Implement tracking of referrals (#659)
* Implement tracking of referrals This also modifies (or fixes) auto-joining.pull/21833/head
parent
9c99e78099
commit
878e5593ba
|
@ -12,4 +12,32 @@ export default class RtsClient {
|
|||
json: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Track a referral with the Riot Team Server. This should be called once a referred
|
||||
* user has been successfully registered.
|
||||
* @param {string} referrer the user ID of one who referred the user to Riot.
|
||||
* @param {string} user_id the user ID of the user being referred.
|
||||
* @param {string} user_email the email address linked to `user_id`.
|
||||
* @returns {Promise} a promise that resolves to [$response, $body], where $response
|
||||
* is the response object created by the request lib and $body is the object parsed
|
||||
* from the JSON response body. $body should be { team_token: 'sometoken' } upon
|
||||
* success.
|
||||
*/
|
||||
trackReferral(referrer, user_id, user_email) {
|
||||
return request({
|
||||
url: this._url + '/register',
|
||||
json: true,
|
||||
body: {referrer, user_id, user_email},
|
||||
method: 'POST',
|
||||
});
|
||||
}
|
||||
|
||||
getTeam(team_token) {
|
||||
return request({
|
||||
url: this._url + '/teamConfiguration',
|
||||
json: true,
|
||||
qs: {team_token},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1055,6 +1055,7 @@ module.exports = React.createClass({
|
|||
sessionId={this.state.register_session_id}
|
||||
idSid={this.state.register_id_sid}
|
||||
email={this.props.startingFragmentQueryParams.email}
|
||||
referrer={this.props.startingFragmentQueryParams.referrer}
|
||||
username={this.state.upgradeUsername}
|
||||
guestAccessToken={this.state.guestAccessToken}
|
||||
defaultHsUrl={this.getDefaultHsUrl()}
|
||||
|
|
|
@ -48,6 +48,7 @@ module.exports = React.createClass({
|
|||
defaultIsUrl: React.PropTypes.string,
|
||||
brand: React.PropTypes.string,
|
||||
email: React.PropTypes.string,
|
||||
referrer: React.PropTypes.string,
|
||||
username: React.PropTypes.string,
|
||||
guestAccessToken: React.PropTypes.string,
|
||||
teamServerConfig: React.PropTypes.shape({
|
||||
|
@ -56,6 +57,7 @@ module.exports = React.createClass({
|
|||
// URL of the riot-team-server to get team configurations and track referrals
|
||||
teamServerURL: React.PropTypes.string.isRequired,
|
||||
}),
|
||||
teamSelected: null,
|
||||
|
||||
defaultDeviceDisplayName: React.PropTypes.string,
|
||||
|
||||
|
@ -209,24 +211,42 @@ module.exports = React.createClass({
|
|||
accessToken: response.access_token
|
||||
});
|
||||
|
||||
// Auto-join rooms
|
||||
if (self.state.teamsConfig && self.state.teamsConfig.teams) {
|
||||
for (let i = 0; i < self.state.teamsConfig.teams.length; i++) {
|
||||
let team = self.state.teamsConfig.teams[i];
|
||||
if (self.state.formVals.email.endsWith(team.domain)) {
|
||||
console.log("User successfully registered with team " + team.name);
|
||||
if (
|
||||
self._rtsClient &&
|
||||
self.props.referrer &&
|
||||
self.state.teamSelected
|
||||
) {
|
||||
// Track referral, get team_token in order to retrieve team config
|
||||
self._rtsClient.trackReferral(
|
||||
self.props.referrer,
|
||||
response.user_id,
|
||||
self.state.formVals.email
|
||||
).then((args) => {
|
||||
const teamToken = args[1].team_token;
|
||||
// Store for use /w welcome pages
|
||||
window.localStorage.setItem('mx_team_token', teamToken);
|
||||
|
||||
self._rtsClient.getTeam(teamToken).then((args) => {
|
||||
const team = args[1];
|
||||
console.log(
|
||||
`User successfully registered with team ${team.name}`
|
||||
);
|
||||
if (!team.rooms) {
|
||||
break;
|
||||
return;
|
||||
}
|
||||
// Auto-join rooms
|
||||
team.rooms.forEach((room) => {
|
||||
if (room.autoJoin) {
|
||||
console.log("Auto-joining " + room.id);
|
||||
MatrixClientPeg.get().joinRoom(room.id);
|
||||
if (room.auto_join && room.room_id) {
|
||||
console.log(`Auto-joining ${room.room_id}`);
|
||||
MatrixClientPeg.get().joinRoom(room.room_id);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, (err) => {
|
||||
console.error('Error getting team config', err);
|
||||
});
|
||||
}, (err) => {
|
||||
console.error('Error tracking referral', err);
|
||||
});
|
||||
}
|
||||
|
||||
if (self.props.brand) {
|
||||
|
@ -298,11 +318,9 @@ module.exports = React.createClass({
|
|||
});
|
||||
},
|
||||
|
||||
onTeamSelected: function(team) {
|
||||
onTeamSelected: function(teamSelected) {
|
||||
if (!this._unmounted) {
|
||||
this.setState({
|
||||
teamIcon: team ? team.icon : null,
|
||||
});
|
||||
this.setState({ teamSelected });
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -407,7 +425,7 @@ module.exports = React.createClass({
|
|||
return (
|
||||
<div className="mx_Login">
|
||||
<div className="mx_Login_box">
|
||||
<LoginHeader icon={this.state.teamIcon}/>
|
||||
<LoginHeader icon={this.state.teamSelected ? this.state.teamSelected.icon : null}/>
|
||||
{this._getRegisterContentJsx()}
|
||||
<LoginFooter />
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue