From 04638cb1550c05435a12d8ed481fd55c13e667da Mon Sep 17 00:00:00 2001 From: Mihir Bhalala <77438541+mihir-4116@users.noreply.github.com> Date: Mon, 9 Jan 2023 11:56:45 +0530 Subject: [PATCH] feat: clientId support added for ga4 hybrid mode (#1759) * feat: clientId support added for ga4 hybrid mode * feat: isHybridModeEnabled function moved to common utils --- src/v0/destinations/ga4/transform.js | 22 ++++++++++++++++------ src/v0/util/index.js | 13 ++++++++++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/v0/destinations/ga4/transform.js b/src/v0/destinations/ga4/transform.js index c8e62a9f4fd..5125a214b37 100644 --- a/src/v0/destinations/ga4/transform.js +++ b/src/v0/destinations/ga4/transform.js @@ -10,7 +10,8 @@ const { removeUndefinedAndNullValues, isDefinedAndNotNull, getFieldValueFromMessage, - getIntegrationsObj + getIntegrationsObj, + isHybridModeEnabled } = require("../../util"); const { InstrumentationError, @@ -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) { diff --git a/src/v0/util/index.js b/src/v0/util/index.js index cf61587d80f..25c909d091b 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -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 // ======================================================================== @@ -1874,5 +1884,6 @@ module.exports = { refinePayload, validateEmail, validatePhoneWithCountryCode, - getEventReqMetadata + getEventReqMetadata, + isHybridModeEnabled };