Skip to content

Commit

Permalink
chore: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc committed Jun 11, 2024
1 parent 696352d commit bb3d938
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
22 changes: 4 additions & 18 deletions src/v0/destinations/ga4/transform.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const get = require('get-value');
const {
ConfigurationError,
InstrumentationError,
UnsupportedEventError,
} = require('@rudderstack/integrations-lib');
const { InstrumentationError, UnsupportedEventError } = require('@rudderstack/integrations-lib');
const { EventType } = require('../../../constants');
const {
isEmptyObject,
Expand Down Expand Up @@ -33,6 +29,7 @@ const {
basicValidation,
addClientDetails,
buildDeliverablePayload,
basicConfigvalidaiton,
} = require('./utils');
require('../../util/constant');

Expand Down Expand Up @@ -204,23 +201,12 @@ const process = (event) => {
const { message, destination } = event;
const { Config } = destination;

if (!Config.typesOfClient) {
throw new ConfigurationError('Client type not found. Aborting ');
}
if (!Config.apiSecret) {
throw new ConfigurationError('API Secret not found. Aborting ');
}
if (Config.typesOfClient === 'gtag' && !Config.measurementId) {
throw new ConfigurationError('measurementId must be provided. Aborting');
}
if (Config.typesOfClient === 'firebase' && !Config.firebaseAppId) {
throw new ConfigurationError('firebaseAppId must be provided. Aborting');
}

if (!message.type) {
throw new InstrumentationError('Message Type is not present. Aborting message.');
}

basicConfigvalidaiton(Config);

const messageType = message.type.toLowerCase();

let response;
Expand Down
16 changes: 16 additions & 0 deletions src/v0/destinations/ga4/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,26 @@ const sanitizeUserProperties = (userProperties) => {
});
};

const basicConfigvalidaiton = (Config) => {
if (!Config.typesOfClient) {
throw new ConfigurationError('Client type not found. Aborting ');

Check warning on line 575 in src/v0/destinations/ga4/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/ga4/utils.js#L575

Added line #L575 was not covered by tests
}
if (!Config.apiSecret) {
throw new ConfigurationError('API Secret not found. Aborting ');
}
if (Config.typesOfClient === 'gtag' && !Config.measurementId) {
throw new ConfigurationError('measurementId must be provided. Aborting');
}
if (Config.typesOfClient === 'firebase' && !Config.firebaseAppId) {
throw new ConfigurationError('firebaseAppId must be provided. Aborting');
}
};

module.exports = {
addClientDetails,
basicValidation,
buildDeliverablePayload,
basicConfigvalidaiton,
getItem,
getItemList,
getItemsArray,
Expand Down
20 changes: 3 additions & 17 deletions src/v0/destinations/ga4_v2/transform.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import {
ConfigurationError,
InstrumentationError,
RudderStackEvent,
} from '@rudderstack/integrations-lib';
import { InstrumentationError, RudderStackEvent } from '@rudderstack/integrations-lib';
import { ProcessorTransformationRequest } from '../../../types';
import { handleCustomMappings } from './customMappingsHandler';
import { process as ga4Process } from '../ga4/transform';
import { basicConfigvalidaiton } from '../ga4/utils';

export function process(event: ProcessorTransformationRequest) {
const { message, destination } = event;
const { Config } = destination;

if (!Config.typesOfClient) {
throw new ConfigurationError('Client type not found. Aborting ');
}
if (!Config.apiSecret) {
throw new ConfigurationError('API Secret not found. Aborting ');
}
if (Config.typesOfClient === 'gtag' && !Config.measurementId) {
throw new ConfigurationError('measurementId must be provided. Aborting');
}
if (Config.typesOfClient === 'firebase' && !Config.firebaseAppId) {
throw new ConfigurationError('firebaseAppId must be provided. Aborting');
}
basicConfigvalidaiton(Config);

const eventPayload = message as RudderStackEvent;

Expand Down

0 comments on commit bb3d938

Please sign in to comment.