Skip to content

Commit 910c735

Browse files
authored
Merge pull request #7263 from NuGet/mogah-gh-usage-analytics
[GH Usage] Added analytics
2 parents 86a909e + 005e2ba commit 910c735

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,25 @@ $(function () {
105105
});
106106
}
107107

108-
// Emit a Google Analytics event when the user expands or collapses the Dependencies section.
109108
if (window.nuget.isGaAvailable()) {
109+
// Emit a Google Analytics event when the user expands or collapses the Dependencies section.
110110
$("#dependency-groups").on('hide.bs.collapse show.bs.collapse', function (e) {
111111
ga('send', 'event', 'dependencies', e.type);
112112
});
113+
114+
// Emit a Google Analytics event when the user expands or collapses the GitHub Usage section.
115+
$("#github-usage").on('hide.bs.collapse show.bs.collapse', function (e) {
116+
ga('send', 'event', 'github-usage', e.type);
117+
});
118+
119+
// Emit a Google Analytics event when the user clicks on a repo link in the GitHub Usage section.
120+
$(".btn-gh-repo").on('click', function (elem) {
121+
if (!elem.delegateTarget.dataset.indexNumber) {
122+
console.error("indexNumber property doesn't exist!");
123+
} else {
124+
let linkIndex = elem.delegateTarget.dataset.indexNumber;
125+
ga('send', 'event', 'github-usage', 'link-click-' + linkIndex);
126+
}
127+
});
113128
}
114129
});

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)