Skip to content

Commit

Permalink
feat: identify and track for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
danrowden committed Jan 10, 2025
1 parent 57fc4fe commit 8bb7426
Show file tree
Hide file tree
Showing 2 changed files with 425 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/cdk/v2/destinations/loops/procWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
bindings:
- name: EventType
path: ../../../../constants
- path: ../../bindings/jsontemplate
exportAll: true
- name: removeUndefinedAndNullValues
path: ../../../../v0/util

steps:
- name: messageType
template: |
.message.type.toLowerCase();
- name: validateInput
template: |
$.assert(.message.type, "message Type is not present. Aborting message.");
$.assert(.message.type in {{$.EventType.([.TRACK, .IDENTIFY])}},
"message type " + .message.type + " is not supported");
- name: validateIdentifyEmail
condition: $.outputs.messageType === {{$.EventType.IDENTIFY}}
template: |
console.log(.message.context.traits);
$.assert(.message.context.traits.email, "email is required. Aborting");
- name: validateTrackIdentifier
condition: $.outputs.messageType === {{$.EventType.TRACK}}
template: |
const userId = .message.({{{{$.getGenericPaths("userIdOnly")}}}});
$.assert(.message.context.traits?.email || userId,
"Either email or userId is required. Aborting");
- name: validateEventName
condition: $.outputs.messageType === {{$.EventType.TRACK}}
template: |
$.assert(.message.event, "event is required for track call")
- name: prepareContext
template: |
$.context.messageType = .message.type.toLowerCase();
$.context.payload = {};
$.context.finalHeaders = {
"authorization": "Bearer " + .destination.Config.apiKey,
"content-type": "application/json"
};
- name: identifyPayload
condition: $.outputs.messageType === {{$.EventType.IDENTIFY}}
template: |
$.context.endpoint = "https://app.loops.so/api/v1/contacts/update";
const payload = {}
Object.assign(payload, .message.context.traits);
payload.userId = .message.userId;
$.context.payload = payload;
- name: trackPayload
condition: $.outputs.messageType === {{$.EventType.TRACK}}
template: |
$.context.endpoint = "https://app.loops.so/api/v1/events/send";
const payload = {}
Object.assign(payload, .message.context.traits);
payload.userId = .message.userId;
payload.eventName = .message.event;
payload.eventProperties = .message.properties;
$.context.payload = payload;
Loading

0 comments on commit 8bb7426

Please sign in to comment.