@segment/analytics-browser-actions-intercom 1.0.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.eslintcache +1 -0
  2. package/dist/cjs/api.d.ts +9 -0
  3. package/dist/cjs/api.js +3 -0
  4. package/dist/cjs/api.js.map +1 -0
  5. package/dist/cjs/generated-types.d.ts +6 -0
  6. package/dist/cjs/generated-types.js +3 -0
  7. package/dist/cjs/generated-types.js.map +1 -0
  8. package/dist/cjs/identifyCompany/generated-types.d.ts +16 -0
  9. package/dist/cjs/identifyCompany/generated-types.js +3 -0
  10. package/dist/cjs/identifyCompany/generated-types.js.map +1 -0
  11. package/dist/cjs/identifyCompany/index.d.ts +6 -0
  12. package/dist/cjs/identifyCompany/index.js +65 -0
  13. package/dist/cjs/identifyCompany/index.js.map +1 -0
  14. package/dist/cjs/identifyUser/generated-types.d.ts +41 -0
  15. package/dist/cjs/identifyUser/generated-types.js +3 -0
  16. package/dist/cjs/identifyUser/generated-types.js.map +1 -0
  17. package/dist/cjs/identifyUser/index.d.ts +6 -0
  18. package/dist/cjs/identifyUser/index.js +213 -0
  19. package/dist/cjs/identifyUser/index.js.map +1 -0
  20. package/dist/cjs/index.d.ts +11 -0
  21. package/dist/cjs/index.js +95 -0
  22. package/dist/cjs/index.js.map +1 -0
  23. package/dist/cjs/init-script.d.ts +4 -0
  24. package/dist/cjs/init-script.js +53 -0
  25. package/dist/cjs/init-script.js.map +1 -0
  26. package/dist/cjs/sharedCompanyProperties.d.ts +2 -0
  27. package/dist/cjs/sharedCompanyProperties.js +62 -0
  28. package/dist/cjs/sharedCompanyProperties.js.map +1 -0
  29. package/dist/cjs/trackEvent/generated-types.d.ts +8 -0
  30. package/dist/cjs/trackEvent/generated-types.js +3 -0
  31. package/dist/cjs/trackEvent/generated-types.js.map +1 -0
  32. package/dist/cjs/trackEvent/index.d.ts +6 -0
  33. package/dist/cjs/trackEvent/index.js +77 -0
  34. package/dist/cjs/trackEvent/index.js.map +1 -0
  35. package/dist/cjs/utils.d.ts +10 -0
  36. package/dist/cjs/utils.js +48 -0
  37. package/dist/cjs/utils.js.map +1 -0
  38. package/dist/esm/api.d.ts +9 -0
  39. package/dist/esm/api.js +2 -0
  40. package/dist/esm/api.js.map +1 -0
  41. package/dist/esm/generated-types.d.ts +6 -0
  42. package/dist/esm/generated-types.js +2 -0
  43. package/dist/esm/generated-types.js.map +1 -0
  44. package/dist/esm/identifyCompany/generated-types.d.ts +16 -0
  45. package/dist/esm/identifyCompany/generated-types.js +2 -0
  46. package/dist/esm/identifyCompany/generated-types.js.map +1 -0
  47. package/dist/esm/identifyCompany/index.d.ts +6 -0
  48. package/dist/esm/identifyCompany/index.js +63 -0
  49. package/dist/esm/identifyCompany/index.js.map +1 -0
  50. package/dist/esm/identifyUser/generated-types.d.ts +41 -0
  51. package/dist/esm/identifyUser/generated-types.js +2 -0
  52. package/dist/esm/identifyUser/generated-types.js.map +1 -0
  53. package/dist/esm/identifyUser/index.d.ts +6 -0
  54. package/dist/esm/identifyUser/index.js +211 -0
  55. package/dist/esm/identifyUser/index.js.map +1 -0
  56. package/dist/esm/index.d.ts +11 -0
  57. package/dist/esm/index.js +91 -0
  58. package/dist/esm/index.js.map +1 -0
  59. package/dist/esm/init-script.d.ts +4 -0
  60. package/dist/esm/init-script.js +48 -0
  61. package/dist/esm/init-script.js.map +1 -0
  62. package/dist/esm/sharedCompanyProperties.d.ts +2 -0
  63. package/dist/esm/sharedCompanyProperties.js +58 -0
  64. package/dist/esm/sharedCompanyProperties.js.map +1 -0
  65. package/dist/esm/trackEvent/generated-types.d.ts +8 -0
  66. package/dist/esm/trackEvent/generated-types.js +2 -0
  67. package/dist/esm/trackEvent/generated-types.js.map +1 -0
  68. package/dist/esm/trackEvent/index.d.ts +6 -0
  69. package/dist/esm/trackEvent/index.js +75 -0
  70. package/dist/esm/trackEvent/index.js.map +1 -0
  71. package/dist/esm/utils.d.ts +10 -0
  72. package/dist/esm/utils.js +40 -0
  73. package/dist/esm/utils.js.map +1 -0
  74. package/dist/tsconfig.tsbuildinfo +1 -0
  75. package/package.json +6 -5
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCompanyProperties = void 0;
4
+ const getCompanyProperties = () => ({
5
+ company_id: {
6
+ description: 'The unique identifier of the company.',
7
+ label: 'Company ID',
8
+ type: 'string',
9
+ required: true
10
+ },
11
+ name: {
12
+ description: 'The name of the company.',
13
+ label: 'Company Name',
14
+ type: 'string',
15
+ required: true
16
+ },
17
+ created_at: {
18
+ description: 'The time the company was created in your system.',
19
+ label: 'Company Creation Time',
20
+ type: 'datetime',
21
+ required: false
22
+ },
23
+ plan: {
24
+ description: 'The name of the plan you have associated with the company.',
25
+ label: 'Company Plan',
26
+ type: 'string',
27
+ required: false
28
+ },
29
+ monthly_spend: {
30
+ description: 'The monthly spend of the company, e.g. how much revenue the company generates for your business.',
31
+ label: 'Monthly Spend',
32
+ type: 'integer',
33
+ required: false
34
+ },
35
+ size: {
36
+ description: 'The number of employees in the company.',
37
+ label: 'Company Size',
38
+ type: 'integer',
39
+ required: false
40
+ },
41
+ website: {
42
+ description: 'The URL for the company website.',
43
+ label: 'Company Website',
44
+ type: 'string',
45
+ required: false
46
+ },
47
+ industry: {
48
+ description: 'The industry that the company operates in.',
49
+ label: 'Industry',
50
+ type: 'string',
51
+ required: false
52
+ },
53
+ company_custom_traits: {
54
+ description: 'The custom attributes for the company object.',
55
+ label: 'Company Custom Attributes',
56
+ type: 'object',
57
+ required: false,
58
+ defaultObjectUI: 'keyvalue'
59
+ }
60
+ });
61
+ exports.getCompanyProperties = getCompanyProperties;
62
+ //# sourceMappingURL=sharedCompanyProperties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharedCompanyProperties.js","sourceRoot":"","sources":["../../src/sharedCompanyProperties.ts"],"names":[],"mappings":";;;AAEO,MAAM,oBAAoB,G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@@
1
+ export interface Payload {
2
+ event_name: string;
3
+ revenue?: number;
4
+ currency?: string;
5
+ event_metadata?: {
6
+ [k: string]: unknown;
7
+ };
8
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../src/trackEvent/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types';
2
+ import { Intercom } from '../api';
3
+ import type { Settings } from '../generated-types';
4
+ import type { Payload } from './generated-types';
5
+ declare const action: BrowserActionDefinition<Settings, Intercom, Payload>;
6
+ export default action;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../utils");
4
+ const action = {
5
+ title: 'Track Event',
6
+ description: 'Submit an event to Intercom.',
7
+ defaultSubscription: 'type = "track"',
8
+ platform: 'web',
9
+ fields: {
10
+ event_name: {
11
+ description: 'The name of the event.',
12
+ label: 'Event Name',
13
+ type: 'string',
14
+ required: true,
15
+ default: {
16
+ '@path': '$.event'
17
+ }
18
+ },
19
+ revenue: {
20
+ description: 'The amount associated with a purchase. Segment will multiply by 100 as Intercom requires the amount in cents.',
21
+ label: 'Revenue',
22
+ type: 'number',
23
+ required: false,
24
+ default: {
25
+ '@path': '$.properties.revenue'
26
+ }
27
+ },
28
+ currency: {
29
+ description: 'The currency of the purchase amount. Segment will default to USD if revenue is provided without a currency.',
30
+ label: 'Currency',
31
+ type: 'string',
32
+ required: false,
33
+ default: {
34
+ '@path': '$.properties.currency'
35
+ }
36
+ },
37
+ event_metadata: {
38
+ description: 'Optional metadata describing the event.',
39
+ label: 'Event Metadata',
40
+ type: 'object',
41
+ required: false,
42
+ default: {
43
+ '@path': '$.properties'
44
+ }
45
+ }
46
+ },
47
+ perform: (Intercom, event) => {
48
+ const { event_name, event_metadata, ...rest } = event.payload;
49
+ const payload = { ...rest };
50
+ const richLinkProperties = Intercom.richLinkProperties ? Intercom.richLinkProperties : [];
51
+ const richLinkObjects = {};
52
+ if (event_metadata && richLinkProperties.length != 0) {
53
+ Object.entries(event_metadata).forEach(([key, value]) => {
54
+ if (richLinkProperties.includes(key)) {
55
+ richLinkObjects[key] = value;
56
+ }
57
+ });
58
+ }
59
+ const filteredMetadata = utils_1.filterCustomTraits(event_metadata);
60
+ let price = {};
61
+ if (payload.revenue) {
62
+ price = {
63
+ amount: payload.revenue * 100,
64
+ currency: payload.currency ?? 'USD'
65
+ };
66
+ delete filteredMetadata.revenue;
67
+ delete filteredMetadata.currency;
68
+ }
69
+ Intercom('trackEvent', event_name, {
70
+ ...filteredMetadata,
71
+ ...richLinkObjects,
72
+ ...(!utils_1.isEmpty(price) && { price })
73
+ });
74
+ }
75
+ };
76
+ exports.default = action;
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/trackEvent/index.ts"],"names":[],"mappings":";;AAGA,oCAAsD;AAGtD,MAAM,MAAM,GAAyD;IACnE,KAAK,EAAE,aAAa;IACpB,WAAW,EAAE,8BAA8B;IAC3C,mBAAmB,EAAE,gBAAgB;IACrC,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE;QACN,UAAU,EAAE;YACV,WAAW,EAAE,wBAAwB;YACrC,KAAK,EAAE,YAAY;YACnB,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE;gBACP,OAAO,EAAE,SAAS;aACnB;SACF;QACD,OAAO,EAAE;YACP,WAAW,EACT,+GAA+G;YACjH,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE;gBACP,OAAO,EAAE,sBAAsB;aAChC;SACF;QACD,QAAQ,EAAE;YACR,WAAW,EACT,6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K;aACpC,CAAA;YACD,OAAO,gBAAgB,CAAC,OAAO,CAAA;YAC/B,OAAO,gBAAgB,CAAC,QAAQ,CAAA;SACjC;QAID,QAAQ,CAAC,YAAY,EAAE,UAAU,EAAE;YACjC,GAAG,gBAAgB;YACnB,GAAG,eAAe;YAClB,GAAG,CAAC,CAAC,eAAO,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;SAClC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,10 @@
1
+ export declare function convertDateToUnix(created_at: string | number): number;
2
+ export declare function filterCustomTraits(traits: {
3
+ [k: string]: unknown;
4
+ } | undefined): {
5
+ [k: string]: unknown;
6
+ };
7
+ export declare function getWidgetOptions(hide_default_launcher: boolean | undefined, activator: string | undefined): {
8
+ [key: string]: unknown;
9
+ };
10
+ export declare function isEmpty(o: object | undefined): boolean;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEmpty = exports.getWidgetOptions = exports.filterCustomTraits = exports.convertDateToUnix = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const actions_core_1 = require("@segment/actions-core");
6
+ const actions_shared_1 = require("@segment/actions-shared");
7
+ const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
8
+ function convertDateToUnix(created_at) {
9
+ if (typeof created_at === 'number') {
10
+ let unixDate = dayjs_1.default.unix(created_at).unix();
11
+ if (unixDate.toString().length == 13) {
12
+ unixDate = Math.floor(unixDate / 1000);
13
+ }
14
+ return unixDate;
15
+ }
16
+ return dayjs_1.default(created_at).unix();
17
+ }
18
+ exports.convertDateToUnix = convertDateToUnix;
19
+ function filterCustomTraits(traits) {
20
+ const filteredCustomTraits = {};
21
+ if (traits) {
22
+ for (const [key, value] of Object.entries(traits)) {
23
+ if (!actions_core_1.isArray(value) && !actions_core_1.isObject(value)) {
24
+ filteredCustomTraits[key] = value;
25
+ }
26
+ }
27
+ }
28
+ return filteredCustomTraits;
29
+ }
30
+ exports.filterCustomTraits = filterCustomTraits;
31
+ function getWidgetOptions(hide_default_launcher, activator) {
32
+ const widgetOptions = {};
33
+ if (hide_default_launcher !== undefined) {
34
+ widgetOptions.hide_default_launcher = hide_default_launcher;
35
+ }
36
+ if (activator !== '#IntercomDefaultWidget') {
37
+ widgetOptions.widget = {
38
+ activator: activator
39
+ };
40
+ }
41
+ return widgetOptions;
42
+ }
43
+ exports.getWidgetOptions = getWidgetOptions;
44
+ function isEmpty(o) {
45
+ return !actions_shared_1.isNonEmpty(o);
46
+ }
47
+ exports.isEmpty = isEmpty;
48
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;;AAAA,wDAAyD;AACzD,4DAAoD;AACpD,0DAAyB;AAEzB,SAAgB,iBAAiB,CAAC,UAA2B;IAC3D,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;QAClC,IAAI,QAAQ,GAAG,eAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAA;QAC5C,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,IAAI,EAAE,EAAE;YACpC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;SACvC;QACD,OAAO,QAAQ,CAAA;KAChB;IACD,OAAO,eAAK,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAA;AACjC,CAAC;AATD,8CASC;AAED,SAAgB,kBAAkB,CAAC,MAA4C;IAC7E,MAAM,oBAAoB,GAA6B,EAAE,CAAA;IACzD,IAAI,MAAM,EAAE;QACV,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACjD,IAAI,CAAC,sBAAO,CAAC,KAAK,CAAC,IAAI,CAAC,uBAAQ,CAAC,KAAK,CAAC,EAAE;gBACvC,oBAAoB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;aAClC;SACF;KACF;IACD,OAAO,oBAAoB,CAAA;AAC7B,CAAC;AAVD,gDAUC;AAED,SAAgB,gBAAgB,CAAC,qBAA0C,EAAE,SAA6B;IACxG,MAAM,aAAa,GAA+B,EAAE,CAAA;IACpD,IAAI,qBAAqB,KAAK,SAAS,EAAE;QACvC,aAAa,CAAC,qBAAqB,GAAG,qBAAqB,CAAA;KAC5D;IACD,IAAI,SAAS,KAAK,wBAAwB,EAAE;QAC1C,aAAa,CAAC,MAAM,GAAG;YACrB,SAAS,EAAE,SAAS;SACrB,CAAA;KACF;IACD,OAAO,aAAa,CAAA;AACtB,CAAC;AAXD,4CAWC;AAED,SAAgB,OAAO,CAAC,CAAqB;IAC3C,OAAO,CAAC,2BAAU,CAAC,CAAC,CAAC,CAAA;AACvB,CAAC;AAFD,0BAEC"}
@@ -0,0 +1,9 @@
1
+ declare type method = 'trackEvent' | 'update';
2
+ declare type IntercomApi = {
3
+ richLinkProperties: string[] | undefined;
4
+ appId: string;
5
+ activator: string | undefined;
6
+ };
7
+ declare type IntercomFunction = (method: method, ...args: unknown[]) => void;
8
+ export declare type Intercom = IntercomFunction & IntercomApi;
9
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export interface Settings {
2
+ appId: string;
3
+ activator?: string;
4
+ richLinkProperties?: string[];
5
+ apiBase?: string;
6
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../src/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ export interface Payload {
2
+ company: {
3
+ company_id: string;
4
+ name: string;
5
+ created_at?: string | number;
6
+ plan?: string;
7
+ monthly_spend?: number;
8
+ size?: number;
9
+ website?: string;
10
+ industry?: string;
11
+ company_custom_traits?: {
12
+ [k: string]: unknown;
13
+ };
14
+ };
15
+ hide_default_launcher?: boolean;
16
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../src/identifyCompany/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types';
2
+ import { Intercom } from '../api';
3
+ import type { Settings } from '../generated-types';
4
+ import type { Payload } from './generated-types';
5
+ declare const action: BrowserActionDefinition<Settings, Intercom, Payload>;
6
+ export default action;
@@ -0,0 +1,63 @@
1
+ import { getCompanyProperties } from '../sharedCompanyProperties';
2
+ import { convertDateToUnix, filterCustomTraits, getWidgetOptions } from '../utils';
3
+ const companyProperties = getCompanyProperties();
4
+ const action = {
5
+ title: 'Identify Company',
6
+ description: 'Create or update a company in Intercom.',
7
+ defaultSubscription: 'type = "group"',
8
+ platform: 'web',
9
+ fields: {
10
+ company: {
11
+ description: "The user's company.",
12
+ label: 'Company',
13
+ type: 'object',
14
+ required: true,
15
+ properties: companyProperties,
16
+ default: {
17
+ company_id: { '@path': '$.groupId' },
18
+ name: { '@path': '$.traits.name' },
19
+ created_at: {
20
+ '@if': {
21
+ exists: { '@path': '$.traits.createdAt' },
22
+ then: { '@path': '$.traits.createdAt' },
23
+ else: { '@path': '$.traits.created_at' }
24
+ }
25
+ },
26
+ plan: { '@path': '$.traits.plan' },
27
+ size: { '@path': '$.traits.size' },
28
+ website: { '@path': '$.traits.website' },
29
+ industry: { '@path': '$.traits.industry' },
30
+ monthly_spend: { '@path': '$.traits.monthly_spend' }
31
+ }
32
+ },
33
+ hide_default_launcher: {
34
+ description: 'Selectively show the chat widget. As per [Intercom docs](https://www.intercom.com/help/en/articles/189-turn-off-show-or-hide-the-intercom-messenger), you want to first hide the Messenger for all users inside the Intercom UI using Messenger settings. Then think about how you want to programmatically decide which users you would like to show the widget to.',
35
+ label: 'Hide Default Launcher',
36
+ type: 'boolean',
37
+ required: false,
38
+ default: {
39
+ '@if': {
40
+ exists: { '@path': '$.context.Intercom.hideDefaultLauncher' },
41
+ then: { '@path': '$.context.Intercom.hideDefaultLauncher' },
42
+ else: { '@path': '$.context.Intercom.hide_default_launcher' }
43
+ }
44
+ }
45
+ }
46
+ },
47
+ perform: (Intercom, event) => {
48
+ const { company_custom_traits, ...rest } = event.payload.company;
49
+ let company = { ...rest };
50
+ if (company?.created_at) {
51
+ company.created_at = convertDateToUnix(company.created_at);
52
+ }
53
+ const filteredCustomTraits = filterCustomTraits(company_custom_traits);
54
+ company = { ...company, ...filteredCustomTraits };
55
+ const widgetOptions = getWidgetOptions(event.payload.hide_default_launcher, Intercom.activator);
56
+ Intercom('update', {
57
+ company,
58
+ ...widgetOptions
59
+ });
60
+ }
61
+ };
62
+ export default action;
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/identifyCompany/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAGlF,MAAM,iBAAiB,GAA+B,oBAAoB,EAAE,CAAA;AAE5E,MAAM,MAAM,GAAyD;IACnE,KAAK,EAAE,kBAAkB;IACzB,WAAW,EAAE,yCAAyC;IACtD,mBAAmB,EAAE,gBAAgB;IACrC,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE;QACN,OAAO,EAAE;YACP,WAAW,EAAE,qBAAqB;YAClC,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,QAAQ;YACd,QAAQ,E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iB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;SAC3D;QAGD,MAAM,oBAAoB,GAAG,kBAAkB,CAAC,qBAAqB,CAAC,CAAA;QAGtE,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,oBAAoB,EAAE,CAAA;QAGjD,MAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,qBAAqB,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAA;QAG/F,QAAQ,CAAC,QAAQ,EAAE;YACjB,OAAO;YACP,GAAG,aAAa;SACjB,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -0,0 +1,41 @@
1
+ export interface Payload {
2
+ user_id?: string;
3
+ custom_traits?: {
4
+ [k: string]: unknown;
5
+ };
6
+ name?: string;
7
+ phone?: string;
8
+ unsubscribed_from_emails?: boolean;
9
+ language_override?: string;
10
+ email?: string;
11
+ created_at?: string | number;
12
+ avatar_image_url?: string;
13
+ user_hash?: string;
14
+ company?: {
15
+ company_id: string;
16
+ name: string;
17
+ created_at?: string | number;
18
+ plan?: string;
19
+ monthly_spend?: number;
20
+ size?: number;
21
+ website?: string;
22
+ industry?: string;
23
+ company_custom_traits?: {
24
+ [k: string]: unknown;
25
+ };
26
+ };
27
+ companies?: {
28
+ company_id: string;
29
+ name: string;
30
+ created_at?: string | number;
31
+ plan?: string;
32
+ monthly_spend?: number;
33
+ size?: number;
34
+ website?: string;
35
+ industry?: string;
36
+ company_custom_traits?: {
37
+ [k: string]: unknown;
38
+ };
39
+ }[];
40
+ hide_default_launcher?: boolean;
41
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../src/identifyUser/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types';
2
+ import { Intercom } from '../api';
3
+ import type { Settings } from '../generated-types';
4
+ import type { Payload } from './generated-types';
5
+ declare const action: BrowserActionDefinition<Settings, Intercom, Payload>;
6
+ export default action;
@@ -0,0 +1,211 @@
1
+ import { getCompanyProperties } from '../sharedCompanyProperties';
2
+ import { convertDateToUnix, filterCustomTraits, getWidgetOptions, isEmpty } from '../utils';
3
+ const companyProperties = getCompanyProperties();
4
+ const action = {
5
+ title: 'Identify User',
6
+ description: 'Create or update a user in Intercom.',
7
+ defaultSubscription: 'type = "identify" or type = "page"',
8
+ platform: 'web',
9
+ fields: {
10
+ user_id: {
11
+ description: 'A unique identifier for the user.',
12
+ label: 'User ID',
13
+ type: 'string',
14
+ required: false,
15
+ default: {
16
+ '@path': '$.userId'
17
+ }
18
+ },
19
+ custom_traits: {
20
+ description: "The user's custom attributes.",
21
+ label: 'Custom Attributes',
22
+ type: 'object',
23
+ required: false,
24
+ defaultObjectUI: 'keyvalue'
25
+ },
26
+ name: {
27
+ description: "The user's name.",
28
+ label: 'Name',
29
+ type: 'string',
30
+ required: false,
31
+ default: {
32
+ '@path': '$.traits.name'
33
+ }
34
+ },
35
+ phone: {
36
+ description: "The user's phone number.",
37
+ label: 'Phone Number',
38
+ type: 'string',
39
+ required: false,
40
+ default: {
41
+ '@path': '$.traits.phone'
42
+ }
43
+ },
44
+ unsubscribed_from_emails: {
45
+ description: "The user's email unsubscribe status.",
46
+ label: 'Unsubscribed From Emails',
47
+ type: 'boolean',
48
+ required: false
49
+ },
50
+ language_override: {
51
+ description: "The user's messenger language (instead of relying on browser language settings).",
52
+ label: 'Language Override',
53
+ type: 'string',
54
+ required: false
55
+ },
56
+ email: {
57
+ description: "The user's email address.",
58
+ label: 'Email Address',
59
+ type: 'string',
60
+ required: false,
61
+ default: {
62
+ '@path': '$.traits.email'
63
+ }
64
+ },
65
+ created_at: {
66
+ description: 'The time the user was created in your system.',
67
+ label: 'User Creation Time',
68
+ type: 'datetime',
69
+ required: false,
70
+ default: {
71
+ '@if': {
72
+ exists: { '@path': '$.traits.createdAt' },
73
+ then: { '@path': '$.traits.createdAt' },
74
+ else: { '@path': '$.traits.created_at' }
75
+ }
76
+ }
77
+ },
78
+ avatar_image_url: {
79
+ description: "The URL for the user's avatar/profile image.",
80
+ label: 'Avatar',
81
+ type: 'string',
82
+ required: false,
83
+ default: { '@path': '$.traits.avatar' }
84
+ },
85
+ user_hash: {
86
+ description: 'The user hash used for identity verification. See [Intercom docs](https://www.intercom.com/help/en/articles/183-enable-identity-verification-for-web-and-mobile) for more information on how to set this field.',
87
+ label: 'User Hash',
88
+ type: 'string',
89
+ required: false,
90
+ default: {
91
+ '@if': {
92
+ exists: { '@path': '$.context.Intercom.user_hash' },
93
+ then: { '@path': '$.context.Intercom.user_hash' },
94
+ else: { '@path': '$.context.Intercom.userHash' }
95
+ }
96
+ }
97
+ },
98
+ company: {
99
+ description: "The user's company.",
100
+ label: 'Company',
101
+ type: 'object',
102
+ required: false,
103
+ properties: companyProperties,
104
+ default: {
105
+ company_id: { '@path': '$.traits.company.id' },
106
+ name: { '@path': '$.traits.company.name' },
107
+ created_at: {
108
+ '@if': {
109
+ exists: { '@path': '$.traits.company.createdAt' },
110
+ then: { '@path': '$.traits.company.createdAt' },
111
+ else: { '@path': '$.traits.company.created_at' }
112
+ }
113
+ },
114
+ plan: { '@path': '$.traits.company.plan' },
115
+ size: { '@path': '$.traits.company.size' },
116
+ website: { '@path': '$.traits.company.website' },
117
+ industry: { '@path': '$.traits.company.industry' },
118
+ monthly_spend: { '@path': '$.traits.company.monthly_spend' }
119
+ }
120
+ },
121
+ companies: {
122
+ description: 'The array of companies the user is associated to.',
123
+ label: 'Companies',
124
+ type: 'object',
125
+ multiple: true,
126
+ required: false,
127
+ properties: companyProperties,
128
+ default: {
129
+ '@arrayPath': [
130
+ '$.traits.companies',
131
+ {
132
+ company_id: { '@path': '$.id' },
133
+ name: { '@path': '$.name' },
134
+ created_at: {
135
+ '@if': {
136
+ exists: { '@path': '$.createdAt' },
137
+ then: { '@path': '$.createdAt' },
138
+ else: { '@path': '$.created_at' }
139
+ }
140
+ },
141
+ plan: { '@path': '$.plan' },
142
+ size: { '@path': '$.size' },
143
+ website: { '@path': '$.website' },
144
+ industry: { '@path': '$.industry' },
145
+ monthly_spend: { '@path': '$.monthly_spend' }
146
+ }
147
+ ]
148
+ }
149
+ },
150
+ hide_default_launcher: {
151
+ description: 'Selectively show the chat widget. As per [Intercom docs](https://www.intercom.com/help/en/articles/189-turn-off-show-or-hide-the-intercom-messenger), you want to first hide the Messenger for all users inside the Intercom UI using Messenger settings. Then think about how you want to programmatically decide which users you would like to show the widget to.',
152
+ label: 'Hide Default Launcher',
153
+ type: 'boolean',
154
+ required: false,
155
+ default: {
156
+ '@if': {
157
+ exists: { '@path': '$.context.Intercom.hideDefaultLauncher' },
158
+ then: { '@path': '$.context.Intercom.hideDefaultLauncher' },
159
+ else: { '@path': '$.context.Intercom.hide_default_launcher' }
160
+ }
161
+ }
162
+ }
163
+ },
164
+ perform: (Intercom, event) => {
165
+ const { custom_traits, avatar_image_url, ...rest } = event.payload;
166
+ const payload = { ...rest };
167
+ if (isEmpty(payload.company?.company_custom_traits)) {
168
+ delete payload.company?.company_custom_traits;
169
+ }
170
+ if (isEmpty(payload.company)) {
171
+ delete payload.company;
172
+ }
173
+ const companies = Array.isArray(payload.companies) ? [...payload.companies] : [];
174
+ const datesToConvert = [payload, payload.company, ...companies];
175
+ for (const objectWithDateProp of datesToConvert) {
176
+ if (objectWithDateProp && objectWithDateProp?.created_at) {
177
+ objectWithDateProp.created_at = convertDateToUnix(objectWithDateProp.created_at);
178
+ }
179
+ }
180
+ const filteredCustomTraits = filterCustomTraits(custom_traits);
181
+ if (payload.company) {
182
+ const { company_custom_traits, ...rest } = payload.company;
183
+ const companyFilteredCustomTraits = filterCustomTraits(company_custom_traits);
184
+ payload.company = { ...rest, ...companyFilteredCustomTraits };
185
+ }
186
+ if (payload.companies) {
187
+ payload.companies = payload.companies.map((company) => {
188
+ const { company_custom_traits, ...rest } = company;
189
+ const companyFilteredCustomTraits = filterCustomTraits(company_custom_traits);
190
+ company = { ...rest, ...companyFilteredCustomTraits };
191
+ return company;
192
+ });
193
+ }
194
+ const widgetOptions = getWidgetOptions(payload.hide_default_launcher, Intercom.activator);
195
+ let avatar = {};
196
+ if (avatar_image_url) {
197
+ avatar = {
198
+ image_url: avatar_image_url,
199
+ type: 'avatar'
200
+ };
201
+ }
202
+ Intercom('update', {
203
+ ...payload,
204
+ ...filteredCustomTraits,
205
+ ...widgetOptions,
206
+ ...(!isEmpty(avatar) && { avatar })
207
+ });
208
+ }
209
+ };
210
+ export default action;
211
+ //# sourceMappingURL=index.js.map