17
Adobe ® Marketing Cloud Adobe Analytics Data Insertion API

Data insertion api

Embed Size (px)

Citation preview

Page 1: Data insertion api

Adobe® Marketing Cloud

Adobe Analytics Data Insertion API

Page 2: Data insertion api

Contents

Data Insertion API.............................................................................................................3Overview...............................................................................................................................................................................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

Adobe Analytics Data Insertion APILast updated 9/24/2013

Page 3: Data insertion api

Data Insertion APIThe 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-sidedata 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 intouser 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 URLdiffers from the standard JavaScript data submission URL. Adobe ClientCare can provide the domain name of the Adobe datacollection 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 Failureresponse. If the data insertion is successful, Adobe queues the data insertion request for processing by the standard AnalyticsData 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 inXML Data Insertion Format.

• Replace Ampersand (&), greater-than (>), and less-than (<) symbols with their HTML equivalents when passing them into aAnalytics 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. Sometools 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 exampleof this in Sample Data Insertion (PHP).

• You can use cURL to send data over an SSL connection. For information about HTTPS POST in Java, seehttp://java.sun.com/developer/technicalArticles/Security/secureinternet/.

3Data Insertion API

Page 4: 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, setServicePointManager.Expect100Continue = False. For more information, seehttp://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 thedata 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 suitewhere you want to submit the data. Adobe ClientCare can provide the domain name of the Adobe data collection servers whereyou 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 Failureresponse. If the data insertion is successful, Adobe queues the data insertion request for processing by the standard AnalyticsData 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 expirationperiod (5 years or more.)

Use the visitorID tag, the combination of IP address and userAgent, to submit visitor ID information to Adobe datacollection 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 enabledfor the visitor's Web browser. If the data insertion identifies visitors using IP address/User Agent, Analytics displays persistentcookies 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 datacollection, or a third-party application. For example, to link a visitor's browsing activity with transactions in a third-partyshopping cart application, you must pass the visitorID to the shopping cart application. The shopping cart application usesthe visitorID when uploading transaction data via the Data Insertion API so Analytics can link the transaction data to thevisitor's browsing activity (previously captured via JavaScript).

4Data Insertion API

Page 5: Data insertion api

Typically, the client systems generate unique visitor identifiers that you can use as the visitorID value. We recommendgenerating 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 visitorevents on the site. For example, if the application records page views for a given visitor 2, 4, and 5 seconds apart, send thosepage views to Analytics using the same cadence.

If the application cannot mimic the original event timing, Adobe recommends sending sequential data insertions 3 secondsapart, 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 collectionservers.

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) butyou do not need to send data for different visitors in any specific order. For example, you can submit all data for visitor A beforedata 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 thetime-stamp variable that you set. Time-stamped hits sent to a report suite that has not been enabled do not appear in thereport.

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-secondpause 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 DataSources User Guide.

5Data Insertion API

Page 6: 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 thefollowing:

• 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 thefollowing HTTP 1.1 response, the numbers 68 and 0 are chunking numbers, which represent the number of bytes to readbefore 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-partypages 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 waythat 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 datain near real-time. If clients have a JavaScript beacon implementation, and want to collect server-side data and submit it inbatches, 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.

6Data Insertion API

Page 7: 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 HTTPGET 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 headervariable 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>.

DescriptionHTTP HeaderVar

JavaScriptVariable

Query String Parameter(GET)

XML Tag (POST)

Browser height in pixels (Forexample, 768).

N/AN/Abh<browserHeight>

Browser width in pixels (Forexample, 1024).

N/AN/Abw<browserWidth>

The campaign tracking codeassociated with the page.

N/Acampaignv0<campaign>

The page title or bread crumb.N/Achannelch<channel>

Monitor color depth in bits (Forexample, 24).

N/AN/Ac<colorDepth>

Visitor's connection type ("lan" or"modem").

N/AN/Act<connectionType>

Key-values pairs are specified in oneof the following formats:

N/AcontextDatac.[key]<contextData>

<my.a>red</my.a>

or:

<my><a>red</a></my>

Each of these examples result in acontext data value of my.a = red.Multiple key-value pairs can bespecified.

In the query string, this context datavariable would appear asc.my.a=red

7Data Insertion API

Page 8: Data insertion api

DescriptionHTTP HeaderVar

JavaScriptVariable

Query String Parameter(GET)

XML Tag (POST)

Whether the visitor supports firstparty session cookies (Y or N).

N/AN/Ak<cookiesEnabled>

Revenue currency code Forexample, USD.

N/AcurrencyCodecc<currencyCode>

Analytics eVar.N/AeVar1 - eVar75v#

For example, v2.

