diff --git a/src/v0/destinations/campaign_manager/data/CampaignManagerTrackConfig.json b/src/v0/destinations/campaign_manager/data/CampaignManagerTrackConfig.json index f36ba8da8a..c8bd10d524 100644 --- a/src/v0/destinations/campaign_manager/data/CampaignManagerTrackConfig.json +++ b/src/v0/destinations/campaign_manager/data/CampaignManagerTrackConfig.json @@ -12,7 +12,8 @@ { "destKey": "timestampMicros", "sourceKeys": "timestamp", - "sourceFromGenericMap": true + "sourceFromGenericMap": true, + "required": true }, { "destKey": "floodlightActivityId", diff --git a/src/v0/destinations/campaign_manager/networkHandler.js b/src/v0/destinations/campaign_manager/networkHandler.js index a80fff6fe4..d8498b7621 100644 --- a/src/v0/destinations/campaign_manager/networkHandler.js +++ b/src/v0/destinations/campaign_manager/networkHandler.js @@ -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; 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 => { + // if code is any of these, event is not retryable + if ( + err.code === 'PERMISSION_DENIED' || + err.code === 'INVALID_ARGUMENT' || + err.code === 'NOT_FOUND' + ) { + isRetryable = false; + } + }) + } } - return true; + return isRetryable; } catch (e) { return true; } diff --git a/src/v0/destinations/campaign_manager/transform.js b/src/v0/destinations/campaign_manager/transform.js index a8983ebccd..5393f18631 100644 --- a/src/v0/destinations/campaign_manager/transform.js +++ b/src/v0/destinations/campaign_manager/transform.js @@ -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; diff --git a/test/__tests__/data/campaign_manager.json b/test/__tests__/data/campaign_manager.json index 6139ddbeb3..4347ce8394 100644 --- a/test/__tests__/data/campaign_manager.json +++ b/test/__tests__/data/campaign_manager.json @@ -572,53 +572,89 @@ "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": "alex@example.com", - "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", @@ -626,7 +662,7 @@ "matchId": "12312321", "requestType": "batchupdate" }, - "originalTimestamp": 1668624722555000, + "timestamp": 1668624722555000, "type": "track", "event": "event test", "anonymousId": "randomId", @@ -670,7 +706,7 @@ "conversions": [ { "floodlightConfigurationId": "213123123", - "ordinal": "string", + "ordinal": "213123", "timestampMicros": "1668624722555000", "floodlightActivityId": "456543345245", "quantity": "455678",