Skip to content

Commit

Permalink
chore: addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishmalik committed Sep 26, 2023
1 parent 3771b3d commit 3e589e7
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
{
"destKey": "timestampMicros",
"sourceKeys": "timestamp",
"sourceFromGenericMap": true
"sourceFromGenericMap": true,
"required": true
},
{
"destKey": "floodlightActivityId",
Expand Down
34 changes: 28 additions & 6 deletions src/v0/destinations/campaign_manager/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,36 @@ const { AbortedError, RetryableError, NetworkError } = require('../../util/error
const tags = require('../../util/tags');

function checkIfFailuresAreRetryable(response) {
const { status } = response;
let isRetryable = true;

Check warning on line 13 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L12-L13

Added lines #L12 - L13 were not covered by tests
try {
if (Array.isArray(response.status) && Array.isArray(response.status[0].errors)) {
return (
response.status[0].errors[0].code !== 'PERMISSION_DENIED' &&
response.status[0].errors[0].code !== 'INVALID_ARGUMENT'
);
if (Array.isArray(status)) {
// iterate over each status, and if found retryable in conversations ..retry else discard
/* status : [{
"conversion": {
object (Conversion)
},
"errors": [
{
object (ConversionError)
}
],
"kind": string
}] */
for (const st of status) {
st.errors.forEach(err => {

Check warning on line 29 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L28-L29

Added lines #L28 - L29 were not covered by tests
// if code is any of these, event is not retryable
if (
err.code === 'PERMISSION_DENIED' ||
err.code === 'INVALID_ARGUMENT' ||
err.code === 'NOT_FOUND'

Check warning on line 34 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L32-L34

Added lines #L32 - L34 were not covered by tests
) {
isRetryable = false;

Check warning on line 36 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L36

Added line #L36 was not covered by tests
}
})
}
}
return true;
return isRetryable;

Check warning on line 41 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L41

Added line #L41 was not covered by tests
} catch (e) {
return true;
}
Expand Down
11 changes: 10 additions & 1 deletion src/v0/destinations/campaign_manager/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,19 @@ function processTrack(message, metadata, destination) {
delete requestJson.limitAdTracking;
}

// for handling when input is timestamp as string
const numTimestamp = /^\d+$/.test(requestJson.timestampMicros);
if (numTimestamp) {
// is digit only, below convert string timestamp to numeric
requestJson.timestampMicros *= 1;
}

// 2022-10-11T05:453:90.ZZ
// 16483423423423423
const date = new Date(requestJson.timestampMicros);
let unixTimestamp = date.getTime();
// Date, moment both are not able to distinguish input if it is second,millisecond or microsecond unix timestamp
// Using count of digits to distinguish between the 3, 9999999999999 (13 digits) means Nov 20 2286
// Using count of digits to distinguish between these 3, 9999999999999 (13 digits) means Nov 20 2286 which is long far in future
if (unixTimestamp.toString().length === 13) {
// milliseconds
unixTimestamp *= 1000;
Expand Down
126 changes: 81 additions & 45 deletions test/__tests__/data/campaign_manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,61 +572,97 @@
"description": "Track - batch update Call timestamp as unix",
"input": {
"message": {
"channel": "web",
"context": {
"app": {
"build": "1.0.0",
"name": "RudderLabs JavaScript SDK",
"namespace": "com.rudderlabs.javascript",
"version": "1.0.0"
},
"device": {
"id": "0572f78fa49c648e",
"name": "generic_x86_arm",
"type": "Android",
"model": "AOSP on IA Emulator",
"manufacturer": "Google",
"adTrackingEnabled": true,
"advertisingId": "44c97318-9040-4361-8bc7-4eb30f665ca8"
},
"traits": {
"email": "[email protected]",
"phone": "+1-202-555-0146",
"firstName": "John",
"lastName": "Gomes",
"city": "London",
"state": "England",
"countryCode": "GB",
"postalCode": "EC3M",
"streetAddress": "71 Cherry Court SOUTHAMPTON SO53 5PD UK"
},
"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36",
"locale": "en-US",
"ip": "0.0.0.0",
"os": {
"name": "",
"version": ""
},
"screen": {
"density": 2
}
"channel": "sources",
"properties": {
"profileId": "34245",
"floodlightConfigurationId": "213123123",
"ordinal": "213123",
"floodlightActivityId": "456543345245",
"value": "756",
"quantity": "455678",
"timestamp": "1668624722903000",
"matchId": "12312321",
"requestType": "batchupdate"
},
"timestamp": "1668624722555000",
"type": "track",
"event": "event test",
"anonymousId": "randomId",
"integrations": {
"All": true
},
"name": "ApplicationLoaded",
"sentAt": "2019-10-14T11:15:53.296Z"
},
"metadata": {
"secret": {
"access_token": "dummyApiToken",
"refresh_token": "efgh5678",
"developer_token": "ijkl91011"
}
},
"destination": {
"Config": {
"profileId": "5343234",
"treatmentForUnderage": false,
"limitAdTracking": false,
"childDirectedTreatment": false,
"nonPersonalizedAd": false,
"rudderAccountId": "2EOknn1JNH7WK1MfNku4fGYKkRK"
}
}
},
"output": {
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://dfareporting.googleapis.com/dfareporting/v4/userprofiles/34245/conversions/batchupdate",
"headers": {
"Authorization": "Bearer dummyApiToken",
"Content-Type": "application/json"
},
"params": {},
"body": {
"JSON": {
"kind": "dfareporting#conversionsBatchUpdateRequest",
"conversions": [
{
"floodlightConfigurationId": "213123123",
"ordinal": "213123",
"timestampMicros": "1668624722555000",
"floodlightActivityId": "456543345245",
"quantity": "455678",
"value": 756,
"matchId": "12312321",
"treatmentForUnderage": false,
"nonPersonalizedAd": false
}
]
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {}
}
},
{
"description": "Track - batch update Call timestamp as unix as digit",
"input": {
"message": {
"channel": "sources",
"properties": {
"profileId": "34245",
"floodlightConfigurationId": "213123123",
"ordinal": "string",
"ordinal": "213123",
"floodlightActivityId": "456543345245",
"value": "756",
"quantity": "455678",
"timestamp": "1668624722903000",
"matchId": "12312321",
"requestType": "batchupdate"
},
"originalTimestamp": 1668624722555000,
"timestamp": 1668624722555000,
"type": "track",
"event": "event test",
"anonymousId": "randomId",
Expand Down Expand Up @@ -670,7 +706,7 @@
"conversions": [
{
"floodlightConfigurationId": "213123123",
"ordinal": "string",
"ordinal": "213123",
"timestampMicros": "1668624722555000",
"floodlightActivityId": "456543345245",
"quantity": "455678",
Expand Down

0 comments on commit 3e589e7

Please sign in to comment.