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.
003 |
using System.Collections.Generic; |
006 |
using System.ServiceModel; |
007 |
using System.ServiceModel.Description; |
008 |
using System.ServiceModel.Channels; |
009 |
using Microsoft.ServiceModel.Samples.CustomToken; |
010 |
using Adobe.OmnitureAPI; |
012 |
namespace ConsoleAPIExample { |
014 |
static void Main( string [] args) { |
017 |
string strAPIUsername = "[API Username]" ; |
018 |
string strAPIKey = "[API Key]" ; |
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; |
032 |
string strRequestOut = "" ; |
033 |
string strResponseOut = "" ; |
034 |
string strResultsOut = "" ; |
035 |
string strErrorMsg = "" ; |
039 |
int intCheckReadyCounter = 0; |
040 |
bool blnReportDone = false ; |
042 |
OmnitureWebServicePortTypeClient client = |
043 |
OmnitureWebServicePortTypeClient.getClient(strAPIUsername, strAPIKey, strAPIUrl); |
046 |
reportDescription scReport = new reportDescription(); |
049 |
reportDefinitionMetric scMetric1 = new reportDefinitionMetric(); |
050 |
reportDefinitionMetric scMetric2 = new reportDefinitionMetric(); |
051 |
reportDefinitionMetric scMetric3 = new reportDefinitionMetric(); |
054 |
reportDefinitionMetric[] scMetricList = new reportDefinitionMetric[3] { |
055 |
scMetric1, scMetric2, scMetric3 |
059 |
reportDefinitionElement scElement1 = new reportDefinitionElement(); |
062 |
reportDefinitionElement[] scElementList = new reportDefinitionElement[1] { |
067 |
reportQueueResponse scResponse = new reportQueueResponse(); |
068 |
report_status scReportStatus = new report_status(); |
069 |
reportResponse scReportResponse = new reportResponse(); |
072 |
scMetric1.id = strMetricId1; |
073 |
scMetric2.id = strMetricId2; |
074 |
scMetric3.id = strMetricId3; |
077 |
scElement1.id = strElementId; |
078 |
scElement1.top = intResultsToGet; |
081 |
scReport.reportSuiteID = strRSID; |
082 |
scReport.dateFrom = strDateFrom; |
083 |
scReport.dateTo = strDateTo; |
084 |
scReport.metrics = scMetricList; |
085 |
scReport.elements = scElementList; |
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); |
093 |
scResponse = client.ReportQueueRanked(scReport); |
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); |
102 |
while (intCheckReadyCounter < 6 && !blnReportDone) { |
103 |
System.Threading.Thread.Sleep(10000); |
106 |
scReportStatus = client.ReportGetStatus(scResponse.reportID); |
107 |
switch (scReportStatus.status.ToString()) { |
109 |
blnReportDone = true ; |
112 |
intCheckReadyCounter++; |
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); |
129 |
Console.Write( "Fetching Results" + "\r\n\r\n\r\n" ); |
132 |
scReportResponse = client.ReportGetReport(scResponse.reportID); |
134 |
Console.Write( "Section" + " | " + "PageViews" + " | " + "Visits" + " | " + "Visitors" + "\r\n" ); |
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); |
147 |
tokenCount = client.CompanyGetTokenCount(); |
149 |
Console.WriteLine( "\r\n\r\n" + "Tokens remaining for the Month: " + tokenCount + "\r\n\r\n" ); |
150 |
Console.Write( "Please Close Window" ); |