<eVar#>

For example,<eVar2>.

A list of Analytics events.N/Aeventsevents<events>

A hierarchy string.N/Ahier1 - hier5h#

For example, h2

<hiern>

For example,<hier2>.

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

N/AN/Ahp<homePage>

The visitor's IP address.X-Forwarded-ForN/AN/A<ipaddress>

Whether the visitor has Java enabled(Y or N).

N/AN/Av<javaEnabled>

JavaScript version. For example, 1.3.N/AN/Aj<javaScriptVersion>

The browser's supported language.For example, "en-us".

Accept-LanguageN/AN/A<language>

Name of link.N/AlinkNamepev2<linkName>

Type of link ("d", "e", or "o").N/AlinkTypepe<linkType>

The link's HREF. For custom links,page values are ignored.

N/AlinkURLpev1<linkURL>

A delimited list of values that arepassed into a variable, then reported

N/Alist1 - list3l#<listn>

For example,<list2>. as individual line items for

reporting.

The Web page name.N/ApageNamepageName<pageName>

8Data Insertion API

Page 9: Data insertion api

DescriptionHTTP HeaderVar

JavaScriptVariable

Query String Parameter(GET)

XML Tag (POST)

The Web page type. This is onlyused on 404 error pages. Set

N/ApageTypepageType<pageType>

pageType to "Error Page" for whena 404 error is detected.

The Web page URL For example,http://www.mysite.com/index.html.

N/ApageURLg<pageURL>

Semicolon separated list of Netscapeplug-in names.

N/AN/Ap<plugins>

List of all products on the page.Separate products with a comma.

N/Aproductsproducts<products>

For example: Sports;Ball;1;5.95,Toys; Top;1:1.99.

Analytics property name.N/Aprop1 - prop75c#

For example, c2

<propn> For example,

<prop2>

Purchase ID number.N/ApurchaseIDpurchaseID<purchaseID>

The URL of the page referrer.N/AN/Ar<referrer>

Specifies the report suites where youwant to submit data. Separate

N/As_accountContained in the URL. SeeHTTP GET Sample.

<reportSuiteID>

multiple report suite IDs with acomma.

Monitor resolution For example,1280x1024.

N/AN/As<resolution>

Analytics XML request versionnumber. For example, 1.0.

N/AN/AN/A<scXmlVer>

The Web server serving the page.N/Aserverserver<server>

The visitor's U.S. state.N/Astatestate<state>

The time and date on which thedata was collected.

N/Atimestampts<timestamp>

9Data Insertion API

Page 10: Data insertion api

DescriptionHTTP HeaderVar

JavaScriptVariable

Query String Parameter(GET)

XML Tag (POST)

XML POST: Visitor's time zoneoffset from GMT in hours. Forexample, -8.

N/AN/APart of the t parameter<timezone>

GET: The visitor's time zone isincluded in the t query stringparameter, which contains the localtime. The t parameter is in thefollowing format:dd/mm/yyyy hh:mm:ss D OFFSET

Where D is a number in the range0-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

Common value used to tiemulti-channel user activities

N/AtransactionIDxact<transactionID>

together for reporting purposes. Formore information, see the DataSources User Guide.

The visitor's browser type and OS.User-AgentN/AN/A<userAgent>

Visitor's unique identifying cookie.See "Visitor Information" in

N/AN/Avid<visitorID>

"Understanding the Data InsertionAPI".

The visitor's zip code.N/Azipzip<zip>

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 headervariable equivalents, where applicable.

ponse messages can help you understand and correct the problem.

10Data Insertion API

Page 11: Data insertion api

DescriptionPOST Response

Success (general)<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0"

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

Failure (general)<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0"

encoding="UTF-8"?><status>FAILURE</status>

Failure (missing required report suite id)<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0"

encoding="UTF-8"?><status>FAILURE</status> <reason>NO

account</reason>

Failure (missing required page name orpage URL)

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

encoding="UTF-8"?><status>FAILURE</status> <reason>NO pagename

OR pageurl</reason>

Failure (missing required visitor id or IPaddress)

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

encoding="UTF-8"?><status>FAILURE</status> <reason>NO

visitorid OR ipaddress</reason>

Failure (syntax error: includes malformedXML, non-encoded reserved characters,etc.)

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

encoding="UTF-8"?><status>FAILURE</status> <reason>Syntax

Error</reason>

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 appropriateto 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 appropriateto your application.

The [rsid] parameter identifies the report suite where you want to submit the data. Other values, such as PageURL, are samplevalues only.

HTTP 1.0 POST RequestPOST /b/ss//6 HTTP/1.0Host: [rsid].112.2o7.netContent-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>

