Created
May 3, 2018 16:01
-
-
Save thechriskent/085e609a5b8b4791f580c91f9e7c1cb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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