Sie sind auf Seite 1von 17

Adobe Marketing Cloud

Adobe Analytics Data Insertion API

Contents
Data Insertion API.............................................................................................................3
Overview...............................................................................................................................................................................3
Data Insertion Process...............................................................................................................................................................................3 Visitor Identification...................................................................................................................................................................................4 Sequential Data Requirements..............................................................................................................................................................5 Delayed Data.................................................................................................................................................................................................5 HTTP 1.1..........................................................................................................................................................................................................6 Limitations.....................................................................................................................................................................................................6

Reference..............................................................................................................................................................................6
Supported XML Tags and Query Variables........................................................................................................................................7 POST Response Codes.............................................................................................................................................................................10

Sample Code.....................................................................................................................................................................11
HTTP POST Sample...................................................................................................................................................................................11 HTTP GET Sample......................................................................................................................................................................................13 Data Insertion Sample (PHP).................................................................................................................................................................14 Data Insertion Sample (Java)................................................................................................................................................................15 Data Insertion Sample (Python)...........................................................................................................................................................17

Last updated 9/24/2013

Adobe Analytics Data Insertion API

Data Insertion API

Data Insertion API


The Data Insertion API supports HTTP POST and HTTP GET for submitting data to Adobe Marketing Cloud servers.

Overview
The Data Insertion API provides a mechanism for server-side data collection and submission to Marketing Cloud servers. Instead of using JavaScript beacons on each Web page to transmit visitor data to Online Marketing Suite servers, server-side data collection collects data based solely on Web browser requests and Web server responses. While this data capture method cannot capture all data that is available via page-based beacons, it provides valuable insight into user activity on your Web pages without the overhead associated with attaching a JavaScript beacon to every Web page.

Data Insertion Process


The Data Insertion API supports HTTP POST and HTTP GET for submitting data to Adobe Marketing Cloud servers. Note: The Analytics response to each data insertion includes a status message (SUCCESS or FAILURE). HTTP POST Use an HTTP POST to submit properly-formatted Data Insertion XML to the Data Insertion URL. The Data Insertion URL differs from the standard JavaScript data submission URL. Adobe ClientCare can provide the domain name of the Adobe data collection servers where you should send data. For example:
http://namespace.112.2o7.net/b/ss//6 http://namespace.122.2o7.net/b/ss//6

Note: The "6" code at the end of the URL indicates that the data submission requires XML processing. Upon receipt, Adobe servers perform basic tag validation of the data insertion. If it encounters an error, Adobe returns a Failure response. If the data insertion is successful, Adobe queues the data insertion request for processing by the standard Analytics Data Processing Engine. The engine processes these requests in the same way it processes data collected via JavaScript. When using HTTP POST with the Data Insertion API, consider the following: The Data Insertion API requires data in UTF-8 format. Specify the character encoding in the opening XML tag, as shown in XML Data Insertion Format. Replace Ampersand (&), greater-than (>), and less-than (<) symbols with their HTML equivalents when passing them into a Analytics variable. For example, submit <evar1>News & Sports <local> </evar1> as <evar1>News &amp; Sports &lt;local&gt; </evar1>. To submit data over an encrypted connection, the application must be configured to support HTTPS POST commands. Some tools that let you do this include: PHP versions 4.3.0 and higher support OpenSSL, and can be used to POST data through SSL port 443. You can see an example of this in Sample Data Insertion (PHP). You can use cURL to send data over an SSL connection. For information about HTTPS POST in Java, see http://java.sun.com/developer/technicalArticles/Security/secureinternet/.

Data Insertion API

