在 SharePoint Server 中設定建議和流量事件類型Configure recommendations and usage event types in SharePoint Server

流量事件可讓您追蹤您的網站上的項目與使用者互動的方式。項目可以是文件、 網站或目錄項目。當使用者與其互動網站上的項目時、 SharePoint Server 就會產生此動作的流量事件。例如,如果您想要監視的目錄項目檢視從行動電話的頻率,您可以追蹤此活動。Usage events enable you to track how users interact with items on your site. Items can be documents, sites, or catalog items. When a user interacts with an item on your site, SharePoint Server generates a usage event for this action. For example, if you want to monitor how often a catalog item is viewed from a mobile phone, you can track this activity.

本文說明如何建立自訂使用事件類型,以及如何新增程式碼來記錄自訂使用事件,如此就能透過分析處理元件來處理它們。This article describes how to create custom usage event types, and how to add code to record custom usage events so that they can be processed by the analytics processing component.

您可以使用您的網站上顯示的建議或常用項目的流量事件所產生的資料。本文也會說明如何影響建議以變更特定的使用事件類型的重要性層級顯示的方式。如需詳細資訊,請參閱中規劃 SharePoint Server 2016 跨網站發佈網站的搜尋的 「 規劃流量分析、 流量事件及建議"。You can use the data that is generated by usage events to show recommendations or popular items on your site. This article also explains how to influence how recommendations are shown by changing the level of importance for a specific usage event type. For more information, see "Plan usage analytics, usage events and recommendations" in Plan search for cross-site publishing sites in SharePoint Server 2016.

您可以在 「 常用性趨勢 」 和 「 最常用項目報告中檢視所有流量事件類型的統計資料。如需詳細資訊,請參閱 < SharePoint Server 中的檢視使用情形報告You can view the statistics for all usage event types in Popularity Trends and Most Popular Items reports. For more information, see View usage reports in SharePoint Server.

建立自訂使用事件類型Create a custom usage event type

在 SharePoint Server 中有三個預設使用事件類型。您可以使用 Microsoft PowerShell 建立多達十二個自訂使用事件類型。There are three default usage event types in SharePoint Server. You can create up to twelve custom usage event types by using Microsoft PowerShell.

若要建立自訂使用事件類型To create a custom usage event type

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 請以高於上述基本要求新增必要的成員資格。Add memberships that are required beyond the minimums above.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    # To get a site at the root site collection level:
    $Site = Get-SPSite "http://localhost"
    # To get a site below the root site collection level:
    $Site = Get-SPSite "http://localhost/sites/<SiteName>"
    # To create a custom usage event type:
    $SSP = Get-SPEnterpriseSearchServiceApplicationProxy
    $EventGuid = [Guid]::NewGuid()
    $EventName = "<EventTypeName>"
    $tenantConfig = $SSP.GetAnalyticsTenantConfiguration([Guid]::Empty)
    $newEventType = $tenantConfig.RegisterEventType($EventGuid, $EventName, "")
    $tenantConfig.Update($SSP)
    

    其中:Where:

    • <SiteName>是您要建立自訂使用事件之網站的名稱。<SiteName> is the name of the site for which you want to create a custom usage event.

    • 是您想要建立之新自訂使用事件類型的名稱-例如BuyEventType is the name of the new custom usage event type that you want to create — for example, BuyEventType .

      此程序可建立使用事件類型的隨機的 GUID。當您新增程式碼來記錄自訂使用事件記錄自訂使用事件中所述時使用這個 GUID。This procedure creates a random GUID for the usage event type. Use this GUID when you add code to record the custom usage event, as described in Record a custom usage event.

      重要

      最多需要三個小時才能讓自訂使用事件類型可在系統中使用。但是,若要加快此程序的速度,您也可以重新啟動 SharePoint 計時器服務。It can take up to three hours for a custom usage event type to become available in the system. However, to speed up the process, you can alternatively restart the SharePoint Timer Service.

注意

