Skip to content

Commit

Permalink
chore: onboard ga4 v2
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc committed Jun 10, 2024
1 parent 6a3d583 commit f2b8bbd
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 14 deletions.
5 changes: 0 additions & 5 deletions src/v0/destinations/ga4/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const {
buildDeliverablePayload,
} = require('./utils');
require('../../util/constant');
const { handleCustomMappings } = require('./customMappingsHandler');

/**
* Returns response for GA4 destination
Expand Down Expand Up @@ -224,10 +223,6 @@ const process = (event) => {

const messageType = message.type.toLowerCase();

if (Array.isArray(Config.eventsMapping) && Config.eventsMapping.length > 0) {
// custom mappings flow
return handleCustomMappings(message, Config);
}
let response;
switch (messageType) {
case EventType.TRACK:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
GA4_PARAMETERS_EXCLUSION,
prepareUserProperties,
sanitizeUserProperties,
} = require('./utils');
} = require('../ga4/utils');
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const {
removeUndefinedAndNullRecurse,
Expand All @@ -25,7 +25,7 @@ const {
getIntegrationsObj,
applyCustomMappings,
} = require('../../util');
const { trackCommonConfig, ConfigCategory, mappingConfig } = require('./config');
const { trackCommonConfig, ConfigCategory, mappingConfig } = require('../ga4/config');

const findGA4Events = (eventsMapping, event) => {
// Find the event using destructuring and early return
Expand Down
34 changes: 34 additions & 0 deletions src/v0/destinations/ga4_v2/transform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
ConfigurationError,
InstrumentationError,
RudderStackEvent,
} from '@rudderstack/integrations-lib';
import { ProcessorTransformationRequest } from '../../../types';
import { handleCustomMappings } from './customMappingsHandler';

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

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

Check warning on line 14 in src/v0/destinations/ga4_v2/transform.ts

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/ga4_v2/transform.ts#L14

Added line #L14 was not covered by tests
}
if (!Config.apiSecret) {
throw new ConfigurationError('API Secret not found. Aborting ');

Check warning on line 17 in src/v0/destinations/ga4_v2/transform.ts

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/ga4_v2/transform.ts#L17

Added line #L17 was not covered by tests
}
if (Config.typesOfClient === 'gtag' && !Config.measurementId) {
throw new ConfigurationError('measurementId must be provided. Aborting');

Check warning on line 20 in src/v0/destinations/ga4_v2/transform.ts

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/ga4_v2/transform.ts#L20

Added line #L20 was not covered by tests
}
if (Config.typesOfClient === 'firebase' && !Config.firebaseAppId) {
throw new ConfigurationError('firebaseAppId must be provided. Aborting');

Check warning on line 23 in src/v0/destinations/ga4_v2/transform.ts

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/ga4_v2/transform.ts#L23

Added line #L23 was not covered by tests
}

const eventPayload = message as RudderStackEvent;

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

Check warning on line 29 in src/v0/destinations/ga4_v2/transform.ts

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/ga4_v2/transform.ts#L29

Added line #L29 was not covered by tests
}

// custom mappings flow
return handleCustomMappings(message, Config);
}
3 changes: 1 addition & 2 deletions test/integrations/destinations/ga4/processor/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { customMappingTestCases } from './customMappings';
import { existingTests } from './exisitngTests';

export const data = [...existingTests, ...customMappingTestCases];
export const data = [...existingTests];
5 changes: 5 additions & 0 deletions test/integrations/destinations/ga4_v2/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const defaultMockFns = () => {
return jest
.spyOn(Date, 'now')
.mockImplementation(() => new Date('2022-04-29T05:17:09Z').valueOf());
};
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const eventsMapping = [
},
{
to: '$.events[0].params.items[*].name',
from: "$.properties.products[?(@.name=='Salt')].name",
from: '$.properties.products[*].name',
},
{
to: '$.events[0].params.prices',
Expand Down Expand Up @@ -227,7 +227,7 @@ const destination = {
};
export const customMappingTestCases = [
{
name: 'ga4',
name: 'ga4_v2',
id: 'ga4_custom_mapping_test_0',
description: 'Custom Mapping Test 0',
feature: 'processor',
Expand Down Expand Up @@ -293,6 +293,7 @@ export const customMappingTestCases = [
id: 213123,
key: 'someValue',
list_id: 'random_list_id',
name: 'Sugar',
},
],
prices: 456,
Expand Down Expand Up @@ -327,7 +328,7 @@ export const customMappingTestCases = [
mockFns: defaultMockFns,
},
{
name: 'ga4',
name: 'ga4_v2',
id: 'ga4_custom_mapping_test_1',
description: 'Custom Mapping Test for multiplexing',
feature: 'processor',
Expand Down Expand Up @@ -491,7 +492,7 @@ export const customMappingTestCases = [
mockFns: defaultMockFns,
},
{
name: 'ga4',
name: 'ga4_v2',
id: 'ga4_custom_mapping_test_2',
description: 'Custom Mapping Test For mapping not present in events mapping',
feature: 'processor',
Expand Down Expand Up @@ -616,7 +617,7 @@ export const customMappingTestCases = [
mockFns: defaultMockFns,
},
{
name: 'ga4',
name: 'ga4_v2',
id: 'ga4_custom_mapping_test_3',
description: 'Custom Mapping Test For Group Event Type',
feature: 'processor',
Expand Down
3 changes: 3 additions & 0 deletions test/integrations/destinations/ga4_v2/processor/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { customMappingTestCases } from './customMappings';

export const data = [...customMappingTestCases];

0 comments on commit f2b8bbd

Please sign in to comment.