Skip to content

Commit

Permalink
feat(gaec): partial failures handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mihir-4116 committed Sep 19, 2023
1 parent 36c7f06 commit e6e61d7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,21 @@ const responseHandler = (destinationResponse) => {
const message = 'Request Processed Successfully';
const { status } = destinationResponse;
if (isHttpStatusSuccess(status)) {
// Mostly any error will not have a status of 2xx
// for google ads enhance conversions the partialFailureError returns with status 200
const { partialFailureError } = destinationResponse.response;
// non-zero code signifies partialFailure
// Ref - https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
if (partialFailureError && partialFailureError.code !== 0) {
throw new NetworkError(
`[Google Ads Offline Conversions]:: partialFailureError - ${partialFailureError?.message}`,
400,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(400),
},
partialFailureError,
);
}

return {
status,
message,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-param-reassign */

const moment = require('moment');
const get = require('get-value');
const { cloneDeep } = require('lodash');
const {
Expand All @@ -11,10 +11,7 @@ const {
getAccessToken,
} = require('../../util');

const {
InstrumentationError,
ConfigurationError,
} = require('../../util/errorTypes');
const { InstrumentationError, ConfigurationError } = require('../../util/errorTypes');

const { trackMapping, BASE_ENDPOINT } = require('./config');
const { JSON_MIME_TYPE } = require('../../util/constant');
Expand Down Expand Up @@ -86,6 +83,18 @@ const processTrackEvent = async (metadata, message, destination) => {
`Any of email, phone, firstName, lastName, city, street, countryCode, postalCode or streetAddress is required in traits.`,
);
}

if (payload.conversionAdjustments[0].gclidDateTimePair.conversionDateTime) {
const conversionDateTime = moment(
payload.conversionAdjustments[0].gclidDateTimePair.conversionDateTime,
)
.utcOffset(
moment(payload.conversionAdjustments[0].gclidDateTimePair.conversionDateTime).utcOffset(),
)
.format('YYYY-MM-DD HH:mm:ssZ');
payload.conversionAdjustments[0].gclidDateTimePair.conversionDateTime = conversionDateTime;
}

payload.conversionAdjustments[0].adjustmentType = 'ENHANCEMENT';
// Removing the null values from userIdentifier
const arr = payload.conversionAdjustments[0].userIdentifiers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{
"gclidDateTimePair": {
"gclid": "gclid1234",
"conversionDateTime": "2022-01-01 12:32:45-08:00"
"conversionDateTime": "2022-01-02 02:02:45+05:30"
},
"restatementValue": {
"adjustedValue": 10,
Expand Down Expand Up @@ -108,7 +108,7 @@
{
"gclidDateTimePair": {
"gclid": "gclid1234",
"conversionDateTime": "2022-01-01 12:32:45-08:00"
"conversionDateTime": "2022-01-02 02:02:45+05:30"
},
"restatementValue": {
"adjustedValue": 10,
Expand Down Expand Up @@ -221,7 +221,7 @@
{
"gclidDateTimePair": {
"gclid": "gclid1234",
"conversionDateTime": "2022-01-01 12:32:45-08:00"
"conversionDateTime": "2022-01-02 02:02:45+05:30"
},
"restatementValue": {
"adjustedValue": 10,
Expand Down Expand Up @@ -277,7 +277,7 @@
{
"gclidDateTimePair": {
"gclid": "gclid1234",
"conversionDateTime": "2022-01-01 12:32:45-08:00"
"conversionDateTime": "2022-01-02 02:02:45+05:30"
},
"restatementValue": {
"adjustedValue": 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"gclidDateTimePair": {
"gclid": "gclid1234",
"conversionDateTime": "2022-01-01 12:32:45-08:00"
"conversionDateTime": "2022-01-02 02:02:45+05:30"
},
"restatementValue": {
"adjustedValue": 10,
Expand Down

0 comments on commit e6e61d7

Please sign in to comment.