Skip to content

Commit

Permalink
fix: Prevent unmapped events from being forwarded (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 authored Nov 1, 2021
1 parent 957b339 commit be274f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
32 changes: 17 additions & 15 deletions src/GoogleAdWordsEventForwarder.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,23 @@
var conversionLabel = getConversionLabel(event);
var customProps = getCustomProps(event);

// Determines the proper event to fire
if (event.EventDataType == MessageType.PageView || event.EventDataType == MessageType.PageEvent) {
eventPayload = generateEventFunction(event, conversionLabel, customProps);
} else if (event.EventDataType == MessageType.Commerce && event.ProductAction) {
eventPayload = generateCommerceEvent(event, conversionLabel, customProps);
}

if (eventPayload) {
reportEvent = sendEventFunction(eventPayload);
}

if (reportEvent && reportingService) {
reportingService(self, event);

return 'Successfully sent to ' + name;
if (conversionLabel) {
// Determines the proper event to fire
if (event.EventDataType == MessageType.PageView || event.EventDataType == MessageType.PageEvent) {
eventPayload = generateEventFunction(event, conversionLabel, customProps);
} else if (event.EventDataType == MessageType.Commerce && event.ProductAction) {
eventPayload = generateCommerceEvent(event, conversionLabel, customProps);
}

if (eventPayload) {
reportEvent = sendEventFunction(eventPayload);
}

if (reportEvent && reportingService) {
reportingService(self, event);

return 'Successfully sent to ' + name;
}
}

return 'Can\'t send to forwarder: ' + name + '. Event not mapped';
Expand Down
10 changes: 4 additions & 6 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ describe('Adwords forwarder', function () {
it('should not forward unmapped events', function (done) {
var failMessage = mParticle.forwarder.process({
EventName: 'Something random',
EventDataType: MessageType.Commerce,
EventDataType: MessageType.PageEvent,
EventAttributes: {
showcase: 'something'
}
showcase: 'something',
},
});

failMessage.should.not.be.null();
Expand Down Expand Up @@ -735,14 +735,12 @@ describe('Adwords forwarder', function () {
it('should not forward unmapped events', function (done) {
var failMessage = mParticle.forwarder.process({
EventName: 'Something random',
EventDataType: MessageType.Commerce,
EventDataType: MessageType.PageEvent,
EventAttributes: {
showcase: 'something'
}
});

// debugger;

failMessage.should.not.be.null();
failMessage.should.be.containEql("Can't send to forwarder")
window.dataLayer.length.should.eql(0)
Expand Down

0 comments on commit be274f7

Please sign in to comment.