diff --git a/src/v0/destinations/mp/util.js b/src/v0/destinations/mp/util.js index d9b8f11dca..30173fd514 100644 --- a/src/v0/destinations/mp/util.js +++ b/src/v0/destinations/mp/util.js @@ -12,6 +12,7 @@ const { getSuccessRespEvents, defaultBatchRequestConfig, IsGzipSupported, + isObject, } = require('../../util'); const { ConfigCategory, @@ -189,7 +190,7 @@ const removeDuplicateMetadata = (mergedBatches) => { */ const buildUtmParams = (campaign) => { const utmParams = {}; - if (campaign) { + if (isObject(campaign)) { Object.keys(campaign).forEach((key) => { if (key === 'name') { utmParams.utm_campaign = campaign[key]; diff --git a/src/v0/destinations/mp/util.test.js b/src/v0/destinations/mp/util.test.js index db39a250dc..6d5b24766d 100644 --- a/src/v0/destinations/mp/util.test.js +++ b/src/v0/destinations/mp/util.test.js @@ -585,6 +585,12 @@ describe('Mixpanel utils test', () => { expect(result).toEqual({}); }); + it('should return an empty object when campaign is not an object', () => { + const campaign = [{ name: 'test' }]; + const result = buildUtmParams(campaign); + expect(result).toEqual({}); + }); + it('should handle campaign object with null/undefined values', () => { const campaign = { name: null, source: 'rudder', medium: 'rudder', test: undefined }; const result = buildUtmParams(campaign);