From 588ed5581a7602620febb7fd21e83f86cf7034bf Mon Sep 17 00:00:00 2001 From: "M. Clay Johns" Date: Tue, 25 Jan 2022 13:12:16 -0700 Subject: [PATCH 1/2] use label_short if available Using the short label here allows us to specify the exact field we'd like to send to Segment. Otherwise, the "name" field is determined by Looker for us, and has its own limitations (e.g. it does not support uppercase characters). --- src/actions/segment/segment.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/actions/segment/segment.ts b/src/actions/segment/segment.ts index 7279345f9..2ccc230e0 100644 --- a/src/actions/segment/segment.ts +++ b/src/actions/segment/segment.ts @@ -222,6 +222,13 @@ export class SegmentAction extends Hub.Action { ) { const traits: { [key: string]: string } = {} for (const field of fields) { + /** + * Using the short label here allows us to specify the exact field we'd like + * to send to Segment. Otherwise, the "name" field is determined by Looker for + * us, and has its own limitations (e.g. it does not support uppercase characters). + */ + const traitName = field.label_short || field.name + if (segmentFields.idFieldNames.indexOf(field.name) === -1) { if (hiddenFields.indexOf(field.name) === -1) { let values: any = {} From 8afb557758e02466e2ddba1fc48954e937edfc27 Mon Sep 17 00:00:00 2001 From: "M. Clay Johns" Date: Tue, 25 Jan 2022 13:13:31 -0700 Subject: [PATCH 2/2] add tests for label_short override --- src/actions/segment/test_segment.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/actions/segment/test_segment.ts b/src/actions/segment/test_segment.ts index e6362fafd..dd6707484 100644 --- a/src/actions/segment/test_segment.ts +++ b/src/actions/segment/test_segment.ts @@ -161,6 +161,31 @@ describe(`${action.constructor.name} unit tests`, () => { }) }) + it("uses the field's short label as the trait name when present", () => { + const request = new Hub.ActionRequest() + request.type = Hub.ActionType.Query + request.params = { + segment_write_key: "mykey", + } + request.attachment = {dataBuffer: Buffer.from(JSON.stringify({ + fields: {dimensions: [ + {name: "coolid", tags: ["user_id"]}, + {name: "cooltrait", label_short: "coolshortlabel", tags: []}, + ]}, + data: [{ + coolid: {value: "id"}, + cooltrait: {value: "funtrait"}, + }], + }))} + return expectSegmentMatch(request, { + userId: "id", + traits: { + coolshortlabel: "funtrait", + }, + anonymousId: null, + }) + }) + it("works with user id and anonymous id", () => { const request = new Hub.ActionRequest() request.type = Hub.ActionType.Query