Skip to content

Commit

Permalink
feat: clientId support added for ga4 hybrid mode (#1759)
Browse files Browse the repository at this point in the history
* feat: clientId support added for ga4 hybrid mode

* feat: isHybridModeEnabled function moved to common utils
  • Loading branch information
mihir-4116 authored Jan 9, 2023
1 parent 6383171 commit 04638cb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/v0/destinations/ga4/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const {
removeUndefinedAndNullValues,
isDefinedAndNotNull,
getFieldValueFromMessage,
getIntegrationsObj
getIntegrationsObj,
isHybridModeEnabled
} = require("../../util");
const {
InstrumentationError,
Expand Down Expand Up @@ -39,16 +40,25 @@ const {
} = require("./utils");

/**
* Returns GA4 client_id
* returns client_id
* @param {*} message
* @param {*} clientIdFieldIdentifier
* @returns
*/
const getGA4ClientId = (message, { clientIdFieldIdentifier }) => {
const getGA4ClientId = (message, Config) => {
let clientId;
// first we will search from webapp
if (clientIdFieldIdentifier) {
clientId = get(message, clientIdFieldIdentifier);

// if hybrid mode enabled, take client_id from integrationsObj
if (isHybridModeEnabled(Config)) {
const integrationsObj = getIntegrationsObj(message, "ga4");
if (integrationsObj && integrationsObj.clientId) {
return integrationsObj.clientId;
}
}

// for cloud mode first we will search from webapp
if (Config.clientIdFieldIdentifier) {
clientId = get(message, Config.clientIdFieldIdentifier);
}
// if we don't find it from the config then we will fall back to the default search
if (!clientId) {
Expand Down
13 changes: 12 additions & 1 deletion src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,16 @@ const validatePhoneWithCountryCode = phone => {
return !!regex.test(phone);
};

/**
* checks for hybrid mode
* @param {*} Config
* @returns
*/
const isHybridModeEnabled = Config => {
const { useNativeSDK, useNativeSDKToSend } = Config;
return useNativeSDK && !useNativeSDKToSend;
};

// ========================================================================
// EXPORTS
// ========================================================================
Expand Down Expand Up @@ -1874,5 +1884,6 @@ module.exports = {
refinePayload,
validateEmail,
validatePhoneWithCountryCode,
getEventReqMetadata
getEventReqMetadata,
isHybridModeEnabled
};

0 comments on commit 04638cb

Please sign in to comment.