MCPcopy Create free account
hub / github.com/DavidWells/analytics / intercomPlugin

Function intercomPlugin

packages/analytics-plugin-intercom/src/browser.js:35–212  ·  view source on GitHub ↗

* intercom analytics plugin * @link https://getanalytics.io/plugins/intercom/ * @link https://developers.intercom.com/installing-intercom/docs/intercom-javascript * @param {object} pluginConfig - Plugin settings * @param {string} pluginConfig.appId - Your intercom app id * @param {boolean} [p

(pluginConfig = {})

Source from the content-addressed store, hash-verified

33 * })
34 */
35function intercomPlugin(pluginConfig = {}) {
36 return {
37 name: "intercom",
38 config: {
39 ...config,
40 ...pluginConfig,
41 },
42 /* Custom methods TODO: shutdown? hide show */
43 methods: {
44 startTour(tourId) {
45 const intercom = window.Intercom;
46 if (typeof intercom === "undefined") return;
47 intercom("startTour", tourId);
48 },
49 shutdown() {
50 const intercom = window.Intercom;
51 if (typeof intercom === "undefined") return;
52 intercom("shutdown");
53 },
54 hide() {
55 const intercom = window.Intercom;
56 if (typeof intercom === "undefined") return;
57 intercom("hide");
58 },
59 show() {
60 const intercom = window.Intercom;
61 if (typeof intercom === "undefined") return;
62 intercom("show");
63 },
64 showMessages() {
65 const intercom = window.Intercom;
66 if (typeof intercom === "undefined") return;
67 intercom("showMessages");
68 },
69 showNewMessage() {
70 const intercom = window.Intercom;
71 if (typeof intercom === "undefined") return;
72 intercom("showNewMessage");
73 },
74 onShow(callback) {
75 const intercom = window.Intercom;
76 if (typeof intercom === "undefined") return;
77 intercom("onShow", callback);
78 },
79 onUnreadCountChange(callback) {
80 const intercom = window.Intercom;
81 if (typeof intercom === "undefined") return;
82 intercom("onUnreadCountChange", callback);
83 },
84 },
85 bootstrap: ({ config, instance }) => {
86 /* Load intercom script after userId exists */
87 if (config.disableAnonymousTraffic && !instance.user("userId")) {
88 instance.once("identifyStart", ({ plugins }) => {
89 const self = plugins["intercom"];
90 if (!self.loaded()) {
91 instance.loadPlugin("intercom");
92 }

Callers

nothing calls this directly

Calls 1

lFunction · 0.85

Tested by

no test coverage detected