[!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

記錄自訂使用事件Record a custom usage event

建立自訂使用事件類型中所述建立自訂使用事件類型之後,您必須將程式碼新增至事件發生的地方 — 例如載入頁面時,或當使用者按一下連結或] 按鈕。然後將此資料傳送至分析處理元件,它會在此記錄及處理。After you have created a custom usage event type, as described in Create a custom usage event type, you have to add code to the place where the event occurs — for example, when a page loads, or when a user clicks a link or a button. This data is then sent to the analytics processing component, where it is recorded and processed.

如果您正在使用跨網站發佈 (您可以在發佈網站上顯示目錄內容),就必須在索引項目的 URL 上記錄使用事件,並覆寫一些網站設定。例如,如果您在已於發佈網站上發佈的製作網站中擁有一個目錄,當使用者與發佈網站上的目錄項目進行互動時,就必須在製作網站中的項目上記錄此使用事件。因此,您新增來記錄使用事件的程式碼必須覆寫發佈網站的 SiteId 和 WebId,並使用製作網站的 SiteId 和 WebId 來取代。If you are using cross-site publishing, where you show catalog content on a publishing site, you must record the usage event on the URL of the indexed item, and override some site settings. For example, if you have a catalog in an authoring site that you have published on a publishing site, when a user interacts with a catalog item on the publishing site, this usage event must be recorded on the item in the authoring site. Furthermore, the code that you add to record the usage event must override the SiteId and the WebId of the publishing site, and be replaced with the SiteId and the WebId of the authoring site.

