|
80 | 80 |
|
81 | 81 | @section bottomScripts { |
82 | 82 | <script type="text/javascript"> |
| 83 | + // Used to track how long the user waited before clicking a search selection. |
| 84 | + var pageLoadTime = Date.now(); |
83 | 85 |
|
| 86 | + // Used to track how many selections were made on this page. Multiple selections can happen if the user opens |
| 87 | + // a search selection in a new tab, instead of navigating away from this page. |
| 88 | + var sincePageLoadCount = 0; |
84 | 89 | @if (!string.IsNullOrWhiteSpace(Model.SearchTerm) && (Model.PageIndex == 0 || Model.Items.Count() > 0)) |
85 | 90 | { |
86 | 91 | var action = Model.IncludePrerelease ? "search-prerel" : "search-stable"; |
87 | 92 | // Emit an event representing the search page and the page index. This make it easier for the search selection |
88 | 93 | // event to be correlated in Google Analytics. |
89 | 94 | <text> |
90 | 95 | window.nuget.sendAnalyticsEvent('search-page', '@action', @Html.Raw(Json.Encode(Model.SearchTerm)), @Model.PageIndex); |
| 96 | + window.nuget.sendAiMetric('BrowserSearchPage', @Model.PageIndex, { |
| 97 | + SearchTerm: @Html.Raw(Json.Encode(Model.SearchTerm)), |
| 98 | + IncludePrerelease: '@Model.IncludePrerelease', |
| 99 | + PageIndex: @Model.PageIndex, |
| 100 | + TotalCount: @Model.TotalCount |
| 101 | + }); |
91 | 102 | </text> |
92 | 103 | } |
93 | 104 |
|
|
111 | 122 | queryString |
112 | 123 | ].join(''); |
113 | 124 | window.location.href = url; |
114 | | - }) |
| 125 | + }); |
| 126 | +
|
| 127 | + var emitAiClickEvent = function () { |
| 128 | + if (!window.nuget.isAiAvailable()) { |
| 129 | + return; |
| 130 | + } |
| 131 | +
|
| 132 | + var $this = $(this); |
| 133 | + var data = $this.data(); |
| 134 | + if ($this.attr('href') && data.track) { |
| 135 | + window.nuget.sendAiMetric('BrowserSearchSelection', data.trackValue, { |
| 136 | + SearchTerm: @Html.Raw(Json.Encode(Model.SearchTerm)), |
| 137 | + IncludePrerelease: '@Model.IncludePrerelease', |
| 138 | + PageIndex: @Model.PageIndex, |
| 139 | + TotalCount: @Model.TotalCount, |
| 140 | + ClickIndex: data.trackValue, |
| 141 | + PackageId: data.packageId, |
| 142 | + PackageVersion: data.packageVersion, |
| 143 | + UseVersion: data.useVersion, |
| 144 | + SincePageLoadMs: Date.now() - pageLoadTime, |
| 145 | + SincePageLoadCount: sincePageLoadCount |
| 146 | + }); |
| 147 | +
|
| 148 | + sincePageLoadCount++; |
| 149 | + } |
| 150 | + }; |
| 151 | + $.each($('a[data-track]'), function () { |
| 152 | + $(this).mouseup(function (e) { |
| 153 | + if (e.which === 2) { // Middle-mouse click |
| 154 | + emitAiClickEvent.call(this, e); |
| 155 | + } |
| 156 | + }); |
| 157 | + $(this).click(function (e) { |
| 158 | + emitAiClickEvent.call(this, e); |
| 159 | + }); |
| 160 | + }); |
115 | 161 | }); |
116 | 162 | </script> |
117 | 163 | } |
0 commit comments