Microsoft .Net Framework version 1.1 supports the HTTP header: Expect: 100-Continue in HTTP POST requests, but Marketing Cloud servers reject POST data sent with this type of request. To avoid this, set ServicePointManager.Expect100Continue = False. For more information, see http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemnetservicepointmanagerclassexpect100continuetopic.asp . HTTP GET Use an HTTP GET to submit data to the Data Insertion URL in a query-string format that supports shortened variable names (for more information, see "Variables and Query String Parameters" in the Analytics Implementation Guide, available at Help > Documentation in the Marketing Cloud. HTTP GET reduces bandwidth needs by 30% - 40%, but Adobe data collection servers do not send response messages, so if the data insertion doesn't work as expected, you do not have that feedback for troubleshooting purposes. For more information, see the HTTP GET Sample. The Data Insertion URL differs from the standard JavaScript data submission URL. The <rsid> in the URL is the report suite where you want to submit the data. Adobe ClientCare can provide the domain name of the Adobe data collection servers where you should send data. For example:
http://namespace.112.2o7.net/b/ss/<rsid>/0 http://namespace.122.2o7.net/b/ss/<rsid>/0

Note: The "0" code at the end of the URL indicates that the data submission requires JavaScript processing. For example: Upon receipt, Adobe servers perform basic tag validation of the data insertion. If it encounters an error, Adobe returns a Failure response. If the data insertion is successful, Adobe queues the data insertion request for processing by the standard Analytics Data Processing Engine. The engine processes these requests in the same way it processes data collected via JavaScript. Note: The Data Insertion API requires data in UTF-8 format.

Visitor Identification
To track site visitors, each visitor must have a unique visitor ID. Ideally, this is a persistent cookie with an extended expiration period (5 years or more.) Use the visitorID tag, the combination of IP address and userAgent, to submit visitor ID information to Adobe data collection servers. The visitorID variable supports up to 100 alpha-numeric characters and cannot contain a hyphen. If the data insertion includes a visitorID, the Analytics Data Processing Engine assumes that persistent cookies are enabled for the visitor's Web browser. If the data insertion identifies visitors using IP address/User Agent, Analytics displays persistent cookies for that visitor as disabled. Note: To avoid processing problems, make sure that visitorID is a uniformly distributed random number. The visitorID is critical for linking a visitor's activities captured via JavaScript with those submitted through tagless data collection, or a third-party application. For example, to link a visitor's browsing activity with transactions in a third-party shopping cart application, you must pass the visitorID to the shopping cart application. The shopping cart application uses the visitorID when uploading transaction data via the Data Insertion API so Analytics can link the transaction data to the visitor's browsing activity (previously captured via JavaScript).

Data Insertion API

Typically, the client systems generate unique visitor identifiers that you can use as the visitorID value. We recommend generating your own visitor id, in both the XML and in the JavaScript so that the values match.

Sequential Data Requirements


To ensure accurate visitor pathing and commerce data, applications must send visitor data in the order it was received. The Analytics Data Processing Engine closes a visit after 30 minutes without receiving data. When simulating previously recorded traffic, Adobe recommends that data insertions mimic the time delays between visitor events on the site. For example, if the application records page views for a given visitor 2, 4, and 5 seconds apart, send those page views to Analytics using the same cadence. If the application cannot mimic the original event timing, Adobe recommends sending sequential data insertions 3 seconds apart, per visitor, to help avoid out-of-order data processing.

Delayed Data
By using the Data Insertion API, you can submit delayed data (for example, from an offline application, to Adobe data collection servers. Note: Data from delayed submissions is available to Data Warehouse and Ad hoc analysis. When submitting delayed data, you must send visitor data in the order it was received, (see Sequential Data Requirements) but you do not need to send data for different visitors in any specific order. For example, you can submit all data for visitor A before data for visitor B, even if some or all of visitor B data occurred before visitor A data. Submitting delayed data requires an additional <timestamp> tag in the XML. Analytics discards data without a timestamp. Note: To view time-stamped hits, Adobe ClientCare must enable time-stamp support on the report suite, in addition to the time-stamp variable that you set. Time-stamped hits sent to a report suite that has not been enabled do not appear in the report. Format the timestamp data, including time zone, using either the Unix timestamp format or the ISO-8601 format. For example, using the ISO-8601 format, a timestamp for a visitor event that occurred on November 17, 2009 at 5:33 PM Mountain Time (GMT-7:00:00) is as follows:
2009-11-17T17:33:22-07

Consider the following when submitting delayed (time-stamped) data: While a report suite is collecting time-stamped data, it cannot collect data through the standard JavaScript beacon method. You must enable time stamp support on a per-report-suite basis. When submitting data delayed by more than 30 minutes, do so without any pauses in the data transmission to make sure Analytics processes it as a single visit. Analytics might process delayed data as separate visits if there is more than a 100-second pause between transmission batches. You can also use Data Sources to send this type of data to the Marketing Cloud via FTP. For more information, see the Data Sources User Guide.

Data Insertion API

HTTP 1.1
Adobe data collection servers support HTTP 1.1. Using HTTP 1.1, you can send multiple POST requests in a single session. However, when using HTTP 1.1, be aware of the following: While a report suite is collecting time-stamped data, it cannot collect data through the standard JavaScript beacon method. Adobe data collection servers limit the number of HTTP requests per HTTP session. To account for this, make sure your application can detect closed sessions and respond appropriately. Adobe data collection servers observe HTTP 1.1 rules when chunking content. Make sure your application properly interprets the chunking numbers provided in the Online Marketing Suite server response to your data insertion. For example, in the following HTTP 1.1 response, the numbers 68 and 0 are chunking numbers, which represent the number of bytes to read before the next chunk.
TTP/1.1 200 OK Date: Thu, 07 Dec 2008 15:48:51 GMT Expires: Wed, 06 Dec 2008 15:48:51 GMT Last-Modified: Fri, 08 Dec 2008 15:48:51 GMT Cache-Control: no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform, private Pragma: no-cache ETag: "457837E3-649A-4BBB9314" Vary: * P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR NID PSA OUR IND COM NAV STA" Transfer-Encoding: chunked Content-Type: text/xml 68 <?xml version="1.0" encoding="UTF-8"?> <status>FAILURE</status> <reason>NO pagename OR pageurl</reason> 0

Limitations
There are some limitations to server-side data collection when compared to client-side data collection using JavaScript. Server-side data collection cannot collect Web browser configuration data. Server-side data collection cannot collect ClickMap data. Server-side data collection loses cached page navigation data because using a Web browser's back button or reloading a cached page does not generate additional server requests or responses. This limits pathing data available for Analytics reports. Typically, bots do not run JavaScript when requesting a page, and do not request the page's image tags. However, server-side data collection includes requests from bots and spiders. You must have control over the servers from which you want to collect data. If you use a Content Delivery Network (CDN) such as Akamai* to deliver web pages, the server-side data collection described here cannot collect data for those pages. If you control most of your Web site pages, but use some third-party services (for example, surveys or shopping cart systems), server-side data collection cannot collect data from the third-party pages. You should use JavaScript tagging on third-party pages that request content from your Web servers to gain visibility into those systems. Server-side data collection alone cannot provide cross-domain tracking of site visitors. However, you can use the <visitorID> tag in conjunction with client-side JavaScript data collection to pass additional information to the server. This is the only way that cross-domain tracking is possible when using a <visitorID>. Server-side data collection can co-exist with a client-side (JavaScript) implementation only if clients submit server-side data in near real-time. If clients have a JavaScript beacon implementation, and want to collect server-side data and submit it in batches, they should use Data Sources, not the Data Insertion API.

Reference
Data insertion API reference topics. This section contains details on supported XML tags and POST response codes.

Data Insertion API

Supported XML Tags and Query Variables


When processing HTTP POST data submissions, only values in supported XML tags are processed. When submitting HTTP GET data submissions, only specified query string and HTTP header variables are processed. The following table lists all supported XML tags, along with their associated query string variable equivalents and HTTP header variable equivalents, where applicable. The JavaScript variable column is provided for reference. Every data insertion must include either <pageName> and/or <pageURL>. Every data insertion must also include either <visitorID> and/or <IPaddress>. XML Tag (POST)
<browserHeight>

Query String Parameter (GET)


bh

JavaScript Variable N/A

HTTP Header Var N/A

Description Browser height in pixels (For example, 768). Browser width in pixels (For example, 1024). The campaign tracking code associated with the page. The page title or bread crumb. Monitor color depth in bits (For example, 24). Visitor's connection type ("lan" or "modem"). Key-values pairs are specified in one of the following formats:
<my.a>red</my.a>

<browserWidth>

bw

N/A

N/A

<campaign>

v0

campaign

N/A

<channel> <colorDepth>

ch c

channel N/A

N/A N/A

<connectionType> ct

N/A

N/A

<contextData>

c.[key]

contextData

N/A

or:
<my><a>red</a></my>

Each of these examples result in a context data value of my.a = red. Multiple key-value pairs can be specified. In the query string, this context data variable would appear as
c.my.a=red

Data Insertion API

XML Tag (POST)

Query String Parameter (GET)

JavaScript Variable N/A

HTTP Header Var N/A

Description Whether the visitor supports first party session cookies (Y or N). Revenue currency code For example, USD. Analytics eVar.

<cookiesEnabled> k

<currencyCode>

cc

currencyCode

N/A

<eVar#>

v#

eVar1 - eVar75

N/A

For example, <eVar2>.


<events> <hiern>

For example, v2.

events h#

events hier1 - hier5

N/A N/A

A list of Analytics events. A hierarchy string.

For example, <hier2>.


<homePage>

For example, h2

hp

N/A

N/A

Whether the current page is the visitor's homepage (Y or N).

<ipaddress> <javaEnabled>

N/A
v

N/A N/A

X-Forwarded-For The visitor's IP address. N/A Whether the visitor has Java enabled (Y or N). JavaScript version. For example, 1.3.

<javaScriptVersion> j <language> N/A

N/A N/A

N/A

Accept-Language The browser's supported language. For example, "en-us". N/A N/A N/A Name of link. Type of link ("d", "e", or "o"). The link's HREF. For custom links, page values are ignored. A delimited list of values that are passed into a variable, then reported as individual line items for reporting. The Web page name.

<linkName> <linkType> <linkURL>

pev2 pe pev1

linkName linkType linkURL

<listn>

l#

list1 - list3

N/A

For example, <list2>.

<pageName>

pageName

pageName

N/A

Data Insertion API

XML Tag (POST)


<pageType>

Query String Parameter (GET)


pageType

JavaScript Variable pageType

HTTP Header Var N/A

Description The Web page type. This is only used on 404 error pages. Set pageType to "Error Page" for when a 404 error is detected. The Web page URL For example, http://www.mysite.com/index.html. Semicolon separated list of Netscape plug-in names. List of all products on the page. Separate products with a comma. For example: Sports;Ball;1;5.95, Toys; Top;1:1.99. Analytics property name.

<pageURL>

pageURL

N/A

<plugins>

N/A

N/A

<products>

products

products

N/A

<propn> For example, c# <prop2> <purchaseID> <referrer> <reportSuiteID>

prop1 - prop75

N/A

For example, c2
purchaseID r

purchaseID N/A s_account

N/A N/A N/A

Purchase ID number. The URL of the page referrer. Specifies the report suites where you want to submit data. Separate multiple report suite IDs with a comma. Monitor resolution For example, 1280x1024. Analytics XML request version number. For example, 1.0. The Web server serving the page. The visitor's U.S. state. The time and date on which the data was collected.

Contained in the URL. See HTTP GET Sample.

<resolution>

N/A

N/A

<scXmlVer>

N/A

N/A

N/A

<server> <state> <timestamp>

server state ts

server state timestamp

N/A N/A N/A

Data Insertion API

10

XML Tag (POST)


<timezone>

Query String Parameter (GET) Part of the t parameter

JavaScript Variable N/A

HTTP Header Var N/A

Description XML POST: Visitor's time zone offset from GMT in hours. For example, -8. GET: The visitor's time zone is included in the t query string parameter, which contains the local time. The t parameter is in the following format:
dd/mm/yyyy hh:mm:ss D OFFSET

Where D is a number in the range 0-6 specifying the day of the week, and OFFSET represents:
offset from GMT in hours * 60 * - 1

For example:
09/23/2013 14:00:00 1 420 <transactionID> xact

transactionID

N/A

Common value used to tie multi-channel user activities together for reporting purposes. For more information, see the Data Sources User Guide. The visitor's browser type and OS. Visitor's unique identifying cookie. See "Visitor Information" in "Understanding the Data Insertion API". The visitor's zip code.

<userAgent> <visitorID>

N/A
vid

N/A N/A

User-Agent N/A

<zip>

zip

zip

N/A

POST Response Codes


The Data Insertion API supports these response messages to HTTP POST operations. The following table lists all supported XML tags, along with their associated JavaScript variable equivalents and HTTP header variable equivalents, where applicable. ponse messages can help you understand and correct the problem.

Data Insertion API

11

POST Response
<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?><status>SUCCESS</status> <?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?><status>FAILURE</status> <?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?><status>FAILURE</status> <reason>NO account</reason>

Description Success (general) Failure (general) Failure (missing required report suite id)

<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" Failure (missing required page name or encoding="UTF-8"?><status>FAILURE</status> <reason>NO pagename page URL) OR pageurl</reason> <?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?><status>FAILURE</status> <reason>NO visitorid OR ipaddress</reason> <?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?><status>FAILURE</status> <reason>Syntax Error</reason>

Failure (missing required visitor id or IP address) Failure (syntax error: includes malformed XML, non-encoded reserved characters, etc.)

Sample Code
The Data Insertion API includes these code samples. Note: Do not copy-and-paste these code samples. They use generic values that you must replace with valid data appropriate to your application.

HTTP POST Sample


This sample displays the structure of an HTTP POST request and response using the Data Insertion API. Note: Do not copy-and-paste these code samples. They use generic values that you must replace with valid data appropriate to your application. The [rsid] parameter identifies the report suite where you want to submit the data. Other values, such as PageURL, are sample values only. HTTP 1.0 POST Request
POST /b/ss//6 HTTP/1.0 Host: [rsid].112.2o7.net Content-Length: 593 <?xml version=1.0 encoding=UTF-8?> <request> <sc_xml_ver>1.0</sc_xml_ver> <pageURL>apps.sillystring.com/summary.do</pageURL> <referrer>http://apps.sillystring.com/summary.do</referrer> <ipAddress>192.168.10.1</ipAddress> <pageName>summary</pageName> <eVar2>14911</eVar2>

Data Insertion API

12

<userAgent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)</userAgent> <prop10>Brazil</prop10> <visitorID>1286556420966514130</visitorID> <timestamp>2009-03-05T01:00:01-05</timestamp> <reportSuiteID>[rsid]</reportSuiteID> </request>

HTTP POST Response


HTTP/1.1 200 OK Date: Wed, 13 May 2009 16:26:47 GMT X-C: ms-3.7.2 Expires: Tue, 12 May 2009 16:26:47 GMT Last-Modified: Thu, 14 May 2009 16:26:47 GMT Cache-Control: no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform, private Pragma: no-cache ETag: "4A0AF4C7-08E1-37C7F492" Vary: * P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR NID PSA OUR IND COM NAV STA" xserver: www79 Connection: close Content-Type: text/xml <?xml version="1.0" encoding="UTF-8"?> <status>SUCCESS</status>

HTTP 1.1 POST Request


POST /b/ss//6 HTTP/1.1 Host: [rsid].112.2o7.net Keep-Alive: timeout=15 Connection: Keep-Alive Content-Length: 593 <?xml version=1.0 encoding=UTF-8?> <request> <sc_xml_ver>1.0</sc_xml_ver> <pageURL>apps.sillystring.com/summary.do</pageURL> <referrer>http://apps.sillystring.com/summary.do</referrer> <ipAddress>192.168.10.1</ipAddress> <pageName>summary</pageName> <eVar2>14911</eVar2> <userAgent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)</userAgent> <prop10>Brazil</prop10> <visitorID>1286556420966514130</visitorID> <timestamp>2009-03-05T01:00:01-05</timestamp> <reportSuiteID>[rsid]</reportSuiteID> </request>

HTTP 1.1 POST Response


HTTP/1.1 200 OK Date: Wed, 13 May 2009 16:25:12 GMT X-C: ms-3.7.2 Expires: Tue, 12 May 2009 16:25:12 GMT Last-Modified: Thu, 14 May 2009 16:25:12 GMT Cache-Control: no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform, private Pragma: no-cache ETag: "4A0AF468-4DF2-33AE9089" Vary: * P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR NID PSA OUR IND COM NAV STA" xserver: www116 Keep-Alive: timeout=15 Connection: Keep-Alive Content-Length: 40 Content-Type: text/xml

Data Insertion API

13

<?xml version="1.0" encoding="UTF-8"?> <status>SUCCESS</status>

HTTP GET Sample


This sample displays the structure of an HTTP GET request and response using the Data Insertion API. The [rsid] parameter identifies the report suite where you want to submit the data. Other values, such as PageURL, are sample values only. Note: Do not copy-and-paste these code samples. They use generic values that you must replace with valid data appropriate to your application. HTTP 1.0 GET Request
GET /b/ss/[rsid]/0?g=apps.sillystring.com%2Fsummary.do&r=http%3A%2F%2Fapps.sillystring.com% 2Fsummary.do&ip=192.168.10.1&gn= summary&v2=14911&c10=Brazil&vid=1286556420966514130&ts=2009-03-05T01%3A00%3A01-05 HTTP/1.0 Host: [rsid].112.2o7.net X-Forwarded-For: 192.168.10.1

HTTP 1.0 GET Response


HTTP/1.0 200 OK Date: Wed, 13 May 2009 16:26:47 GMT X-C: ms-3.7.2 Expires: Tue, 12 May 2009 16:26:47 GMT Last-Modified: Thu, 14 May 2009 16:26:47 GMT Cache-Control: no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform, private Pragma: no-cache ETag: "49F5FD79-3E44-38021808" Vary: * P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR NID PSA OUR IND COM NAV STA" xserver: www83 Connection: close Content-Type: text/html

HTTP 1.1 GET Request


GET /b/ss/[rsid]/0?g=apps.sillystring.com%2Fsummary.do&r=http%3A%2F%2Fapps.sillystring.com% 2Fsummary.do&ip=192.168.10.1&gn=summary&v2=14911&c10=Brazil&vid=1286556420966514130&ts=2009-03-05T01%3A00%3A01-05 HTTP/1.1 Host: [rsid].112.2o7.net Keep-Alive: timeout=15 Connection: Keep-Alive X-Forwarded-For: 192.168.10.1

HTTP 1.1 GET Response


HTTP/1.1 200 OK Date: Mon, 19 Oct 2009 17:26:24 GMT Server: Omniture DC/2.0.0 X-C: ms-4.1.3 Expires: Thu, 01 Jan 1970 00:20:55 GMT Last-Modified: Thu, 01 Jan 1970 00:20:56 GMT Cache-Control: no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform, private Pragma: no-cache ETag: "4ADCA140-6E16-1FADA4C7" Vary: * P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR NID PSA OUR IND COM NAV STA" xserver: www176 Content-Length: 43

Data Insertion API

14

Keep-Alive: timeout=15 Connection: Keep-Alive Content-Type: image/gif

Data Insertion Sample (PHP)


This PHP sample illustrates how to connect to Adobe data collection servers and record a page view.
<?/ ** * @file * Example code to send one pageview to Omniture via the Data Insertion API * and check for a valid response. * * @author Omniture, an Adobe Company <clientcare@omniture.com> * @copyright 2007-2010 Adobe Systems, Inc. All Rights Reserved. */ // NOTE: Contact an ClientCare to identify the correct namespace and domain for your company. $namespace $domain $host $rsid $vid $ip $page_url $pageName $timestamp = = = = = = = = = "namespace"; "112.2o7.net"; $namespace.".".$domain; "rsid"; ""; "10.0.0.1"; ""; "Test Page"; "2008-10-21T17:33:22-07";

// create opening XML tags $xml = "<?xml version=1.0 encoding=UTF-8?>\n"; $xml .= "<request>\n"; $xml .= " <scXmlVer>1.0</scXmlVer>\n"; // add tags for required elements $xml .= $rsid ? " <reportSuiteID>$rsid</reportSuiteID>\n":""; //The timestamp line of code can only be used when an Omniture representitive has enabled timestamp support for your organization. $xml .= $timestamp ? " <timestamp>$timestamp</timestamp>\n":""; $xml .= $vid ? " <visitorID>$vid</visitorID>\n":""; $xml .= $ip ? " <ipAddress>$ip</ipAddress>\n":""; $xml .= $page_url ? " <pageURL>$page_url</pageURL>\n":""; $xml .= $pageName ? " <pageName>$pageName</pageName>\n":""; // close the XML request $xml .= "</request>\n"; // Create POST, Host and Content-Length headers $head = "POST /b/ss//6 HTTP/1.0\n"; $head .= "Host: $host\n"; $head .= "Content-Length: ".(string)strlen($xml)."\n\n"; // combine the head and XML $request = $head.$xml; $fp=fsockopen($host,80,$errno,$errstr,30); // Use this function in place of the call above if you have PHP 4.3.0 or // higher and have compiled OpenSSL into the build. // // $fp = pfsockopen("ssl://".$host, 443, $errno, $errstr); // if( $fp ) { // send data fwrite($fp,$request);

Data Insertion API

15

// get response $response=""; while( !feof($fp) ){ $response .= fgets($fp,1028); } fclose($fp); // display results echo "RESULTS:\n"; print_r($response); echo "\n"; // check for errors if( preg_match("/status\>FAILURE\<\/status/im",$response) ){ /* * TODO: * write $request and $response to log file for investigation * and retries */ echo "<h1>Failure</h1>\n"; echo "<p>Note the reason tag in the response, fix and try again.</h1>\n"; } } else { echo "<H1>Couldn't open port to Analytics servers</H1>\n"; if(!$rsid){ echo "<H4>No report suite specified</H4>\n"; } else { echo "<p>$errstr ($errno)</p>\n"; /* * TODO: * write $request and $errstr to log file for investigation * and retries */ } } ?>

Data Insertion Sample (Java)


This Java sample illustrates how to use Java classes to send an XML request. This example sets the IP address, page name, and custom variables.
DataSubmission.java package com.omniture; import java.util.ArrayList; import java.util.Iterator; public class DataInsertion { private String rptSuiteID private String visitorID private StringBuffer buff private ArrayList<String> request

= null; = null; = null; = new ArrayList<String>();

public DataInsertion( String rsid, String vid ) { this.rptSuiteID = rsid; this.visitorID = vid; } public String toString() { buff = new StringBuffer(); buff.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); buff.append( "<request>\n" );

Data Insertion API

16

buff.append( "<sc_xml_ver>1.0</sc_xml_ver>\n" ); if( this.rptSuiteID != null ) buff.append( this.tagify( "reportsuiteid", this.rptSuiteID ) ); if( this.visitorID != null ) buff.append( this.tagify( "visitorid", this.visitorID ) ); Iterator iter = this.request.iterator(); while( iter.hasNext() ) { buff.append( iter.next() ); } buff.append( "</request>\n" ); return buff.toString(); } private String tagify( String name, String value ) { return "<" + name + ">" + value + "</" + name + ">\n"; } private String tagify( String name, char value ) { return "<" + name + ">" + value + "</" + name + ">\n"; } public void set( String tag, String value ) { this.request.add( this.tagify(tag, value) ); } public void set( String tag, char value ) { this.request.add( this.tagify(tag, value) ); } }

