mirror of
https://github.com/vale981/Vulcan
synced 2025-03-08 19:11:38 -05:00
49 lines
1.1 KiB
JavaScript
49 lines
1.1 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';
|
|
|
|
const token = getSetting('intercom.accessToken');
|
|
|
|
if (!token) {
|
|
throw new Error('Please add your Intercom access token in settings.json');
|
|
} else {
|
|
|
|
const intercomClient = new Intercom.Client({ token });
|
|
|
|
const getDate = () => new Date().valueOf().toString().substr(0,10);
|
|
|
|
/*
|
|
|
|
New User
|
|
|
|
*/
|
|
function intercomNewUser(user) {
|
|
intercomClient.users.create({
|
|
email: user.email,
|
|
custom_attributes: {
|
|
name: user.displayName,
|
|
profileUrl: Users.getProfileUrl(user, true),
|
|
_id: user._id,
|
|
}
|
|
});
|
|
}
|
|
addUserFunction(intercomNewUser);
|
|
|
|
/*
|
|
|
|
Track Event
|
|
|
|
*/
|
|
function intercomTrackServer(eventName, eventProperties, currentUser) {
|
|
intercomClient.events.create({
|
|
event_name: eventName,
|
|
created_at: getDate(),
|
|
email: currentUser.email,
|
|
metadata: {
|
|
...eventProperties
|
|
}
|
|
});
|
|
}
|
|
addTrackFunction(intercomTrackServer);
|
|
|
|
}
|