mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Add custom traits to Segment Node (#1145)
This commit is contained in:
parent
1630d20e39
commit
03a672300f
|
@ -262,6 +262,38 @@ export const identifyFields = [
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Custom Traits',
|
||||||
|
name: 'customTraitsUi',
|
||||||
|
placeholder: 'Add Custom Trait',
|
||||||
|
type: 'fixedCollection',
|
||||||
|
default: '',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'customTraitValues',
|
||||||
|
displayName: 'Custom Traits',
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
displayName: 'Key',
|
||||||
|
name: 'key',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Value',
|
||||||
|
name: 'value',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -38,6 +38,7 @@ import {
|
||||||
} from './TrackInterface';
|
} from './TrackInterface';
|
||||||
|
|
||||||
import * as uuid from 'uuid/v4';
|
import * as uuid from 'uuid/v4';
|
||||||
|
import { customerFields } from '../CustomerIo/CustomerDescription';
|
||||||
|
|
||||||
export class Segment implements INodeType {
|
export class Segment implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -170,6 +171,7 @@ export class Segment implements INodeType {
|
||||||
if (traits.id) {
|
if (traits.id) {
|
||||||
body.traits!.id = traits.id as string;
|
body.traits!.id = traits.id as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (traits.company) {
|
if (traits.company) {
|
||||||
const company = (traits.company as IDataObject).companyUi as IDataObject;
|
const company = (traits.company as IDataObject).companyUi as IDataObject;
|
||||||
if (company) {
|
if (company) {
|
||||||
|
@ -384,6 +386,14 @@ export class Segment implements INodeType {
|
||||||
if (traits.id) {
|
if (traits.id) {
|
||||||
body.traits!.id = traits.id as string;
|
body.traits!.id = traits.id as string;
|
||||||
}
|
}
|
||||||
|
if (traits.customTraitsUi) {
|
||||||
|
const customTraits = (traits.customTraitsUi as IDataObject).customTraitValues as IDataObject[];
|
||||||
|
if (customTraits && customTraits.length !== 0) {
|
||||||
|
for (const customTrait of customTraits) {
|
||||||
|
body.traits![customTrait.key as string] = customTrait.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (traits.company) {
|
if (traits.company) {
|
||||||
const company = (traits.company as IDataObject).companyUi as IDataObject;
|
const company = (traits.company as IDataObject).companyUi as IDataObject;
|
||||||
if (company) {
|
if (company) {
|
||||||
|
@ -531,6 +541,17 @@ export class Segment implements INodeType {
|
||||||
body.integrations!.salesforce = integrations.salesforce as boolean;
|
body.integrations!.salesforce = integrations.salesforce as boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Object.keys(traits.company as IDataObject).length === 0) {
|
||||||
|
//@ts-ignore
|
||||||
|
delete body.traits.company;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(traits.address as IDataObject).length === 0) {
|
||||||
|
//@ts-ignore
|
||||||
|
delete body.traits.address;
|
||||||
|
}
|
||||||
|
|
||||||
responseData = await segmentApiRequest.call(this, 'POST', '/identify', body);
|
responseData = await segmentApiRequest.call(this, 'POST', '/identify', body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -602,6 +623,14 @@ export class Segment implements INodeType {
|
||||||
if (traits.id) {
|
if (traits.id) {
|
||||||
body.traits!.id = traits.id as string;
|
body.traits!.id = traits.id as string;
|
||||||
}
|
}
|
||||||
|
if (traits.customTraitsUi) {
|
||||||
|
const customTraits = (traits.customTraitsUi as IDataObject).customTraitValues as IDataObject[];
|
||||||
|
if (customTraits && customTraits.length !== 0) {
|
||||||
|
for (const customTrait of customTraits) {
|
||||||
|
body.traits![customTrait.key as string] = customTrait.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (traits.company) {
|
if (traits.company) {
|
||||||
const company = (traits.company as IDataObject).companyUi as IDataObject;
|
const company = (traits.company as IDataObject).companyUi as IDataObject;
|
||||||
if (company) {
|
if (company) {
|
||||||
|
@ -760,6 +789,17 @@ export class Segment implements INodeType {
|
||||||
body.properties!.value = properties.value as string;
|
body.properties!.value = properties.value as string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Object.keys(traits.company as IDataObject).length === 0) {
|
||||||
|
//@ts-ignore
|
||||||
|
delete body.traits.company;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(traits.address as IDataObject).length === 0) {
|
||||||
|
//@ts-ignore
|
||||||
|
delete body.traits.address;
|
||||||
|
}
|
||||||
|
|
||||||
responseData = await segmentApiRequest.call(this, 'POST', '/track', body);
|
responseData = await segmentApiRequest.call(this, 'POST', '/track', body);
|
||||||
}
|
}
|
||||||
//https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/#page
|
//https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/#page
|
||||||
|
|
|
@ -285,6 +285,38 @@ export const trackFields = [
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Custom Traits',
|
||||||
|
name: 'customTraitsUi',
|
||||||
|
placeholder: 'Add Custom Trait',
|
||||||
|
type: 'fixedCollection',
|
||||||
|
default: '',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'customTraitValues',
|
||||||
|
displayName: 'Custom Traits',
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
displayName: 'Key',
|
||||||
|
name: 'key',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Value',
|
||||||
|
name: 'value',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue