Upload
akihiro-ehara
View
731
Download
2
Embed Size (px)
Citation preview
GoogleアナリティクスでSharePointの利用状況を確認する
2016年5月
SharePoint Onlineカスタマイズ
今回のお題
SharePoint Onlineの利用状況をGoogleアナリティクスで解析する
利用する仕組み
•UserCustomActions
•すべてのページにJavascriptを埋め込める
•GoogleアナリティクスのJavascriptをこれで組み込む
Hackingには超便利な手法!
JavaScriptの埋め込み
Powershellで簡単に埋め込める
• Activate Google Analytics in SharePoint Online site
https://gist.github.com/vgrem/2884bdad94d450e0f869
埋め込みスクリプト
(function (i, s, o, g, r, a, m) {i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {(i[r].q = i[r].q || []).push(arguments)}, i[r].l = 1 * new Date(); a = s.createElement(o),m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g;
m.parentNode.insertBefore(a, m)})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-4XXXXXXXX9-5', 'auto');ga('send', 'pageview');
Googleのアナリティクスポータルで取得可能
埋め込みスクリプトの改造①
• SharePoint OnlineのURLはこんな感じ
https://yoursite.sharepoint.com/_layouts/15/start.aspx#/Demo/Forms/AllItems.aspx
• Googleアナリティクスの既定のスクリプトではハッシュ(#)以降が無視される
https://yoursite.sharepoint.com/_layouts/15/start.aspx
リストなどの重要な情報がなくなってしまう
• ハッシュ(#)以降も記録するためには少し変更ga('send', 'pageview');
↓
ga('send', 'pageview', {
'page': location.pathname + location.search + location.hash});
埋め込みスクリプトの改造②
• 標準ではどのユーザーのアクセスかは分析できない(注意) Googleアナリティクスでは個人情報を収集することは禁止している。今回は内部的なIDを利用することで回避しているはず
• カスタムディメンションを使うと特別な情報を追加できる
• SharePoint内部のIDをカスタムディメンションに設定
var uid = currentUser.get_userId().get_nameId();ga('set', 'dimension1', uid);
最終的な埋め込みコード
(function () {this.send = function () {
if (!SP.ClientContext) {setTimeout(this.send, 100);return;
}(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
var ctx = new SP.ClientContext.get_current();var website = ctx.get_web();var currentUser = website.get_currentUser();ctx.load(currentUser);ctx.executeQueryAsync(function () {
var uid = currentUser.get_userId().get_nameId();ga('create', 'UA-XXXXXXX-5', { 'userId': uid });ga('set', 'dimension1', uid);ga('send', 'pageview', {
'page': location.pathname + location.search + location.hash});
},function () {
ga('create', 'UA-XXXXXXX-5', 'auto');ga('send', 'pageview', {
'page': location.pathname + location.search + location.hash});
});}setTimeout(this.send, 0);
})();
ちょっと長いがSP.ClientContextはすぐに
利用可能にならないようなのでsetTimeoutで調整
Googleアナリティクスで収集されたデータ
URLとユーザの情報は収集できているただ直接ダウンロードされるドキュメントのログは収集できない
社内の情報がGoogleに送信されるのは…
• 社内の情報がGoogleに送信されるのが抵抗のある場合の選択肢
• Piwik(オープンソース)AzureのMarketplaceにもイメージがあるので簡単に利用可能
• 独自に作成Azure Storageなどを使えば収集は簡単PowerBIで表示するなども考えられる
• Publicサイトはともかく、そもそもGoogleアナリティクスをイントラのシステムで利用してよいのか?
まとめ
• SharePoint Onlineの利用状況をGoogleアナリティクスやPiwikで分析することは可能
• 利用概要を見るレベルであれば十分利用可能
• Public以外の社内サイトでも技術的には利用可能
• UserCustomActionsの仕組みを利用してトラッキング用のJavascriptを埋め込む
• Javascriptベースの仕組みでは直接ダウンロードするログは収集できない課題が残る
http://www.proaxia-consulting.co.jp
Azure&SharePointアプリケーション開発についてのお問合せ[担当] [email protected]
SharePoint Onlineとファイルサーバーを統合するCloud Storage Lighthttps://www.cloudstoragelight.com
SharePoint 上のファイルをエクスプローラ感覚でサクサク操作するSharePointエクスプローラhttps://www.cloudstoragelight.com/sharepointexplorer/