11Data Insertion API

Page 12: Data insertion api

<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 ResponseHTTP/1.1 200 OKDate: Wed, 13 May 2009 16:26:47 GMTX-C: ms-3.7.2Expires: Tue, 12 May 2009 16:26:47 GMTLast-Modified: Thu, 14 May 2009 16:26:47 GMTCache-Control: no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform, privatePragma: no-cacheETag: "4A0AF4C7-08E1-37C7F492"Vary: *P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR NID PSA OUR IND COM NAV STA"xserver: www79Connection: closeContent-Type: text/xml<?xml version="1.0" encoding="UTF-8"?><status>SUCCESS</status>

HTTP 1.1 POST RequestPOST /b/ss//6 HTTP/1.1Host: [rsid].112.2o7.netKeep-Alive: timeout=15Connection: Keep-AliveContent-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 ResponseHTTP/1.1 200 OKDate: Wed, 13 May 2009 16:25:12 GMTX-C: ms-3.7.2Expires: Tue, 12 May 2009 16:25:12 GMTLast-Modified: Thu, 14 May 2009 16:25:12 GMTCache-Control: no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform, privatePragma: no-cacheETag: "4A0AF468-4DF2-33AE9089"Vary: *P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR NID PSA OUR IND COM NAV STA"xserver: www116Keep-Alive: timeout=15Connection: Keep-AliveContent-Length: 40Content-Type: text/xml

12Data Insertion API

Page 13: Data insertion api

<?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 samplevalues only.

Note: Do not copy-and-paste these code samples. They use generic values that you must replace with valid data appropriateto your application.

HTTP 1.0 GET RequestGET /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.0Host: [rsid].112.2o7.netX-Forwarded-For: 192.168.10.1

HTTP 1.0 GET ResponseHTTP/1.0 200 OKDate: Wed, 13 May 2009 16:26:47 GMTX-C: ms-3.7.2Expires: Tue, 12 May 2009 16:26:47 GMTLast-Modified: Thu, 14 May 2009 16:26:47 GMTCache-Control: no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform, privatePragma: no-cacheETag: "49F5FD79-3E44-38021808"Vary: *P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR NID PSA OUR IND COM NAV STA"xserver: www83Connection: closeContent-Type: text/html

HTTP 1.1 GET RequestGET /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.1Host: [rsid].112.2o7.netKeep-Alive: timeout=15Connection: Keep-AliveX-Forwarded-For: 192.168.10.1

HTTP 1.1 GET ResponseHTTP/1.1 200 OKDate: Mon, 19 Oct 2009 17:26:24 GMTServer: Omniture DC/2.0.0X-C: ms-4.1.3Expires: Thu, 01 Jan 1970 00:20:55 GMTLast-Modified: Thu, 01 Jan 1970 00:20:56 GMTCache-Control: no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform, privatePragma: no-cacheETag: "4ADCA140-6E16-1FADA4C7"Vary: *P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR NID PSA OUR IND COM NAV STA"xserver: www176Content-Length: 43

13Data Insertion API

Page 14: Data insertion api

Keep-Alive: timeout=15Connection: Keep-AliveContent-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 <[email protected]> * @copyright 2007-2010 Adobe Systems, Inc. All Rights Reserved. */ // NOTE: Contact an ClientCare to identify the correct namespace and domain for your company.

$namespace = "namespace";$domain = "112.2o7.net";$host = $namespace.".".$domain;$rsid = "rsid";$vid = "";$ip = "10.0.0.1";$page_url = "";$pageName = "Test Page"; $timestamp = "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 datafwrite($fp,$request);

14Data Insertion API

Page 15: Data insertion api

// get response$response="";while( !feof($fp) ){ $response .= fgets($fp,1028);}fclose($fp);

// display resultsecho "RESULTS:\n";print_r($response);echo "\n";

// check for errorsif( 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.javapackage com.omniture;

import java.util.ArrayList;import java.util.Iterator;

public class DataInsertion{ private String rptSuiteID = null; private String visitorID = null; private StringBuffer buff = null; private ArrayList<String> request = 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" );

15Data Insertion API

Page 16: Data insertion api

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.javapackage com.omniture;

import java.io.BufferedReader;import java.io.DataOutputStream;import java.io.InputStreamReader;import java.net.URL;import 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 = null; DataOutputStream printout = null;

16Data Insertion API

Page 17: Data insertion api

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 = new BufferedReader( new InputStreamReader( urlConn.getInputStream( ) ) );

System.out.println( di ); while( null != ( ( tmp = input.readLine() ) ) ) { System.out.println( tmp ); } printout.close(); input.close(); }

}

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())

17Data Insertion API