From 7a25d89931de753ec7faf3839cfeb007d9a7d1c4 Mon Sep 17 00:00:00 2001 From: Nan Jiang Date: Thu, 4 Aug 2016 14:55:20 -0400 Subject: [PATCH] fix (addon): #1034 Fix event ping to include experiment data only if necessary --- content-src/components/LinkMenu/LinkMenu.js | 6 ++++-- content-src/components/Spotlight/Spotlight.js | 11 +++++++---- content-test/components/Spotlight.test.js | 4 ++-- lib/RecommendationProvider.js | 15 ++++++++------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/content-src/components/LinkMenu/LinkMenu.js b/content-src/components/LinkMenu/LinkMenu.js index b083b0307..1bbab0dff 100644 --- a/content-src/components/LinkMenu/LinkMenu.js +++ b/content-src/components/LinkMenu/LinkMenu.js @@ -21,9 +21,11 @@ const LinkMenu = React.createClass({ page: page, source: source, action_position: index, - url: site.recommended ? site.url : null, - recommender_type: site.recommended ? site.recommender_type : null }; + if (site.recommended) { + payload.url = site.url; + payload.recommender_type = site.recommender_type; + } dispatch(actions.NotifyEvent(payload)); } }, diff --git a/content-src/components/Spotlight/Spotlight.js b/content-src/components/Spotlight/Spotlight.js index b571ca448..dc3eda8ce 100644 --- a/content-src/components/Spotlight/Spotlight.js +++ b/content-src/components/Spotlight/Spotlight.js @@ -99,15 +99,18 @@ const Spotlight = React.createClass({ }, onClickFactory(index, site) { return () => { - this.props.dispatch(actions.NotifyEvent({ + let payload = { event: "CLICK", page: this.props.page, source: "FEATURED", action_position: index, highlight_type: site.type, - url: site.recommended ? site.url : null, - recommender_type: site.recommended ? site.recommender_type : null - })); + }; + if (site.recommended) { + payload.url = site.url; + payload.recommender_type = site.recommender_type; + } + this.props.dispatch(actions.NotifyEvent(payload)); if (site.recommended) { this.props.dispatch(actions.NotifyBlockRecommendation(site.url)); } diff --git a/content-test/components/Spotlight.test.js b/content-test/components/Spotlight.test.js index b2aea94c5..39c0c119f 100644 --- a/content-test/components/Spotlight.test.js +++ b/content-test/components/Spotlight.test.js @@ -42,8 +42,8 @@ describe("Spotlight", function() { assert.equal(a.data.source, "FEATURED"); assert.equal(a.data.action_position, 0); assert.equal(a.data.highlight_type, fakeSpotlightItems[0].type); - assert.equal(a.data.url, null); - assert.equal(a.data.recommender_type, null); + assert.equal(a.data.url, undefined); + assert.equal(a.data.recommender_type, undefined); done(); } } diff --git a/lib/RecommendationProvider.js b/lib/RecommendationProvider.js index ec2ef7314..662788993 100644 --- a/lib/RecommendationProvider.js +++ b/lib/RecommendationProvider.js @@ -48,13 +48,14 @@ RecommendationProvider.prototype = { * Handle the NEW_RECOMMENDATION event */ _handleNewRecommendationEvent(currentRecommendation) { - let url = currentRecommendation ? currentRecommendation.url : null; - let recommenderType = currentRecommendation ? currentRecommendation.recommender_type : null; - this._tabTracker.handleUserEvent({ - event: "NEW_RECOMMENDATION", - url: url, - recommender_type: recommenderType - }); + if (currentRecommendation && currentRecommendation.url && + currentRecommendation.recommender_type) { + this._tabTracker.handleUserEvent({ + event: "NEW_RECOMMENDATION", + url: currentRecommendation.url, + recommender_type: currentRecommendation.recommender_type + }); + } }, /**