您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

如何使用网页将实际用户度量发送到 Azure 流量管理器How to send Real User Measurements to Azure Traffic Manager using web pages

可以配置网页,通过获取实际用户度量 (RUM) 密钥并将生成的代码嵌入到网页,将实际用户度量发送到流量管理器。You can configure your web pages to send Real User Measurements to Traffic Manager by obtaining a Real User Measurements (RUM) key and embedding the generated code to web page.

获取实际用户度量密钥Obtain a Real User Measurements key

从客户端应用程序获取并发送到流量管理器的度量由使用唯一字符串的服务标识,称为实际用户度量 (RUM) 密钥The measurements you take and send to Traffic Manager from your client application are identified by the service using a unique string, called the Real User Measurements (RUM) Key. 可以使用 Azure 门户、REST API 或使用 PowerShell/Azure CLI 获取 RUM 密钥。You can get a RUM key using the Azure portal, a REST API, or by using the PowerShell or Azure CLI.

若要使用 Azure 门户获取 RUM 密钥,请执行以下操作:To obtain the RUM Key using Azure portal:

  1. 在浏览器中,登录 Azure 门户。From a browser, sign in to the Azure portal. 如果还没有帐户,可以注册免费一个月试用版。If you don’t already have an account, you can sign up for a free one-month trial.

  2. 在门户的搜索栏中,搜索要修改的流量管理器配置文件名称,并在显示的结果中单击该流量管理器配置文件。In the portal’s search bar, search for the Traffic Manager profile name that you want to modify, and then click the Traffic Manager profile in the results that the displayed.

  3. 在“流量管理器配置文件”边栏选项卡中,单击“设置”**** 下的“实际用户度量”****。In the Traffic Manager profile blade, click Real User Measurements under Settings.

  4. 单击“生成密钥”**** 新建 RUM 密钥。Click Generate Key to create a new RUM Key.

    生成实际用户度量密钥

    图 1:生成实际用户度量密钥Figure 1: Real User Measurements Key Generation

  5. 该边栏选项卡现在显示生成的 RUM 密钥和需要嵌入到 HTML 页中的 JavaScript 代码片段。The blade now displays the RUM Key generated and a JavaScript code snippet that needs to be embedded into your HTML page.

    实际用户度量密钥的 Javascript 代码

    图 2:实际用户度量密钥和度量 JavaScriptFigure 2: Real User Measurements Key and Measurement JavaScript

  6. 单击“复制”**** 按钮复制 JavaScript 代码。Click the Copy button to copy the JavaScript code.

重要

使用生成的 JavaScript 使“实际用户度量”功能正常工作。Use the generated JavaScript for Real User Measurements feature to function properly. 对此脚本或“实际用户度量”使用的脚本进行任何更改可能会导致不可预知的行为。Any changes to this script or the scripts used by Real User Measurements can lead to unpredictable behavior.

将代码嵌入到 HTML 网页Embed the code to an HTML web page

获取 RUM 密钥后,下一步是将此复制的 JavaScript 嵌入到最终用户访问的 HTML 页面。After you have obtained the RUM key, the next step is to embed this copied JavaScript into an HTML page that your end users visit. 编辑 HTML 可以使用不同的工具和工作流以多种方式完成。Editing HTML can be done in many ways and using different tools and workflows. 本示例演示如何更新 HTML 页面以添加此脚本。This example shows how to update an HTML page to add this script. 可以使用本指南使它适合于 HTML 源管理工作流。You can use this guidance to adapt it to your HTML source management workflow.

  1. 在文本编辑器中打开 HTML 页面Open the HTML page in a text editor

  2. 将在前面步骤中复制的 JavaScript 代码粘贴到 HTML 的 BODY 部分中(复制的代码位于第 8 行和第 9 行,请参见图 3)。Paste the JavaScript code you had copied in the earlier step to the BODY section of the HTML (the copied code is on line 8 & 9, see figure 3).

    将 Javascript 代码嵌入到实际用户度量网页中

    图 3:嵌入实际用户度量 JavaScript 的简单 HTMLFigure 3: Simple HTML with embedded Real User Measurements JavaScript

  3. 保存 HTML 文件并将托管在连接到 Internet 的 Web 服务器上。Save the HTML file and host it on a webserver connected to the internet.

  4. 下一次在 Web 浏览器中呈现此页时,将下载引用的 JavaScript,并且脚本将执行度量和报告操作。Next time this page is rendered on a web browser, the JavaScript referenced is downloaded and the script will execute the measurement and reporting operations.

后续步骤Next steps