diff --git a/src/GoogleAdWordsEventForwarder.js b/src/GoogleAdWordsEventForwarder.js index 114918e..9c7fa28 100644 --- a/src/GoogleAdWordsEventForwarder.js +++ b/src/GoogleAdWordsEventForwarder.js @@ -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'; diff --git a/test/tests.js b/test/tests.js index be218a0..ac40a4e 100644 --- a/test/tests.js +++ b/test/tests.js @@ -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(); @@ -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)