mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
import Intercom from 'intercom-client';
|
|
import { getSetting, /* addCallback, Utils */ } from 'meteor/vulcan:core';
|
|
import {
|
|
// addPageFunction,
|
|
addUserFunction,
|
|
// addInitFunction,
|
|
// addIdentifyFunction,
|
|
addTrackFunction,
|
|
} from 'meteor/vulcan:events';
|
|
import Users from 'meteor/vulcan:users';
|
|
|
|
const token = getSetting('intercom.accessToken');
|
|
|
|
if (!token) {
|
|
throw new Error('Please add your Intercom access token as intercom.accessToken in settings.json');
|
|
} else {
|
|
|
|
export const intercomClient = new Intercom.Client({ token });
|
|
|
|
const getDate = () => new Date().valueOf().toString().substr(0,10);
|
|
|
|
/*
|
|
|
|
New User
|
|
|
|
*/
|
|
// eslint-disable-next-line no-inner-declarations
|
|
function intercomNewUser(user) {
|
|
intercomClient.users.create({
|
|
email: user.email,
|
|
user_id: user._id,
|
|
custom_attributes: {
|
|
name: user.displayName,
|
|
profileUrl: Users.getProfileUrl(user, true),
|
|
}
|
|
});
|
|
}
|
|
addUserFunction(intercomNewUser);
|
|
|
|
/*
|
|
|
|
Track Event
|
|
|
|
*/
|
|
// eslint-disable-next-line no-inner-declarations
|
|
function intercomTrackServer(eventName, eventProperties, currentUser) {
|
|
intercomClient.events.create({
|
|
event_name: eventName,
|
|
created_at: getDate(),
|
|
email: currentUser.email,
|
|
user_id: currentUser._id,
|
|
metadata: {
|
|
...eventProperties
|
|
}
|
|
});
|
|
}
|
|
addTrackFunction(intercomTrackServer);
|
|
|
|
}
|