Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: identify and track for loops #3976

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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