新增程式碼來記錄自訂使用事件To add code to record a custom usage event

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 請以高於上述基本要求新增必要的成員資格。Add memberships that are required beyond the minimums above.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    # To view GUIDs for all usage event types:
    $SSP = Get-SPEnterpriseSearchServiceApplicationProxy
    $SSP.GetAnalyticsEventTypeDefinitions([Guid]::Empty, 3) | ft
    
  4. 在 HTML 編輯程式中,開啟應記錄自訂使用事件的檔案 (例如,適用於內容搜尋網頁組件的顯示範本),並新增下列程式碼:In an HTML editor, open the file where the custom usage event should be logged — for example, a display template for a Content Search Web Part, and add the following code:

    window.Log<CustomUsageEventType>ToEventStore = function(url)
    {
       ExecuteOrDelayUntilScriptLoaded(function()
       {
           var spClientContext = SP.ClientContext.get_current();
           var eventGuid = new SP.Guid("<GUID>");
           SP.Analytics.AnalyticsUsageEntry.logAnalyticsAppEvent(spClientContext, eventGuid, url);
           spClientContext.executeQueryAsync(null, Function.createDelegate(this, function(sender, e){ alert("Failed to log event for item: " + document.URL + " due to: " + e.get_message()) }));
       }, "SP.js");
    }
    
    • 是自訂事件的名稱-例如BuyEventType is the name of the custom event — for example, BuyEventType .

    • 為使用事件類型的數值識別碼-例如4e605543-63cf-4b5f-aab6-99a10b8fb257 is the numeric ID of the usage event type — for example, 4e605543-63cf-4b5f-aab6-99a10b8fb257 .

  5. 在 HTML 編輯程式中,開啟參考自訂使用事件的檔案,並新增下列程式碼:In an HTML editor, open the file that refers to the custom usage event, and add the following code:

    # The example below shows how a custom usage event type is referred to when a button is clicked: 
    <button onclick="Log<CustomUsageEventType>ToEventStore('<URL>')"></button>
    

    其中:Where:

    • <CustomUsageEventType>是自訂事件類型的名稱。<CustomUsageEventType> is the name of the custom event type.

    • 是應記錄使用事件之項目的完整 URL-例如http://contoso.com/faq is the full URL of the item to which the usage event should be logged — for example, http://contoso.com/faq .

    新增程式碼來記錄自訂使用事件並覆寫網站設定To add code to record a custom usage event and override site settings

  6. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 請以高於上述基本要求新增必要的成員資格。Add memberships that are required beyond the minimums above.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  7. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  8. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    # To view GUIDs for all usage event types:
    $SSP = Get-SPEnterpriseSearchServiceApplicationProxy
    $SSP.GetAnalyticsEventTypeDefinitions([Guid]::Empty, 3) | ft
    
  9. 在 HTML 編輯程式中,開啟應記錄自訂使用事件的檔案 - 例如,適用於內容搜尋網頁組件的顯示範本。下列範例示範如何覆寫目前的 SiteId、WebId 及 UserId。In an HTML editor, open the file where the custom usage event should be logged — for example, a display template for a Content Search Web Part. The following example shows how to override the current SiteId, WebId and UserId.

    window.Log<CustomUsageEventType>ToEventStore = function(url, siteIdGuid, webIdGuid, spUser)
    {
       ExecuteOrDelayUntilScriptLoaded(function()
       {
         var spClientContext = SP.ClientContext.get_current();
         var eventGuid = new SP.Guid("<GUID>");
    SP.Analytics.AnalyticsUsageEntry.logAnalyticsAppEvent2(spClientContext, eventGuid, url, webIdGuid, siteIdGuid, spUser);
         spClientContext.executeQueryAsync(null, Function.createDelegate(this, function(sender, e){ alert("Failed to log event for item: " + document.URL + " due to: " + e.get_message()) }));
       }, "SP.js");
    }
    

    其中:Where:

    • 是自訂事件類型的名稱-例如BuyEventType is the name of the custom event type — for example, BuyEventType .

    • 為使用事件類型的數值識別碼-例如4e605543-63cf-4b5f-aab6-99a10b8fb257 is the numeric ID of the usage event type — for example, 4e605543-63cf-4b5f-aab6-99a10b8fb257 .

  10. 在 HTML 編輯程式中,開啟參考自訂使用事件類型的檔案,並新增下列程式碼:In an HTML editor, open the file that refers to the custom usage event type, and add the following code:

    # The example below shows how a custom usage event type is referred to when the "Buy!" button is clicked:
    <button onclick="Log<CustomUsageEventType>ToEventStore('<URL>', new SP.Guid('{<SiteId GUID>}'), new SP.Guid('{<WebId GUID>}'), '<UserName>')">Buy!</button>
    

    其中:Where:

    • <CustomUsageEventType>是自訂事件類型的名稱-例如 BuyEventType。<CustomUsageEventType> is the name of the custom event type — for example, BuyEventType.

    • <URL>是 managed 屬性 OriginalPath 中找到的 URL。<URL> is the URL found in the managed property OriginalPath.

    • 是製作網站的 SiteId GUID。如需如何取得 SiteId GUID,請參閱取得 SiteId GUID 與 WebId GUID 站台的資訊。 is the SiteId GUID of the authoring site. For information about how to get the SiteId GUID, see Get SiteId GUID and WebId GUID for a site.

    • 已製作網站 WebId GUID。如需如何取得 WebId GUID,請參閱取得 SiteId GUID 與 WebId GUID 站台的資訊。 is the WebId GUID of the authoring site. For information about how to get the WebId GUID, see Get SiteId GUID and WebId GUID for a site.

    • <UserName>可以是用來識別使用者在具有匿名使用者的網站上的 cookie 識別碼。<UserName> can be a cookie ID that is used to identify users on a site that has anonymous users.

記錄預設的使用事件Record a default usage event

如果您想要新增參考預設使用事件類型的程式碼 (例如 [檢視]),就必須將程式碼新增至事件發生的地方。If you want to add code that refers to a default usage event type — for example, views, you have to add code to the place where the event occurs.

如果您正在使用跨網站發佈 (其會在發佈網站上顯示目錄內容),您必須在索引項目 的 URL 上記錄使用事件,並覆寫一些網站設定。例如,如果您在已於發佈網站上發佈的製作網站中擁有一個目錄,當使用者與發佈網站上的目錄項目進行互動時,就必須在製作網站中的項目上記錄此使用事件。因此,您新增來記錄使用事件的程式碼必須覆寫發佈網站的 SiteId 和 WebId,並使用製作網站的 SiteId 和 WebId 來取代。If you are using cross-site publishing, which shows catalog content on a publishing site, you must record the usage event on the URL of the indexed item, and override some site settings. For example, if you have a catalog in an authoring site that you have published on a publishing site, when a user interacts with a catalog item on the publishing site, this usage event must be recorded on the item in the authoring site. Furthermore, the code that you add to record the usage event must override the SiteId and WebId of the publishing site, and be replaced with the SiteId and WebId of the authoring site.

