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: onboard Yandex Metrica Offline Events Destination #3232

Merged
merged 9 commits into from
Apr 29, 2024
yashasvibajpai marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const YANDEX_METRICA_OFFLINE_EVENTS = 'yandex_metrica_offline_events';

module.exports = {
YANDEX_METRICA_OFFLINE_EVENTS,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
bindings:
- name: EventType
path: ../../../../constants
- path: ../../bindings/jsontemplate
exportAll: true
- path: ./config
- name: removeUndefinedAndNullValues
path: ../../../../v0/util
- name: defaultRequestConfig
path: ../../../../v0/util
- path: ./utils

steps:
- name: validateInput
template: |
let messageType = .message.type;
$.assert(messageType, "message Type is not present. Aborting message.");
$.assert(.message.type.toLowerCase() ==='identify', "Event type " + .message.type.toLowerCase() + " is not supported. Aborting message.");
$.assert(.message.traits || .message.properties, "Message traits/properties not present. Aborting message.");

- name: prepareData
template: |
let data = .message.traits
data = $.validateData(data)
let identifierType = .message.context.externalId[0].identifierType;
sanpj2292 marked this conversation as resolved.
Show resolved Hide resolved
let identifierValue = .message.context.externalId[0].id;
data = $.setIdentifier(data, identifierType, identifierValue)
data

- name: buildResponseForProcessTransformation
description: build response
template: |
const response = $.defaultRequestConfig();
response.body.JSON = $.outputs.prepareData
response
33 changes: 33 additions & 0 deletions src/cdk/v2/destinations/yandex_metrica_offline_events/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { InstrumentationError } = require('@rudderstack/integrations-lib');

const setIdentifier = (data, identifierType, identifierValue) => {
const updatedData = data;
if (identifierType === 'ClientId') {
updatedData.ClientId = identifierValue;
} else if (identifierType === 'YCLID') {
updatedData.Yclid = identifierValue;
} else if (identifierType === 'UserId') {
updatedData.UserId = identifierValue;
} else {
throw new InstrumentationError(

Check warning on line 12 in src/cdk/v2/destinations/yandex_metrica_offline_events/utils.js

View check run for this annotation

Codecov / codecov/patch

src/cdk/v2/destinations/yandex_metrica_offline_events/utils.js#L11-L12

Added lines #L11 - L12 were not covered by tests
'Invalid identifier type passed in external Id. Valid types are ClientId, YCLID, UserId. Aborting!',
);
}
return updatedData;
};

const validateData = (data) => {
const { Price } = data;
if (!data) {
throw new InstrumentationError('No traits found in the payload. Aborting!');

Check warning on line 22 in src/cdk/v2/destinations/yandex_metrica_offline_events/utils.js

View check run for this annotation

Codecov / codecov/patch

src/cdk/v2/destinations/yandex_metrica_offline_events/utils.js#L22

Added line #L22 was not covered by tests
}
if (Price && typeof Price !== 'number') {
throw new InstrumentationError('Price can only be a numerical value. Aborting!');
}
return data;
};

module.exports = {
setIdentifier,
validateData,
};
Loading
Loading