好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Metrics & Methods

Metrics & Methods

Omniture SiteCatalyst Reporting API & Visual Studio .NET

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.

view source

print ?

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

 

RECENT POSTS Omniture SiteCatalyst Reporting API & Visual Studio .NET A Buffer for Custom Link Tracking Foxy Debugging (Updated) Introductions

RECOMMENDED BLOGS emptymind.org Omniture Blog Rudi Shumpert: Code by Numbers The Omni Man Blog

NEED A WEB ANALYST?

Send Me an E-Mail

 

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

作者: Leo_wl

    

出处: http://www.cnblogs.com/Leo_wl/

    

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

版权信息

查看更多关于Metrics & Methods的详细内容...

  阅读:51次