zoukankan      html  css  js  c++  java
  • Metrics & Methods

    You are in a helicopter.

    The application below takes my eighteen hours (approximately) of Microsoft C# experience and builds upon Sean Gubler’s work posted on the Omniture Developer Connection Blog. In lieu of optimal code, I have gone for a verbose example that tries to show the what, why and how.

    If you:

      • Follow Sean’s instructions
      • Replace his code example for mine

    You should have a fully functional application which, for your top 5 site sections, displays:

    • Page Views
    • Visits
    • Visitors

    This application was built as a proof of concept, before attempting a SSIS Package which places site section traffic in a SQL Server Database. A few minor changes are required to the code below, but it works quite well as a Script Component.

    The DLLs Sean provides are compiled using .net 4, which does not play nice when building a SSIS Package using SQL Server 2008 R2 Business Intelligence Development Studio . To overcome this issue, I compiled the DLLs using .net 3.5 and have yet to experience any problems. If you go this route, you may hit a few snags with the DLLs being unsigned or not registered. If you do, drop me a comment and I will relay how I addressed.

    Finally, onto the application.

    002 using System;
    003 using System.Collections.Generic;
    004 using System.Linq;
    005 using System.Text;
    006 using System.ServiceModel;
    007 using System.ServiceModel.Description;
    008 using System.ServiceModel.Channels;
    009 using Microsoft.ServiceModel.Samples.CustomToken;
    010 using Adobe.OmnitureAPI;
    011  
    012 namespace ConsoleAPIExample {
    013     class Program {
    014         static void Main(string[] args) {
    015  
    016             //API Parameters
    017             string strAPIUsername = "[API Username]";
    018             string strAPIKey = "[API Key]";
    019             string strAPIUrl = "https://api.omniture.com/admin/1.2/";
    020  
    021             //Report Parameters
    022             string strDateFrom = "[Date From]";
    023             string strDateTo = "[Date To]";
    024             string strRSID = "[RSID]";
    025             string strMetricId1 = "pageViews";
    026             string strMetricId2 = "visits";
    027             string strMetricId3 = "visitorsMonthly";
    028             string strElementId = "siteSection";
    029             int intResultsToGet = 5; //kept this at 5 just for debugging purposes
    030  
    031             //Output Messages
    032             string strRequestOut = "";
    033             string strResponseOut = "";
    034             string strResultsOut = "";
    035             string strErrorMsg = "";
    036             int tokenCount;
    037  
    038             //Used to check status of report
    039             int intCheckReadyCounter = 0;
    040             bool blnReportDone = false;
    041  
    042             OmnitureWebServicePortTypeClient client =
    043             OmnitureWebServicePortTypeClient.getClient(strAPIUsername, strAPIKey, strAPIUrl);
    044  
    045             //Contains information for creating a report
    046             reportDescription scReport = new reportDescription();
    047  
    048             //Requesting three metrics and each reportDefinitionMetric identifies one metric
    049             reportDefinitionMetric scMetric1 = new reportDefinitionMetric();
    050             reportDefinitionMetric scMetric2 = new reportDefinitionMetric();
    051             reportDefinitionMetric scMetric3 = new reportDefinitionMetric();
    052  
    053             //A list of reportDefinitionMetrics
    054             reportDefinitionMetric[] scMetricList = new reportDefinitionMetric[3] {
    055                 scMetric1, scMetric2, scMetric3
    056             };
    057  
    058             //Using two parameters of one element
    059             reportDefinitionElement scElement1 = new reportDefinitionElement();
    060  
    061             //An array of reportDefinitionElements
    062             reportDefinitionElement[] scElementList = new reportDefinitionElement[1] {
    063                 scElement1
    064             };
    065  
    066             //Variables to hold responses for requests
    067             reportQueueResponse scResponse = new reportQueueResponse(); //response to initial report request
    068             report_status scReportStatus = new report_status(); //response to status checks
    069             reportResponse scReportResponse = new reportResponse(); //actual report results
    070  
    071             //Setting the report metrics
    072             scMetric1.id = strMetricId1;
    073             scMetric2.id = strMetricId2;
    074             scMetric3.id = strMetricId3;
    075  
    076             //Setting the parameters of the report element
    077             scElement1.id = strElementId;
    078             scElement1.top = intResultsToGet;
    079  
    080             //Setting report description
    081             scReport.reportSuiteID = strRSID;
    082             scReport.dateFrom = strDateFrom;
    083             scReport.dateTo = strDateTo;
    084             scReport.metrics = scMetricList;
    085             scReport.elements = scElementList;
    086  
    087             strRequestOut = "Requesting traffic to the top " + intResultsToGet + " ";
    088             strRequestOut = strRequestOut + "site sections for " + scReport.dateFrom + " ";
    089             strRequestOut = strRequestOut + "to " + scReport.dateTo + "\r\n\r\n\r\n";
    090             Console.Write(strRequestOut);
    091  
    092             //Queuing the report via the API
    093             scResponse = client.ReportQueueRanked(scReport);
    094  
    095             strResponseOut = "Report Request ID: " + scResponse.reportID.ToString() + "\r\n";
    096             strResponseOut = strResponseOut + "Report Request Status: " + scResponse.status.ToString() + "\r\n";
    097             strResponseOut = strResponseOut + "Report Request Status Msg: " + scResponse.statusMsg.ToString() + "\r\n\r\n";
    098             strResponseOut = strResponseOut + "Checking Every 10 Seconds for Report" + "\r\n\r\n\r\n";
    099             Console.Write(strResponseOut);
    100  
    101             //Timed delay used when checking report status
    102             while (intCheckReadyCounter < 6 && !blnReportDone) {
    103                 System.Threading.Thread.Sleep(10000);
    104  
    105                 //Checking report status via API
    106                 scReportStatus = client.ReportGetStatus(scResponse.reportID);
    107                 switch (scReportStatus.status.ToString()) {
    108                 case "done":
    109                     blnReportDone = true;
    110                     break;
    111                 case "ready":
    112                     intCheckReadyCounter++;
    113                     break;
    114                 case "failed":
    115                 default:
    116                     //Created string in this manner for readibility
    117                     strErrorMsg = "error returning results--";
    118                     strErrorMsg = strErrorMsg + "--rprtID--" + scResponse.reportID.ToString();
    119                     strErrorMsg = strErrorMsg + "--rqst status--" + scResponse.status.ToString();
    120                     strErrorMsg = strErrorMsg + "--status msg--" + scResponse.statusMsg.ToString();
    121                     strErrorMsg = strErrorMsg + "--rpt status--" + scReportStatus.status.ToString();
    122                     strErrorMsg = strErrorMsg + "--err code--" + scReportStatus.error_code.ToString();
    123                     strErrorMsg = strErrorMsg + "--err msg--" + scReportStatus.error_msg.ToString();
    124                     throw new InvalidOperationException(strErrorMsg);
    125                 }
    126  
    127             }
    128  
    129             Console.Write("Fetching Results" + "\r\n\r\n\r\n");
    130  
    131             //Fetching the results via the API
    132             scReportResponse = client.ReportGetReport(scResponse.reportID);
    133  
    134             Console.Write("Section" + "  |  " + "PageViews" + "  |  " + "Visits" + "  |  " + "Visitors" + "\r\n");
    135  
    136             //Output results
    137             for (int i = 0; i < intResultsToGet; i++) {
    138                 strResultsOut = scReportResponse.report.data[i].name.ToString() + "  |  ";
    139                 strResultsOut = strResultsOut + scReportResponse.report.data[i].counts[0].ToString() + "  |  ";
    140                 strResultsOut = strResultsOut + scReportResponse.report.data[i].counts[1].ToString() + "  |  ";
    141                 strResultsOut = strResultsOut + scReportResponse.report.data[i].counts[2].ToString() + "\r\n";
    142                 Console.Write(strResultsOut);
    143                 strResultsOut = "";
    144             }
    145  
    146             //Thrown in to watch token usage
    147             tokenCount = client.CompanyGetTokenCount();
    148  
    149             Console.WriteLine("\r\n\r\n" + "Tokens remaining for the Month:  " + tokenCount + "\r\n\r\n");
    150             Console.Write("Please Close Window");
    151  
    152             //Pauses the App
    153             Console.ReadLine();
    154         }
    155  
    156     }
    157 }
    NO COMMENTS
     
     

    http://metricsandmethods.com/omniture-api-visual-studio-example?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+metricsandmethods+%28Metrics+%26+Methods%29

  • 相关阅读:
    裸眼 3D 技术是什么原理?
    裸眼3D全攻略3:拍摄3D—瞳距、镜距、视角偏转与空间感
    JFreeChart DateAxis用法
    remount issue on android 7.0
    获取WebView加载的网页内容并进行动态修改
    android自定义Activity窗口大小(theme运用)
    Android5.0免Root截屏,录屏
    coursera上的软件安全课程的课后阅读补充
    java,C#接口与C++的虚基类
    单元测试之C/C++
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2514882.html
Copyright © 2011-2022 走看看