Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function logItemUsage(itemId, listName) {
SP.SOD.executeOrDelayUntilScriptLoaded(function() {
var stuff = {
ctx: SP.ClientContext.get_current()
};
stuff.user = stuff.ctx.get_web().get_currentUser();
stuff.ctx.load(stuff.user);
stuff.scope = "{00000000-0000-0000-0000-000000000000}";
stuff.site = stuff.ctx.get_site();
stuff.ctx.load(stuff.site);
this.stuff.ctx.executeQueryAsync(
function () {
stuff.siteId = stuff.site.get_id();
var itemUrl = _spPageContextInfo.webAbsoluteUrl + "/Lists/" + listName + "/DispForm.aspx?ID=" + itemId;
SP.Analytics.AnalyticsUsageEntry.logAnalyticsEvent2(
stuff.ctx,
1,
itemUrl,
stuff.scope,
stuff.siteId,
stuff.user
);
stuff.ctx.executeQueryAsync(
function() {
console.log("Logged: " + itemUrl);
}, function (s, a) {
console.log(a.get_message());
}
}, function (s, a) {
console.log(a.get_message());
}
);
}, "SP.js");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.