Skip to content

Commit 31496c4

Browse files
committed
[GH Usage] Updated analytics click link index
1 parent 80cbd3f commit 31496c4

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

src/NuGetGallery/Scripts/gallery/page-display-package.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,13 @@ $(function () {
119119
});
120120

121121
// Emit a Google Analytics event when the user clicks on a repo link in the GitHub Usage section.
122-
$(".btn-gh-repo").on('click', function (e) {
123-
let elem = e.delegateTarget.parentElement.parentElement;
124-
let linkIndex = 0;
125-
while ((elem = elem.previousSibling) != null) {
126-
if (elem.nodeName === "DIV") {
127-
linkIndex++;
128-
}
122+
$(".btn-gh-repo").on('click', function (elem) {
123+
if (!elem.delegateTarget.dataset.indexNumber) {
124+
console.error("indexNumber property doesn't exist!");
125+
} else {
126+
let linkIndex = elem.delegateTarget.dataset.indexNumber;
127+
ga('send', 'event', 'github-usage', 'link-click-' + linkIndex);
129128
}
130-
131-
ga('send', 'event', 'github-usage', 'link-click-' + linkIndex);
132129
});
133130
}
134131
});

src/NuGetGallery/Views/Packages/DisplayPackage.cshtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,16 +535,16 @@
535535
@(Model.Id), including the following:
536536
</p>
537537

538-
@foreach (var dep in Model.GitHubDependenciesInformation.Repos)
538+
@foreach (var item in Model.GitHubDependenciesInformation.Repos.Select((elem, i) => new { Value = elem, Idx = i}))
539539
{
540540
<div class="row top-buffer">
541541
<div class="col-xs-12">
542-
<a class="btn btn-gh-repo text-left" href="@dep.Url" target="_blank">
542+
<a data-index-number="@item.Idx" class="btn btn-gh-repo text-left" href="@item.Value.Url" target="_blank">
543543
<span class="pull-left">
544-
@(dep.Id)
544+
@(item.Value.Id)
545545
</span>
546546
<span class="badge pull-right badge-gh-repo">
547-
@(dep.Stars.ToKiloFormat()) <i class="ms-Icon ms-Icon--FavoriteStarFill star-gh-repo" aria-hidden="true"></i>
547+
@(item.Value.Stars.ToKiloFormat()) <i class="ms-Icon ms-Icon--FavoriteStarFill star-gh-repo" aria-hidden="true"></i>
548548
</span>
549549
</a>
550550
</div>

0 commit comments

Comments
 (0)