Skip to content

Commit

Permalink
fix: Prevent attribute cleansing when data cleansing is disabled (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 authored Sep 11, 2023
1 parent b7dfef8 commit 9847bf8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
6 changes: 1 addition & 5 deletions packages/GA4Client/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ Common.prototype.truncateAttributes = function (

if (!isEmpty(attributes)) {
Object.keys(attributes).forEach(function (attribute) {
var standardizedKey = attribute.replace(
FORBIDDEN_CHARACTERS_REGEX,
'_'
);
var key = truncateString(standardizedKey, keyLimit);
var key = truncateString(attribute, keyLimit);
var val = truncateString(attributes[attribute], valueLimit);
truncatedAttributes[key] = val;
});
Expand Down
23 changes: 23 additions & 0 deletions packages/GA4Client/test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,29 @@ describe('Google Analytics 4 Event', function () {
done();
});

it('should not standardize event names and event attributes if data cleansing is not enabled', function (done) {
mParticle.forwarder.process({
EventDataType: MessageType.PageEvent,
EventCategory: EventType.Navigation,
EventName: '2?Test Event ?Standardization',
EventAttributes: {
foo: 'bar',
'1?test4ever!!!': 'tester',
},
});

var expectedEventName = '2?Test Event ?Standardization';

var expectedEventAttributes = {
foo: 'bar',
'1?test4ever!!!': 'tester',
};

window.dataLayer[0][1].should.eql(expectedEventName);
window.dataLayer[0][2].should.eql(expectedEventAttributes);
done();
});

// This test exist for backwards compatibility of custom flags carried
// over from legacy Google Analytics - Google.Title and Google.Location
it('should log page view with legacy GA custom flags', function (done) {
Expand Down

0 comments on commit 9847bf8

Please sign in to comment.