More finer grained web services stats

pull/14/head
Tim Su 14 years ago
parent 6060fd5ef5
commit 96ae27f16d

@ -96,8 +96,10 @@ public class StatisticsService {
String[] abAttributes = new StatisticsDependencies().abOptions.getLocalyticsAttributeArrayForEvent(event); String[] abAttributes = new StatisticsDependencies().abOptions.getLocalyticsAttributeArrayForEvent(event);
if(attributes.length > 0 || abAttributes.length > 0) { if(attributes.length > 0 || abAttributes.length > 0) {
HashMap<String, String> attrMap = new HashMap<String, String>(); HashMap<String, String> attrMap = new HashMap<String, String>();
for(int i = 1; i < attributes.length; i += 2) for(int i = 1; i < attributes.length; i += 2) {
if(attributes[i] != null)
attrMap.put(attributes[i-1], attributes[i]); attrMap.put(attributes[i-1], attributes[i]);
}
for (int i = 1; i < abAttributes.length; i += 2) for (int i = 1; i < abAttributes.length; i += 2)
attrMap.put(abAttributes[i-1], abAttributes[i]); attrMap.put(abAttributes[i-1], abAttributes[i]);
localyticsSession.tagEvent(event, attrMap); localyticsSession.tagEvent(event, attrMap);

@ -71,7 +71,6 @@ public class WebServicesView extends LinearLayout {
private LinearLayout.LayoutParams rowParams; private LinearLayout.LayoutParams rowParams;
@Autowired RestClient restClient; @Autowired RestClient restClient;
@Autowired ExceptionService exceptionService; @Autowired ExceptionService exceptionService;
@ -271,7 +270,8 @@ public class WebServicesView extends LinearLayout {
String url = String.format("http://www.amazon.com/s/?field-keywords=%s&tag=%s", String url = String.format("http://www.amazon.com/s/?field-keywords=%s&tag=%s",
URLEncoder.encode(task.getValue(Task.TITLE), "UTF-8"), ASSOCIATE_TAG); URLEncoder.encode(task.getValue(Task.TITLE), "UTF-8"), ASSOCIATE_TAG);
View view = inflateRow(body, null, moreLabel, "", url); View view = inflateRow(body, null, moreLabel, "",
new LinkTag(url, "amazon-more", null));
view.setBackgroundColor(Color.argb(128, 128, 128, 128)); view.setBackgroundColor(Color.argb(128, 128, 128, 128));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
// //
@ -288,13 +288,13 @@ public class WebServicesView extends LinearLayout {
attributes.get("title")); attributes.get("title"));
((TextView)view.findViewById(R.id.price)).setText( ((TextView)view.findViewById(R.id.price)).setText(
attributes.get("price")); attributes.get("price"));
view.setTag(attributes.get("url")); view.setTag(new LinkTag(attributes.get("url"),
"amazon", attributes.get("price")));
String subtitle = attributes.get("subtitle"); String subtitle = attributes.get("subtitle");
if(authors.size() > 0) { if(authors.size() > 0) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for(String author : authors) { for(String author : authors) {
System.err.println("AUTHOR " + author);
sb.append(author).append(", "); sb.append(author).append(", ");
} }
subtitle = sb.toString().substring(0, sb.length() - 2); subtitle = sb.toString().substring(0, sb.length() - 2);
@ -404,7 +404,9 @@ public class WebServicesView extends LinearLayout {
JSONObject result = results.getJSONObject(i); JSONObject result = results.getJSONObject(i);
String title = StringEscapeUtils.unescapeHtml(result.getString("titleNoFormatting")); String title = StringEscapeUtils.unescapeHtml(result.getString("titleNoFormatting"));
inflateRow(body, null, title, inflateRow(body, null, title,
result.getString("visibleUrl"), result.getString("url")); result.getString("visibleUrl"),
new LinkTag(result.getString("url"),
"google", null));
} }
JSONObject cursor = searchResults.getJSONObject("cursor"); JSONObject cursor = searchResults.getJSONObject("cursor");
@ -413,7 +415,8 @@ public class WebServicesView extends LinearLayout {
moreLabel = "Search Google"; moreLabel = "Search Google";
String url = cursor.getString("moreResultsUrl"); String url = cursor.getString("moreResultsUrl");
View view = inflateRow(body, null, moreLabel, "", url); View view = inflateRow(body, null, moreLabel, "",
new LinkTag(url, "google-more", null));
view.setBackgroundColor(Color.argb(128, 128, 128, 128)); view.setBackgroundColor(Color.argb(128, 128, 128, 128));
} catch (JSONException e) { } catch (JSONException e) {
@ -461,7 +464,7 @@ public class WebServicesView extends LinearLayout {
protected View inflateRow(ViewGroup body, String imageUrl, String title, String subtitle, protected View inflateRow(ViewGroup body, String imageUrl, String title, String subtitle,
String tag) { LinkTag tag) {
View view = inflater.inflate(R.layout.web_service_row, body, false); View view = inflater.inflate(R.layout.web_service_row, body, false);
AsyncImageView imageView = (AsyncImageView)view.findViewById(R.id.image); AsyncImageView imageView = (AsyncImageView)view.findViewById(R.id.image);
@ -480,13 +483,51 @@ public class WebServicesView extends LinearLayout {
return view; return view;
} }
private class LinkTag {
private final String url;
private final String servce;
private String price;
public LinkTag(String url, String servce, String price) {
this.url = url;
this.servce = servce;
this.price = price;
}
}
public OnClickListener linkClickListener = new OnClickListener() { public OnClickListener linkClickListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if(v.getTag() instanceof String) { if(v.getTag() instanceof LinkTag) {
StatisticsService.reportEvent(StatisticsConstants.IDEAS_LINK_CLICKED); LinkTag tag = (LinkTag) v.getTag();
if(tag.price != null) {
try {
double price = Double.parseDouble(tag.price.replaceAll("[^.\\d]", ""));
if(price < 5)
tag.price = "$0 - $4";
else if(price < 10)
tag.price = "$5 - $9";
else if(price < 25)
tag.price = "$10 - $24";
else if(price < 50)
tag.price = "$25 - $49";
else if(price < 100)
tag.price = "$50 - $99";
else if(price < 500)
tag.price = "$100 - $499";
else
tag.price = "$500+";
} catch(Exception e) {
tag.price = null;
}
}
StatisticsService.reportEvent(StatisticsConstants.IDEAS_LINK_CLICKED,
"service", tag.servce, "price", tag.price);
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse((String) v.getTag())); intent.setData(Uri.parse(tag.url));
activity.startActivity(intent); activity.startActivity(intent);
} }
} }

Loading…
Cancel
Save