新增程式碼來記錄預設使用事件To add code to record a default usage event

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 請以高於上述基本要求新增必要的成員資格。Add memberships that are required beyond the minimums above.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    # To view EventTypeId for all usage event types:
    $SSP = Get-SPEnterpriseSearchServiceApplicationProxy
    $SSP.GetAnalyticsEventTypeDefinitions([Guid]::Empty, 3) | ft
    
  4. 在 HTML 編輯程式中,開啟應記錄自訂使用事件的檔案 (例如,適用於內容搜尋網頁組件的顯示範本),並新增下列程式碼:In an HTML editor, open the file where the custom usage event should be logged — for example, a display template for a Content Search Web Part, and add the following code:

    window.Log<DefaultUsageEventType>ToEventStore = function(url)
    {
       ExecuteOrDelayUntilScriptLoaded(function()
       {
           var spClientContext = SP.ClientContext.get_current();
           SP.Analytics.AnalyticsUsageEntry.logAnalyticsEvent(spClientContext, <EventTypeId>, url);
           spClientContext.executeQueryAsync(null, Function.createDelegate(this, function(sender, e){ alert("Failed to log event for item: " + document.URL + " due to: " + e.get_message()) }));
       }, "SP.js");
    }
    

    其中:Where:

    • 是預設使用事件類型的名稱 — 例如檢視 is the name of the default usage event type — for example, Views .

    • 為使用事件類型的數值識別碼-例如1 is the numeric ID of the usage event type — for example, 1 .

  5. 在 HTML 編輯程式中,開啟參考預設使用事件的檔案,並新增下列程式碼:In an HTML editor, open the file that refers to the default usage event, and add the following code:

    # The example below shows how a default usage event type is referred to on a page load:
    <body onload="Log<DefaultUsageEventType>ToEventStore('<URL>')"> 
    

    其中:Where:

    • 是預設使用事件類型的名稱 — 例如檢視 is the name of the default usage event type — for example, Views .

    • <URL>是要應記錄使用事件,項目的完整 URL-例如http://contoso.com/careers<URL> is the full URL of the item to which the usage event should be logged, — for example, http://contoso.com/careers

  6. 儲存檔案。Save the file.

    新增程式碼來記錄預設使用事件並覆寫網站設定To add code to record a default usage event and override site settings

  7. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 請以高於上述基本要求新增必要的成員資格。Add memberships that are required beyond the minimums above.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  8. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  9. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    # To view EventTypeId for all usage event types:
    $SSP = Get-SPEnterpriseSearchServiceApplicationProxy
    $SSP.GetAnalyticsEventTypeDefinitions([Guid]::Empty, 3) | ft
    
  10. 在 HTML 編輯程式中,開啟應記錄自訂使用事件的檔案 - 例如,適用於內容搜尋網頁組件的顯示範本。下列範例示範如何覆寫目前的 SiteId、WebId 及 UserId。In an HTML editor, open the file where the custom usage event should be logged — for example, a display template for a Content Search Web Part. The example below shows how to override the current SiteId, the WebId and the UserId.

    window.Log<DefaultUsageEventType>ToEventStore = function(url, siteIdGuid, webIdGuid, spUser)
    {
       ExecuteOrDelayUntilScriptLoaded(function()
       {
         var spClientContext = SP.ClientContext.get_current();
         SP.Analytics.AnalyticsUsageEntry.logAnalyticsEvent(spClientContext, <EventTypeId>, url, webIdGuid, siteIdGuid, spUser);
    spClientContext.executeQueryAsync(null, Function.createDelegate(this, function(sender, e){ alert("Failed to log event for item: " + document.URL + " due to: " + e.get_message()) }));
       }, "SP.js");
    }
    

    其中:Where:

    • 是預設事件類型的名稱 — 例如檢視 is the name of the default event type — for example, Views .

    • 為使用事件類型的數值識別碼-例如1 is the numeric ID of the usage event type — for example, 1 .

  11. 在 HTML 編輯程式中,開啟參考預設使用事件類型的檔案,並新增下列程式碼:In an HTML editor, open the file that refers to the default usage event type, and add the following code:

    # The example below shows how a default usage event type is referred to on a page load:
    <body onload="Log<DefaultUsageEventType>ToEventStore('<URL>', new SP.Guid('{<SiteId GUID>}'), new SP.Guid('{<WebId GUID>}'), '<UserName>')">
    

    其中:Where:

    • 是預設事件類型的名稱 — 例如檢視 is the name of the default event type — for example, Views .

    • 是 managed 屬性OriginalPath中的 URL。 is the URL in the managed property OriginalPath .

    • 是製作網站的 SiteId GUID。如需如何取得 SiteId GUID,請參閱取得 SiteId GUID 與 WebId GUID 站台 is the SiteId GUID of the authoring site. For information on how to get the SiteId GUID, see Get SiteId GUID and WebId GUID for a site.

    • 已製作網站 WebId GUID。如需如何取得 WebId GUID,請參閱取得 SiteId GUID 與 WebId GUID 站台 is the WebId GUID of the authoring site. For information on how to get the WebId GUID, see Get SiteId GUID and WebId GUID for a site.

    • <UserName>可以是用來識別使用者在具有匿名使用者,例如網站的 cookie 識別碼。<UserName> can be a cookie ID that is used to identify users on a site that has anonymous users, for example.

