Hi,
If anyone had a similar issue before and happened to know the answer please help me out here! Thanks in advance!
I have downloaded the sample code of DataInsertionAPI from Omniture and run it with Yell name space given by our Omniture admin.
The problem is that although the returned message was a ‘SUCCESS’ but I can not find any page views on SiteCatalyst. I’m not sure what I have missed here apart from the unspecified visitorID.
Here I’m attaching the two Java source classes and I’d like you to point out what is wrong with my code. It could be a very silly mistake and you might spot it very easily.
All you need to do is the run the main in DataInsertionRequest.java.
Please let me know if you see anything obvious.
1.
public class DataInsertionRequest {
public static void main(String[] args) throws Exception
{
SimpleDataInsertion di = new SimpleDataInsertion( "lctest", "123456" );
di.set( "ipaddress", "127.0.0.1" );
di.set( "pageName", "Test Page" );
di.set( "channel", "Tests" );
di.set( "prop1", "All" );
di.set( "eventList", "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;
BufferedReader input = null;
String u = "http://yellssldev.122.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( "PRINTING URL [[[ "+ url.toString() + " ]]]" );
while( null != ( ( tmp = input.readLine() ) ) )
{
System.out.println("PRINTING Input Stream [[[ " + tmp + " ]]" );
}
printout.close();
input.close();
}
}
2.
public class DataInsertion {
private String rptSuiteID = null;
private String visitorID = null;
private StringBuffer buff = null;
private ArrayList request = new ArrayList();
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("\n");
buff.append("1.0\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("\n");
return buff.toString();
}
private String tagify(String name, String value) {
return "<" + name + ">" + value + "\n";
}
private String tagify(String name, char value) {
return "<" + name + ">" + value + "\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));
}
public void setAllPageViewTags(PageViewObject pageObj){
Iterator key = pageObj.keySet().iterator();
while (key.hasNext()){
String name = (String) key.next();
String value = (String)pageObj.get(name);
this.request.add(this.tagify(name, value));
}
}
}
Hi there,
The second class should be SimpleDataInsertion not DataInsertion. The code is slightly different. Sorry for the confusion.
public class SimpleDataInsertion {
private String rptSuiteID = null;
private String visitorID = null;
private StringBuffer buff = null;
private ArrayList request = new ArrayList();
public SimpleDataInsertion(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("\n");
buff.append("1.0\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("\n");
return buff.toString();
}
private String tagify(String name, String value) {
return "<" + name + ">" + value + "\n";
}
private String tagify(String name, char value) {
return "<" + name + ">" + value + "\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));
}
}