|
406 | 406 | if (window.nuget.isGaAvailable()) { |
407 | 407 | ga('send', 'event', category, action, label, eventValue, options); |
408 | 408 | } |
409 | | - } |
| 409 | + }; |
410 | 410 |
|
411 | 411 | window.nuget = nuget; |
412 | 412 |
|
|
447 | 447 | .focus(); |
448 | 448 |
|
449 | 449 | // Handle Google analytics tracking event on specific links. |
| 450 | + var emitClickEvent = function (e, emitDirectly) { |
| 451 | + if (!window.nuget.isGaAvailable()) { |
| 452 | + return; |
| 453 | + } |
| 454 | + |
| 455 | + var href = $(this).attr('href'); |
| 456 | + var category = $(this).data().track; |
| 457 | + var trackValue = $(this).data().trackValue; |
| 458 | + if (href && category) { |
| 459 | + if (emitDirectly) { |
| 460 | + window.nuget.sendAnalyticsEvent(category, 'click', href, trackValue); |
| 461 | + } else { |
| 462 | + // This path is used when the click will result in a page transition. Because of this we need to |
| 463 | + // emit telemetry in a special way so that the event gets out before the page transition occurs. |
| 464 | + e.preventDefault(); |
| 465 | + window.nuget.sendAnalyticsEvent(category, 'click', href, trackValue, { |
| 466 | + 'transport': 'beacon', |
| 467 | + 'hitCallback': window.nuget.createFunctionWithTimeout(function () { |
| 468 | + document.location = href; |
| 469 | + }) |
| 470 | + }); |
| 471 | + } |
| 472 | + } |
| 473 | + }; |
450 | 474 | $.each($('a[data-track]'), function () { |
451 | | - $(this).click(function (e) { |
452 | | - var href = $(this).attr('href'); |
453 | | - var category = $(this).data().track; |
454 | | - var trackValue = $(this).data().trackValue; |
455 | | - if (window.nuget.isGaAvailable() && href && category) { |
456 | | - if (e.altKey || e.ctrlKey || e.metaKey) { |
457 | | - window.nuget.sendAnalyticsEvent(category, 'click', href, trackValue); |
458 | | - } else { |
459 | | - e.preventDefault(); |
460 | | - window.nuget.sendAnalyticsEvent(category, 'click', href, trackValue, { |
461 | | - 'transport': 'beacon', |
462 | | - 'hitCallback': window.nuget.createFunctionWithTimeout(function () { |
463 | | - document.location = href; |
464 | | - }) |
465 | | - }); |
466 | | - } |
| 475 | + $(this).mouseup(function (e) { |
| 476 | + if (e.which === 2) { // Middle-mouse click |
| 477 | + emitClickEvent.call(this, e, true); |
467 | 478 | } |
468 | 479 | }); |
| 480 | + $(this).click(function (e) { |
| 481 | + emitClickEvent.call(this, e, e.altKey || e.ctrlKey || e.metaKey); |
| 482 | + }); |
469 | 483 | }); |
470 | 484 |
|
471 | 485 | // Show elements that require ClickOnce |
|
0 commit comments