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

Accoil analytics destination #3873

Open
wants to merge 1 commit 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
123 changes: 123 additions & 0 deletions src/cdk/v2/destinations/accoil_analytics/procWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
bindings:
- name: EventType
path: ../../../../constants
- path: ../../bindings/jsontemplate
exportAll: true
- name: removeUndefinedAndNullValues
path: ../../../../v0/util
- name: base64Convertor
path: ../../../../v0/util
- path: ./utils

steps:
- name: validateInput
template: |
$.assert(.message.type, "message type is not present. Aborting message.");
$.assert(.message.type in {{$.EventType.([.TRACK, .PAGE, .SCREEN, .IDENTIFY, .GROUP])}},
"message type " + .message.type + " is not supported");
accoilmj marked this conversation as resolved.
Show resolved Hide resolved
$.assertConfig(.destination.Config.apiKey, "apiKey must be supplied in destination config");

# Note our auth does not require a password in basic auth just the string "key:"
- name: prepareContext
template: |
$.context.messageType = .message.type.toLowerCase();
$.context.payload = {
"type": $.context.messageType
};
$.context.finalHeaders = {
"authorization": "Basic " + $.base64Convertor(.destination.Config.apiKey + ":"),
"content-type": "application/json"
};
$.context.endpoint = $.endpointUrl(.destination.Config.apiKey);

- name: trackPayload
condition: $.context.messageType == {{$.EventType.TRACK}}
template: |
$.context.payload.event = .message.event;
$.context.payload.userId = .message.().({{{{$.getGenericPaths("userId")}}}})
$.context.payload.timestamp = .message.().({{{{$.getGenericPaths("timestamp")}}}})

- name: pagePayload
condition: $.context.messageType == {{$.EventType.PAGE}}
template: |
$.context.payload.userId = .message.().({{{{$.getGenericPaths("userId")}}}});
$.context.payload.name = .message.name;
$.context.payload.timestamp = .message.().({{{{$.getGenericPaths("timestamp")}}}});

- name: screenPayload
condition: $.context.messageType == {{$.EventType.SCREEN}}
template: |
$.context.payload.userId = .message.().({{{{$.getGenericPaths("userId")}}}});
$.context.payload.name = .message.name;
$.context.payload.timestamp = .message.().({{{{$.getGenericPaths("timestamp")}}}});

- name: identifyPayload
condition: $.context.messageType == {{$.EventType.IDENTIFY}}
template: |
$.context.payload.userId = .message.().({{{{$.getGenericPaths("userId")}}}});
$.context.payload.traits = .message.traits ?? .message.context.traits;
$.context.payload.timestamp = .message.().({{{{$.getGenericPaths("timestamp")}}}});

- name: groupPayload
condition: $.context.messageType == {{$.EventType.GROUP}}
template: |
$.context.payload.anonymousId = .message.anonymousId;
$.context.payload.userId = .message.().({{{{$.getGenericPaths("userId")}}}});
$.context.payload.groupId = .message.groupId;
$.context.payload.timestamp = .message.().({{{{$.getGenericPaths("timestamp")}}}});
$.context.payload.traits = .message.traits ?? .message.context.traits;

- name: validateTimestamp
template: |
$.assert($.context.payload.timestamp, "timestamp is required for all calls")
accoilmj marked this conversation as resolved.
Show resolved Hide resolved

- name: validateTrackPayload
condition: $.context.messageType == {{$.EventType.TRACK}}
template: |
$.assert($.context.payload.event, "event is required for track call")
$.assert($.context.payload.userId, "userId is required for track call")

- name: validatePagePayload
condition: $.context.messageType == {{$.EventType.PAGE}}
template: |
$.assert($.context.payload.name, "name is required for page call")
$.assert($.context.payload.userId, "userId is required for page call")

- name: validateScreenPayload
condition: $.context.messageType == {{$.EventType.SCREEN}}
template: |
$.assert($.context.payload.name, "name is required for screen call")
$.assert($.context.payload.userId, "userId is required for screen call")

- name: validateIdentifyPayload
condition: $.context.messageType == {{$.EventType.IDENTIFY}}
template: |
$.assert($.context.payload.userId, "userId is required for identify call")

- name: validateGroupPayload
condition: $.context.messageType == {{$.EventType.GROUP}}
template: |
$.assert($.context.payload.userId, "userId is required for group call")
$.assert($.context.payload.groupId, "groupId is required for group call")

accoilmj marked this conversation as resolved.
Show resolved Hide resolved
- name: cleanPayload
template: |
$.context.payload = $.removeUndefinedAndNullValues($.context.payload);

- name: buildResponseForProcessTransformation
template: |
$.context.payload.({
"body": {
"JSON": .,
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": $.context.endpoint,
"headers": $.context.finalHeaders,
"params": {},
"files": {}
})
33 changes: 33 additions & 0 deletions src/cdk/v2/destinations/accoil_analytics/rtWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
bindings:
- name: handleRtTfSingleEventError
path: ../../../../v0/util/index

steps:
- name: validateInput
template: |
$.assert(Array.isArray(^) && ^.length > 0, "Invalid event array")

- name: transform
externalWorkflow:
path: ./procWorkflow.yaml
loopOverInput: true

- name: successfulEvents
template: |
$.outputs.transform#idx.output.({
"batchedRequest": .,
"batched": false,
"destination": ^[idx].destination,
"metadata": ^[idx].metadata[],
"statusCode": 200
})[]

- name: failedEvents
template: |
$.outputs.transform#idx.error.(
$.handleRtTfSingleEventError(^[idx], .originalError ?? ., {})
)[]

- name: finalPayload
template: |
[...$.outputs.failedEvents, ...$.outputs.successfulEvents]
10 changes: 10 additions & 0 deletions src/cdk/v2/destinations/accoil_analytics/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const stgRegex = new RegExp(/^stg_/, 'i');

const endpointUrl = (apiKey) => {
const staging = stgRegex.test(apiKey);
return staging ? 'https://instaging.accoil.com/segment' : 'https://in.accoil.com/segment';
};

module.exports = {
endpointUrl,
};
Loading