diff --git a/src/utils/logger.js b/src/utils/logger.js index afdb545bae..76185be72b 100644 --- a/src/utils/logger.js +++ b/src/utils/logger.js @@ -8,7 +8,7 @@ import { ZalgoPromise } from '@krakenjs/zalgo-promise/src'; import { getGlobalUrl } from './global'; import { request } from './miscellaneous'; -import { getLibraryVersion, getDisableSetCookie } from './sdk'; +import { getLibraryVersion, getDisableSetCookie, getClientId } from './sdk'; function generateLogPayload(account, { meta, events: bizEvents, tracking }) { const { deviceID, sessionID, integration_type, messaging_version } = meta.global ?? {}; @@ -173,6 +173,18 @@ export const logger = Logger({ ? `${url}?disableSetCookie=true&features=disable-set-cookie` : url; + // Send authorization header with tracking event + if (__MESSAGES__.__TARGET__ === 'SDK') { + const encodedClientId = btoa(getClientId()); + // eslint-disable-next-line no-param-reassign + headers.Authorization = `Basic ${encodedClientId}`; + } + if (__MESSAGES__.__TARGET__ === 'STANDALONE' || __MESSAGES__.__TARGET__ === 'STANDALONE_MODAL') { + const encodedPayerId = btoa(trimmedMeta['1'].account); + // eslint-disable-next-line no-param-reassign + headers.Authorization = `Basic ${encodedPayerId}`; + } + return ZalgoPromise.all( translateLogData(trimmedLog).map(data => { return request(method, urlWithCookieParams, { diff --git a/src/utils/sdk.js b/src/utils/sdk.js index 4f798167c3..0de2ca1796 100644 --- a/src/utils/sdk.js +++ b/src/utils/sdk.js @@ -71,6 +71,15 @@ export function getAccount() { return undefined; } } + +export function getClientId() { + if (__MESSAGES__.__TARGET__ === 'SDK') { + return getClientID(); + } else { + return undefined; + } +} + export function getPageType() { if (__MESSAGES__.__TARGET__ === 'SDK') { return getSDKPageType();