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');
*/
function ShareLinks({ analytics, analyticsEventName, shareURI }) {
const trackShareClick = shareTarget => {
analytics.track(analyticsEventName, shareTarget);
return () => {
analytics.track(analyticsEventName, shareTarget);
};
};
// This is the double-encoded format needed for other services (the entire
......
......@@ -57,9 +57,16 @@ describe('ShareLinks', () => {
const wrapper = createComponent({ shareURI: shareLink });
const link = wrapper.find(`a[title="${testCase.title}"]`);
link.simulate('click');
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(
fakeAnalytics.track,
'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