Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercom updates #290

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/analytics-plugin-intercom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
"release:patch": "npm version patch && npm publish",
"release:minor": "npm version minor && npm publish",
"release:major": "npm version major && npm publish",
"es": "../../node_modules/.bin/babel-node ./testBabel.js"
"es": "../../node_modules/.bin/babel-node ./testBabel.js",
"types": "tsc"
},
"main": "lib/analytics-plugin-intercom.cjs.js",
"types": "types/browser.d.ts",
"globalName": "analyticsIntercom",
"jsnext:main": "lib/analytics-plugin-intercom.es.js",
"module": "lib/analytics-plugin-intercom.es.js",
Expand All @@ -40,6 +42,7 @@
"files": [
"dist",
"lib",
"types",
"README.md"
],
"homepage": "https://github.com/DavidWells/analytics#readme",
Expand Down
37 changes: 23 additions & 14 deletions packages/analytics-plugin-intercom/src/browser.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
/* global analytics */

/**
* @typedef {Object} IntercomPluginConfig
* @property {string} appId Your intercom app id
* @property {boolean=} disableAnonymousTraffic Disable loading intercom for anonymous visitors
* @property {string=} alignment Customize left or right position of messenger
* @property {string=} horizontalPadding Customize horizontal padding
* @property {string=} verticalPadding Customize vertical padding
* @property {string=} customLauncherSelector Css selector of the custom launcher see https://www.intercom.com/help/en/articles/2894-customize-the-intercom-messenger-technical for additional info
* @property {string=} userHash User hash used for identity verification
*/

/** @type IntercomPluginConfig */
const config = {
/* Your intercom app id */
appId: null,
disableAnonymousTraffic: false,
/* Customize left or right position of messenger */
alignment: undefined,
/* Customize horizontal padding */
horizontalPadding: undefined,
/* Customize vertical padding */
verticalPadding: undefined,
/* Css selector of the custom launcher */
customLauncherSelector: undefined,
userHash: undefined,
}

/**
* 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} [pluginConfig.disableAnonymousTraffic] - Disable loading intercom for anonymous visitors
* @param {string} [pluginConfig.alignment] - Customize left or right position of messenger
* @param {number} [pluginConfig.horizontalPadding] - Customize horizontal padding
* @param {number} [pluginConfig.verticalPadding] - Customize vertical padding
* @param {string} [pluginConfig.customLauncherSelector] - Css selector of the custom launcher see https://www.intercom.com/help/en/articles/2894-customize-the-intercom-messenger-technical for additional info
* @return {object} Analytics plugin
* @param {IntercomPluginConfig} pluginConfig - Plugin settings
* @return {Object} Analytics plugin
* @example
*
* intercomPlugin({
Expand Down Expand Up @@ -81,6 +83,11 @@ function intercomPlugin(pluginConfig = {}) {
if (typeof intercom === "undefined") return;
intercom("onUnreadCountChange", callback);
},
update(config) {
const intercom = window.Intercom;
if (typeof intercom === "undefined") return;
intercom("update", config);
},
},
bootstrap: ({ config, instance }) => {
/* Load intercom script after userId exists */
Expand All @@ -104,6 +111,7 @@ function intercomPlugin(pluginConfig = {}) {
horizontalPadding,
verticalPadding,
customLauncherSelector,
userHash,
} = config;
if (!appId) {
throw new Error("No intercom appId");
Expand Down Expand Up @@ -154,6 +162,7 @@ function intercomPlugin(pluginConfig = {}) {
horizontal_padding: horizontalPadding,
vertical_padding: verticalPadding,
custom_launcher_selector: customLauncherSelector,
user_hash: userHash,
};
},
/* Trigger intercom page view */
Expand Down Expand Up @@ -206,7 +215,7 @@ function intercomPlugin(pluginConfig = {}) {
},
/* Check if intercom loaded */
loaded: () => {
return window.Intercom;
return window.Intercom && window.Intercom.booted;
},
};
}
Expand Down
12 changes: 12 additions & 0 deletions packages/analytics-plugin-intercom/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"allowJs": true,
"declarationDir": "types/"
},
"include": [
"src/**/*.js"
]
}
3 changes: 2 additions & 1 deletion packages/analytics-util-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
"amdName": "utilTypes",
"source": "src/index.js",
"main": "dist/analytics-util-types.js",
"types": "dist/index.d.ts",
"module": "dist/analytics-util-types.module.js",
"unpkg": "dist/analytics-util-types.umd.js",
"sideEffects": false,
"scripts": {
"test": "uvu tests -r esm -i setup",
"types": "tsc --noEmit false --emitDeclarationOnly true",
"types": "tsc --emitDeclarationOnly -d --allowJs --declarationDir dist/ src/index.js",
"start": "npm run sync && concurrently 'npm:watch:*' 'npm:copy' 'npm:serve'",
"serve": "servor dist index.html 8081 --reload --browse",
"copy": "watchlist examples -- npm run sync",
Expand Down