2017-12-26 11:16:49 +09:00
|
|
|
import Intercom from 'intercom-client';
|
2018-01-25 15:03:03 -06:00
|
|
|
import { getSetting, /* addCallback, Utils */ } from 'meteor/vulcan:core';
|
|
|
|
import {
|
|
|
|
// addPageFunction,
|
|
|
|
addUserFunction,
|
|
|
|
// addInitFunction,
|
|
|
|
// addIdentifyFunction,
|
|
|
|
addTrackFunction,
|
|
|
|
} from 'meteor/vulcan:events';
|
|
|
|
import Users from 'meteor/vulcan:users';
|
2017-12-26 11:16:49 +09:00
|
|
|
|
|
|
|
const token = getSetting('intercom.accessToken');
|
|
|
|
|
|
|
|
if (!token) {
|
2018-02-02 17:44:53 +09:00
|
|
|
throw new Error('Please add your Intercom access token as intercom.accessToken in settings.json');
|
2017-12-26 11:16:49 +09:00
|
|
|
} else {
|
|
|
|
|
2018-02-02 17:44:53 +09:00
|
|
|
export const intercomClient = new Intercom.Client({ token });
|
2017-12-26 11:16:49 +09:00
|
|
|
|
|
|
|
const getDate = () => new Date().valueOf().toString().substr(0,10);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
New User
|
|
|
|
|
|
|
|
*/
|
2018-01-25 15:03:03 -06:00
|
|
|
// eslint-disable-next-line no-inner-declarations
|
2017-12-26 11:16:49 +09:00
|
|
|
function intercomNewUser(user) {
|
|
|
|
intercomClient.users.create({
|
|
|
|
email: user.email,
|
2018-02-05 10:45:51 +09:00
|
|
|
user_id: user._id,
|
2017-12-26 11:16:49 +09:00
|
|
|
custom_attributes: {
|
|
|
|
name: user.displayName,
|
|
|
|
profileUrl: Users.getProfileUrl(user, true),
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
addUserFunction(intercomNewUser);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Track Event
|
|
|
|
|
|
|
|
*/
|
2018-01-25 15:03:03 -06:00
|
|
|
// eslint-disable-next-line no-inner-declarations
|
2017-12-26 11:16:49 +09:00
|
|
|
function intercomTrackServer(eventName, eventProperties, currentUser) {
|
|
|
|
intercomClient.events.create({
|
|
|
|
event_name: eventName,
|
|
|
|
created_at: getDate(),
|
|
|
|
email: currentUser.email,
|
2018-02-21 10:48:01 +09:00
|
|
|
user_id: currentUser._id,
|
2017-12-26 11:16:49 +09:00
|
|
|
metadata: {
|
|
|
|
...eventProperties
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
addTrackFunction(intercomTrackServer);
|
|
|
|
|
|
|
|
}
|