|
3891 | 3891 | same(this.requests.length, 0, "autocapture init with pageview=false should not fire request on load");
|
3892 | 3892 | });
|
3893 | 3893 |
|
3894 |
| - test("autocapture tracks click events", 4, function() { |
| 3894 | + test("autocapture tracks click events", 5, function() { |
3895 | 3895 | mixpanel.init("autocapture_test_token", {
|
3896 | 3896 | autocapture: {
|
3897 | 3897 | pageview: false,
|
|
3912 | 3912 | same(this.requests.length, 1, "click event should fire request");
|
3913 | 3913 | var last_event = getRequestData(this.requests[0]);
|
3914 | 3914 | same(last_event.event, "$mp_click", "last request should be $mp_click event");
|
| 3915 | + same(last_event.properties.$captured_for_heatmap, false, "click event should not be tagged as captured for heatmap"); |
3915 | 3916 | ok(originalHandlerCalled, "original click handler should also have been called");
|
3916 | 3917 | });
|
3917 | 3918 |
|
|
6184 | 6185 | this.randomStub = sinon.stub(Math, 'random');
|
6185 | 6186 | this.fetchStub = sinon.stub(window, 'fetch');
|
6186 | 6187 |
|
| 6188 | + if (USE_XHR) { |
| 6189 | + this.xhr = sinon.useFakeXMLHttpRequest(); |
| 6190 | + this.requests = []; |
| 6191 | + this.xhr.onCreate = _.bind(function(req) { |
| 6192 | + this.requests.push(req); |
| 6193 | + }, this); |
| 6194 | + } |
| 6195 | + |
6187 | 6196 | // realistic successful response
|
6188 | 6197 | this.fetchStub.returns(Promise.resolve(new Response(JSON.stringify({code: 200, status: 'OK'}), {
|
6189 | 6198 | status: 200,
|
|
6324 | 6333 | this.responseBlobStub.restore();
|
6325 | 6334 | }
|
6326 | 6335 |
|
| 6336 | + if (USE_XHR) { |
| 6337 | + this.xhr.restore(); |
| 6338 | + } |
| 6339 | + |
6327 | 6340 | var scriptEl = this.getRecorderScript();
|
6328 | 6341 | if (scriptEl) {
|
6329 | 6342 | scriptEl.parentNode.removeChild(scriptEl);
|
|
6547 | 6560 | }, this))
|
6548 | 6561 | });
|
6549 | 6562 |
|
| 6563 | + if (USE_XHR) { |
| 6564 | + asyncTest('does not track clicks when using recording and capturing heat map data is off', function () { |
| 6565 | + this.randomStub.returns(0.02); |
| 6566 | + this.initMixpanelRecorder({record_sessions_percent: 100, record_heatmap_data: false, batch_requests: false}); |
| 6567 | + this.waitForRecorderLoad() |
| 6568 | + .then(_.bind(function () { |
| 6569 | + var e1 = ele_with_class(); |
| 6570 | + var originalHandlerCalled = false; |
| 6571 | + e1.e.onclick = function() { |
| 6572 | + originalHandlerCalled = true; |
| 6573 | + return false; |
| 6574 | + } |
| 6575 | + |
| 6576 | + simulateMouseClick(e1.e); |
| 6577 | + |
| 6578 | + same(this.requests.length, 0, "click event should not fire request"); |
| 6579 | + ok(originalHandlerCalled, "original click handler should also have been called"); |
| 6580 | + }, this)) |
| 6581 | + .then(start) |
| 6582 | + }); |
| 6583 | + |
| 6584 | + asyncTest('tracks clicks when using recording and capturing capturing heat map data is on', function () { |
| 6585 | + this.randomStub.returns(0.02); |
| 6586 | + this.initMixpanelRecorder({record_sessions_percent: 100, record_heatmap_data: true, batch_requests: false}); |
| 6587 | + this.waitForRecorderLoad() |
| 6588 | + .then(_.bind(function () { |
| 6589 | + var e1 = ele_with_class(); |
| 6590 | + var originalHandlerCalled = false; |
| 6591 | + e1.e.onclick = function() { |
| 6592 | + originalHandlerCalled = true; |
| 6593 | + return false; |
| 6594 | + } |
| 6595 | + |
| 6596 | + simulateMouseClick(e1.e); |
| 6597 | + |
| 6598 | + same(this.requests.length, 1, "click event should fire request"); |
| 6599 | + var last_event = getRequestData(this.requests[0]); |
| 6600 | + same(last_event.event, "$mp_click", "last request should be $mp_click event"); |
| 6601 | + same(last_event.properties.$captured_for_heatmap, true, "last request should be tagged as captured for heat map"); |
| 6602 | + ok(originalHandlerCalled, "original click handler should also have been called"); |
| 6603 | + }, this)) |
| 6604 | + .then(start) |
| 6605 | + }); |
| 6606 | + } |
| 6607 | + |
6550 | 6608 | test('respects tracking opt-out when sampled', 3, function () {
|
6551 | 6609 | this.randomStub.returns(0.02);
|
6552 | 6610 | this.initMixpanelRecorder({record_sessions_percent: 10, window: {navigator: {doNotTrack: '1'}}});
|
|
0 commit comments