注意

[!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

變更使用事件類型的重要性層級Change the level of importance of a usage event type

流量事件類型屬性、 RecommendationWeight、 是重要性的對使用者顯示的比較流量事件類型層級,建議計算中所用的其他流量事件類型的數值。預設檢視使用事件類型已預先設定的RecommendationWeight值 1。其他預設使用事件類型、建議顯示,並建議點選和所有自訂使用事件類型,有RecommendationWeight值為 0。若要增加的建議計算流量事件類型的重要性,變更RecommendationWeight參數的值。最高可用的重要性層級為 10。The usage event type property, RecommendationWeight, is a numeric value that shows the level of importance of a usage event type compared to other usage event types that are used in the recommendations calculation. The default Views usage event type has a preconfigured RecommendationWeight value of 1. The other default usage event types, Recommendations displayed, and Recommendations clicked, and all custom usage event types, have a RecommendationWeight value of 0. To increase the importance of a usage event type in the recommendations calculation, change the value of the RecommendationWeight parameter. The highest level of importance available is 10.

若要變更使用事件類型的重要性層級To change the level of importance of a usage event type

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 請以高於上述基本要求新增必要的成員資格。Add memberships that are required beyond the minimums above.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    # To view EventTypeId for all usage event types:
    $SSP = Get-SPEnterpriseSearchServiceApplicationProxy
    $SSP.GetAnalyticsEventTypeDefinitions([Guid]::Empty, 3) | ft
    # To get a usage event type:
    $tenantConfig = $SSP.GetAnalyticsTenantConfiguration([Guid]::Empty)
    $event = $tenantConfig.EventTypeDefinitions | where-object { $_.EventTypeId -eq <EventTypeId> }
    # To change the importance level of a usage event type:
    $event.RecommendationWeight = <RecommendationWeightNumber>
    $tenantConfig.Update($SSP)
    # To verify the changed importance level for the usage event type:
    $tenantConfig = $SSP.GetAnalyticsTenantConfiguration([Guid]::Empty)
    $event = $tenantConfig.EventTypeDefinitions | where-object { $_.EventTypeId -eq <EventTypeId> }
    $event
    

    其中:Where:

    • 為您要變更權數之使用事件類型的數值識別碼-例如256 is the numeric ID of the usage event type for which you want to change the weight — for example, 256 .

    • 是您想要套用至使用者事件類型的重要性層級-例如4 is the level of importance that you want to apply to the user event type — for example, 4 .

注意

[!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

變更使用事件類型的最近時間週期Change the Recent time period for a usage event type

流量事件類型屬性RecentPopularityTimeframe是定義最近使用最常用項目報告中的時間週期的數值。最常用項目報告文件庫或清單中顯示每個流量事件類型的所有項目最常用項目 — 例如最檢視文件庫或清單中的項目。報表可以排序的最近使用全部的時段。根據預設的最近時間週期設定的最後一個 14 天的每個流量事件。您可以變更此設定第一和 14 之間的時間期間天。The usage event type property RecentPopularityTimeframe is a numeric value that defines the Recent time period in the Most Popular Items report. The Most Popular Items report shows the most popular items per usage event type for all items in a library or list — for example, the most viewed items in a library or list. The report can be sorted by the time periods Recent or Ever. By default, the Recent time period is set to the last 14 days for each usage event. You can change this to a time period between one and 14 days.

若要變更使用事件類型的最近時間週期To change the Recent time period for a usage event type

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 請以高於上述基本要求新增必要的成員資格。Add memberships that are required beyond the minimums above.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    # To view EventTypeId for all usage event types:
    $SSP = Get-SPEnterpriseSearchServiceApplicationProxy
    $SSP.GetAnalyticsEventTypeDefinitions([Guid]::Empty, 3) | ft
    # To get a usage event type:
    $tenantConfig = $SSP.GetAnalyticsTenantConfiguration([Guid]::Empty)
    $event = $tenantConfig.EventTypeDefinitions | where-object { $_.EventTypeId -eq <EventTypeId> }
    # To change the Recent time span for a usage event type:
    $event.RecentPopularityTimeFrame = <TimeFrame>
    $tenantConfig.Update($SSP)
    # To verify the changed Recent time frame for the usage event type:
    $tenantConfig = $SSP.GetAnalyticsTenantConfiguration([Guid]::Empty)
    $event = $tenantConfig.EventTypeDefinitions | where-object { $_.EventTypeId -eq <EventTypeId> }
    $event
    

    其中:Where:

    • 為您要變更 [最近] 時間範圍之使用事件類型的數值識別碼-例如256 is the numeric ID of the usage event type for which you want to change the Recent time frame — for example, 256 .

    • 為您想要套用至使用者事件類型的新最近使用的時間範圍-例如7 is the new Recent time frame that you want to apply to the user event type — for example, 7 .

      注意

      只有在執行使用分析計時器工作之後,系統才會更新對於 [最近] 時間週期的任何變更。The system updates any changes to the Recent time period only after the Usage Analytics Timer Job has run.

注意

[!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

啟用和停用匿名使用者的使用事件記錄Enable and disable the logging of usage events of anonymous users

已瀏覽的網站內容沒有連線至系統帳戶的使用者稱為匿名使用者。僅限檢視事件類型為啟用匿名使用者記錄。根據預設,自訂使用事件記錄已停用匿名使用者。Users that are browsing the contents of a site without being connected to an account are known as anonymous users. Only the Views event type is enabled for the logging of anonymous users. By default, the logging of custom usage events is disabled for anonymous users.

若要啟用匿名使用者的使用事件記錄To enable the logging of usage events of anonymous users

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 請以高於上述基本要求新增必要的成員資格。Add memberships that are required beyond the minimums above.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    # To view EventTypeId for all usage event types:
    $SSP = Get-SPEnterpriseSearchServiceApplicationProxy
    $SSP.GetAnalyticsEventTypeDefinitions([Guid]::Empty, 3) | ft
    # To get a usage event type:
    $tenantConfig = $SSP.GetAnalyticsTenantConfiguration([Guid]::Empty)
    $event = $tenantConfig.EventTypeDefinitions | where-object { $_.EventTypeId -eq <EventTypeId> }
    # To enable the logging of anonymous users:
    $event.Options = [Microsoft.Office.Server.Search.Analytics.EventOptions]::AllowAnonymousWrite
    $tenantConfig.Update($SSP)
    # To verify that the logging of anonymous users has been enabled, i.e. that the Options property is set to AllowAnonymousWrite:
    $tenantConfig = $SSP.GetAnalyticsTenantConfiguration([Guid]::Empty)
    $event = $tenantConfig.EventTypeDefinitions | where-object { $_.EventTypeId -eq <EventTypeId> }
    $event
    

    其中:Where:

    • 為您要啟用匿名使用者記錄使用事件類型的數值識別碼-例如256 is the numeric ID of the usage event type that you want to enable for the logging of anonymous users — for example, 256 .

    若要停用匿名使用者的使用事件記錄To disable the logging of usage events of anonymous users

  4. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 請以高於上述基本要求新增必要的成員資格。Add memberships that are required beyond the minimums above.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  5. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  6. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    # To view EventTypeId for all usage event types:
    $SSP = Get-SPEnterpriseSearchServiceApplicationProxy
    $SSP.GetAnalyticsEventTypeDefinitions([Guid]::Empty, 3) | ft
    # To get a usage event type:
    $tenantConfig = $SSP.GetAnalyticsTenantConfiguration([Guid]::Empty)
    $event = $tenantConfig.EventTypeDefinitions | where-object { $_.EventTypeId -eq <EventTypeId> }
    # To disable the logging of anonymous users:
    $event.Options = [Microsoft.Office.Server.Search.Analytics.EventOptions]::None
    $tenantConfig.Update($SSP)
    # To verify that logging of anonymous users has been disabled, i.e. that the Options property is set to None:
    $tenantConfig = $SSP.GetAnalyticsTenantConfiguration([Guid]::Empty)
    

    其中:Where:

    • 為您要停用匿名使用者記錄使用事件類型的數值識別碼-例如256 is the numeric ID of the usage event type that you want to disable for the logging of anonymous users — for example, 256 .

      注意

      預設流量事件類型的檢視,您無法停用匿名使用者記錄。For the default usage event type Views , you cannot disable the logging of anonymous users.

注意

[!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

取得網站的 SiteId GUID 與 WebId GUIDGet SiteId GUID and WebId GUID for a site

您可以使用下列 PowerShell 命令來取得網站的 SiteId GUID 與 WebId GUID。You can use the following PowerShell commands to get the SiteId GUID and the WebId GUID for a site.

若要取得網站的 SiteId GUID 與 WebId GUIDTo get SiteId GUID and WebId GUID for a site

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 請以高於上述基本要求新增必要的成員資格。Add memberships that are required beyond the minimums above.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    # To get the SiteId GUID and the WebId GUID for a root site collection:
    $site = Get-SPSite "<RootSiteURL>"
    $web = $site.RootWeb
    $site.id
    $web.id
    # To get the WebId GUID for a site below the root site collection:
    $site = Get-SPSite "<RootSiteURL>"
    $web = $site.OpenWeb("<SubSiteLocation>")
    $web.id
    

    其中:Where:

    • <RootSiteURL>_是您想要取得 SiteId GUID 之根網站的 URL 與 WebId GUID 之 — 例如_http://contoso.com/sites/catalog<RootSiteURL> is the URL of the root site that you want to get the SiteId GUID and the WebId GUID of — for example, http://contoso.com/sites/catalog.

    • <SubSiteLocation>_是根網站 URL 後的子網站的 URL 路徑的其餘部分。例如,如果您的根網站 URL 是_http://contoso.com/sites/catalog,與您的子網站 URL 是_http://contoso.com/sites/catalog/products_,輸入此版面配置區的_產品_。<SubSiteLocation> is the remainder of the URL path to the subsite after the root site URL. For example, if your root site URL is http://contoso.com/sites/catalog, and your subsite URL is http://contoso.com/sites/catalog/products, type products for this placeholder.

注意

[!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

另請參閱See also

概念Concepts

在 SharePoint Server 中檢視使用情形報告View usage reports in SharePoint Server

其他資源Other Resources

如何在 SharePoint Server 2013 網站上顯示建議和常用項目How to display recommendations and popular items on a SharePoint Server 2013 site