DataSubmission.java
package com.omniture; import import import import import java.io.BufferedReader; java.io.DataOutputStream; java.io.InputStreamReader; java.net.URL; java.net.URLConnection;

public class DataInsertionRequest { public static void main(String[] args) throws Exception { DataInsertion di = new DataInsertion( "test", "123456" ); di.set( "ipaddress", "127.0.0.1" ); di.set( "pagename", "Test Page" ); di.set( "channel", "Tests" ); di.set( "prop1", "All" ); di.set( "events", "event1" ); di.set( "evar2", "Test Page" ); di.set( "evar3", "Test Page" ); di.set( "evar4", "Test Page" ); di.set( "hier1", "Test|Test Page|All" ); URL url = null; URLConnection urlConn DataOutputStream printout = null; = null;

Data Insertion API

17

BufferedReader input = null; String u = "http://namespace.112.2o7.net/b/ss/ll/6"; String tmp = null; url = new URL( u ); urlConn = url.openConnection(); urlConn.setDoInput( true ); urlConn.setDoOutput( true ); urlConn.setUseCaches( false ); urlConn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" ); printout = new DataOutputStream(urlConn.getOutputStream());

printout.writeBytes( di.toString() ); printout.flush(); printout.close(); input ) ) ); System.out.println( di ); while( null != ( ( tmp = input.readLine() ) ) ) { System.out.println( tmp ); } printout.close(); input.close(); } } = new BufferedReader( new InputStreamReader( urlConn.getInputStream(

Data Insertion Sample (Python)


This Python sample illustrates how to access the Data Insertion API.
import httplib xml='<?xml version="1.0" encoding="UTF-8"?> <request> <scXmlVer>1.0</scXmlVer> <reportSuiteID>Corp1_rs</reportSuiteID> <timestamp>2010-03-20T10:33:22-07</timestamp> <visitorID>169</visitorID> <ipAddress>10.0.0.1</ipAddress> <pageName>Test Page</pageName></request>' conn = httplib.HTTPConnection("namespace.112.2o7.net:80") conn.request("POST", "/b/ss//6",xml ) response = conn.getresponse() print(response.status, response.reason) print(response.read())

Das könnte Ihnen auch gefallen