From 8ea0daf0bf082597bdf086c0f74d5ac3139a52e5 Mon Sep 17 00:00:00 2001 From: devrnt Date: Thu, 21 May 2020 12:20:09 +0200 Subject: [PATCH 1/6] chore: add custom attribute to data attributes --- src/types.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/types.ts b/src/types.ts index 5ff0ee34..12260df0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -127,7 +127,7 @@ export type RawDataAttributes = { user_hash?: string; company?: RawDataAttributesCompany; companies?: RawDataAttributesCompany[]; - [custom_property: string]: any; + customAttributes?: Record; }; export type DataAttributes = { @@ -210,11 +210,19 @@ export type DataAttributes = { companies?: DataAttributesCompany[]; /** * You can do this anytime by adding additional key/value pairs to your intercomSettings code snippet + * These should be raw snake_cased + * + * @example + * ``` + * customAttributes={ + * my_custom_attibute: 'my attribute value' + * } + * ``` * * @see {@link https://www.intercom.com/help/en/articles/179-send-custom-user-attributes-to-intercom} * @remarks The key is the attribute name. The value is a placeholder for the data you’ll track */ - [customProperty: string]: any; + customAttributes?: Record; }; export type IntercomMethod = From 0c99edb3dfe00e51546a23d51c2aaf223b19fe0f Mon Sep 17 00:00:00 2001 From: devrnt Date: Thu, 21 May 2020 12:20:25 +0200 Subject: [PATCH 2/6] chore: prepare playground for mapper tests --- example/modules/useIntercom/useIntercom.tsx | 93 +++++++++++++++++++-- 1 file changed, 87 insertions(+), 6 deletions(-) diff --git a/example/modules/useIntercom/useIntercom.tsx b/example/modules/useIntercom/useIntercom.tsx index df414fc4..5d1e574f 100644 --- a/example/modules/useIntercom/useIntercom.tsx +++ b/example/modules/useIntercom/useIntercom.tsx @@ -34,13 +34,80 @@ const RawUseIntercomPage = () => { showMessages, showNewMessages, getVisitorId, - startTour, trackEvent, } = useIntercom(); + const handleBoot = React.useCallback(() => boot(), [boot]); - const handleBoot = React.useCallback(() => boot({ name: 'Russo' }), [boot]); + const handleSeededBoot = React.useCallback(() => boot({ name: 'Russo' }), [ + boot, + ]); + + const handleExtendedSeededBoot = React.useCallback( + () => + boot({ + name: 'Russo', + actionColor: 'red', + email: 'russo@email.com', + utmContent: 'content', + verticalPadding: 10, + alignment: 'left', + avatar: { + type: 'image', + imageUrl: 'https://github.com/devrnt/react-use-intercom', + }, + company: { + companyId: 'company', + createdAt: 'now', + industry: 'industry', + monthlySpend: 10, + name: 'name', + plan: 'plan', + size: 12, + userCount: 100, + website: 'https://github.com/devrnt/react-use-intercom', + }, + companies: [ + { + companyId: 'company', + createdAt: 'now', + industry: 'industry', + monthlySpend: 10, + name: 'name', + plan: 'plan', + size: 12, + userCount: 100, + website: 'https://github.com/devrnt/react-use-intercom', + }, + ], + backgroundColor: 'green', + createdAt: 'now', + customLauncherSelector: '.id', + hideDefaultLauncher: false, + horizontalPadding: 10, + languageOverride: 'en', + phone: '0470', + sessionDuration: 1000, + unsubscribedFromEmails: false, + userHash: '123', + lastRequestAt: 'now', + utmCampaign: 'campaign', + utmSource: 'source', + utmMedium: 'medium', + utmTerm: 'term', + userId: '12345', + customAttributes: { + my_custom_attribute: 'custom_attribute_value', + my_second_custom_attribute: 'second_custom_attribute_value', + }, + }), + [boot], + ); const handleUpdate = React.useCallback(() => { + update(); + }, [update]); + + const handleSeededUpdate = React.useCallback(() => { update({ name: 'ponas' }); }, [update]); @@ -75,13 +142,27 @@ const RawUseIntercomPage = () => { boots the Intercom instance, not needed if autoBoot in{' '} IntercomProvider is true

-