Rudi Shumpert : Code By Numbers

Twitter 2 Omniture

This is a CFML based project to search twitter and then push the data into Omniture using the Data Insertion API.

Version 2.0 of the code is posted on RIAForge!

The whole process of searching twitter and pushing the data is done with 4 steps.

1)  Use Twitter's search API to pull back a set of results.

<cfhttp url='http://search.twitter.com/search.atom?lang=en&rpp=100&phrase=#url.searchby#&since_id=#variables.tempTime#' method="GET"  resolveUrl="false" timeout="45" charset="iso-8859-1"  />

2) Convert the returned data from XML into a Struct

<cfscript>
   myxmldoc = XmlParse(cfhttp.fileContent);

</cfscript>
<!--- Convert XML results into a CFML struct for ease of traversal --->
<cfset objXml = createObject("component","cfc.xml2Struct")>
<cfset strTwitterFeed = objXml.ConvertXmlToStruct(myxmldoc, StructNew())>

This should provide a nice struct to work with like this:

Sample XML

3) Loop over new struct and build XML to send to Omniture

<cfxml variable="xml2Omniture" >
    <?xml version="1.0" encoding="utf-8" ?>
    <request>
<sc_xml_ver>1.0</sc_xml_ver>
<reportSuiteID>sitecatalyst-reportID</reportSuiteID>
<IPaddress>127.0.0.1</IPaddress>
<evar4><![CDATA[<cfoutput>#variables.searchTerm#</cfoutput>]]></evar4>
<evar5><![CDATA[<cfoutput>#variables.searchTerm#</cfoutput>]]></evar5>
<evar6>Twitter</evar6>
<evar7><![CDATA[<cfoutput>#StripTags(strTwitterFeed.entry[i].title)#</cfoutput>]]></evar7>
<evar8><![CDATA[<cfoutput>#StripTags(strTwitterFeed.entry[i].author.name)#</cfoutput>]]></evar8>
<evar9><![CDATA[<cfoutput>#StripTags(strTwitterFeed.entry[i].link_attributes.href)#</cfoutput>]]></evar9>
<pageURL>http://www.yoursitehere.com</pageURL>
<pageName>Social Media Mention</pageName>
<events>event4</events>
<prop4><![CDATA[<cfoutput>#variables.searchTerm#</cfoutput>]]></prop4>
<prop5><![CDATA[<cfoutput>#variables.searchTerm#</cfoutput>]]></prop5>
<prop6>Twitter</prop6>
<prop7><![CDATA[<cfoutput>#StripTags(strTwitterFeed.entry[i].title)#</cfoutput>]]></prop7>
<prop8><![CDATA[<cfoutput>#StripTags(strTwitterFeed.entry[i].author.name)#</cfoutput>]]></prop8>
<prop9><![CDATA[<cfoutput>#StripTags(strTwitterFeed.entry[i].link_attributes.href)#</cfoutput>]]></prop9>
<linkName>Social Media Mention</linkName>
<linkType>o</linkType>
    </request>
</cfxml>

4) Push the XML doc to Omniture

<cfhttp
url="http://reportSuite.112.2O7.net/b/ss//6"
method="POST"
useragent="#CGI.http_user_agent#"
result="objGet">
<cfhttpparam type="XML" value="#xml2Omniture#"	 />
</cfhttp>

NOTE: You have to push the XML docs to Omniture one at a time. If you try and build a single xml doc with all of the results in it, it will not work.

Version 2.0 Changes:

Code was updated to send a single XML push for each tweet found.
Omniture's Data Insertion API will not accept multiple tweets per push.

Also, I changed the structure of the XML push to add linkName & linkType.
This will keep the page view counts in Omniture from being falsely inflated due to
the push of data from twitter.

For More details on this see this post by Omniture

Omniture & Twitter

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes