Unverified Commit bf4c06c2 authored by Lyza Gardner's avatar Lyza Gardner Committed by GitHub

Merge pull request #1568 from hypothesis/fix-sharing-events

Fix click callback in `ShareLinks` to not track analytics events until clicked
parents 2db37db8 dccf9876
...@@ -12,7 +12,9 @@ const SvgIcon = require('./svg-icon'); ...@@ -12,7 +12,9 @@ const SvgIcon = require('./svg-icon');
*/ */
function ShareLinks({ analytics, analyticsEventName, shareURI }) { function ShareLinks({ analytics, analyticsEventName, shareURI }) {
const trackShareClick = shareTarget => { const trackShareClick = shareTarget => {
analytics.track(analyticsEventName, shareTarget); return () => {
analytics.track(analyticsEventName, shareTarget);
};
}; };
// This is the double-encoded format needed for other services (the entire // This is the double-encoded format needed for other services (the entire
......
...@@ -57,9 +57,16 @@ describe('ShareLinks', () => { ...@@ -57,9 +57,16 @@ describe('ShareLinks', () => {
const wrapper = createComponent({ shareURI: shareLink }); const wrapper = createComponent({ shareURI: shareLink });
const link = wrapper.find(`a[title="${testCase.title}"]`); const link = wrapper.find(`a[title="${testCase.title}"]`);
link.simulate('click');
assert.equal(link.prop('href'), testCase.expectedURI); assert.equal(link.prop('href'), testCase.expectedURI);
// Assure tracking doesn't happen until clicked
// See https://github.com/hypothesis/client/issues/1566
assert.notCalled(fakeAnalytics.track);
// Now click...
link.simulate('click');
assert.calledWith( assert.calledWith(
fakeAnalytics.track, fakeAnalytics.track,
'potato-peeling', 'potato-peeling',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment