class eMarketerAction
This object represents an “action” (in most cases – HTML content) that you want to execute in your application. You get action objects from call to eMarketerTracker.inst.getResult()
action.getId()
int getId()
Returns the action ID that distinguishes one action from another. This is e-Marketer internal property.
action.getName()
String getName()
Returns the action name – how you called it in the e-Marketer panel. The result is never null.
action.getContentType()
String getContentType()
Returns MIME type of action’s content. It depends on action type. If you create a Banner, or a Recommendation action, the MIME type is “text/html”. In e-Marketer panel you can create action of type Javascript, and target it to the application, and the MIME type will be “application/javascript”. There is no reason to do this, because there is nothing to do with Javascript code in a mobile application. So you can decide how and whether to handle this action according to it’s MIME type.
action.getContent()
String getContent()
Returns the raw content of the action. It can be an HTML string, a JSON stringified value, or something else. The result is never null.
action.getContentJsonArray()
ArrayList<HashMap<String, String>> getContentJsonArray()
Assuming that the action raw content was a JSON stringified array of objects, this method gets the action content as ArrayList<HashMap<String, String»
. If the action’s content cannot be parsed this way, or if MIME type was not “application/json”, this method returns null.
action.getContentHtmlDoc()
String getContentHtmlDoc()
If the MIME type of the action is “text/html”, this method wraps the HTML in <html>, <head> and <body> tags, and adds all the libraries necessary to run this HTML in a WebView widget. It installs capturing onclick event handler that prevents the user from leaving this HTML page by clicking on a hyperlink.
You will want to allow javascript in this WebView by calling
webView.getSettings().setJavaScriptEnabled(true);
Or just use action.renderOnWebView()
(see below).
action.renderOnWebView()
void renderOnWebView(WebView webView) void renderOnWebView(WebView webView, final eMarketerTracker.Async<Clicked> asyncClicked)
If the MIME type of the action is “text/html”, this method renders the HTML on a provided WebView component. It uses action.getContentHtmlDoc()
to get the HTML, calls webView.getSettings().setJavaScriptEnabled(true)
to allow javascript, and installs click event handlers, that allow you to react on things clicked inside the HTML document.
When user clicks a hyperlink, the default behavior is suppressed, but you will catch this click, and get the link URL. To do this webView.addJavascriptInterface()
is utilized.
e-Marketer HTML actions can contain whatever HTML content that you put in the e-Marketer panel when you create the action. There can be hyperlinks. Also e-Marketer allows to put “close this action” buttons, so probably you want to react on them clicked too. Recommendation actions also report about recommended products clicked.
You can catch all these user-generated events through the asyncClicked
parameter. If you’re not interested in catching events, you can omit this parameter.
Here is typical usage example:
action.renderOnWebView ( webView, new eMarketerTracker.Async<eMarketerAction.Clicked>() { @Override public void callback(final eMarketerAction.Clicked clicked) { // Got event. This means that you clicked some sensitive region // I report this event to e-Marketer. So there will be CTR and close-rate statistics, and widget contribution rate (products bought from this action) eMarketerTracker.inst.reportActionClicked(clicked); // Print out the information about this click Log.w("eMarketer", String.format("clicked=%s; arg=%s; href=%s", clicked.status, clicked.arg, clicked.href)); } } );
The eMarketerAction.Clicked
is dumb structure with the following fields:
- int actionId
- String href – if a hyperlink clicked, this is it’s URL. Otherwise empty string (never null).
- String status – one of “target”, “close”, “product”, “article”.
- String arg – for a product or an article – it’s Internal ID. For “close” this is number of sessions not to show again.
If you handle this click event, report to e-Marketer about it by calling eMarketerTracker.inst.reportActionClicked(), so e-Marketer will be able to show you CTR, close-rates, recommendation contribution value, and other statistics about how this action performs.
action.reportClick()
void reportClick()
If you present this action in a custom way (not through action.renderOnWebView()
), and this action is considered “clickable”, call this method to report to e-Marketer that it was clicked. Later e-Marketer will show you CTR (percent of clicked per shown) statistics that will indicate the performance of this action.
action.reportClose()
void reportClose() void reportClose(int dontShowSessions)
If you present this action in a custom way (not through action.renderOnWebView()
), and this action is considered “closable”, call this method when you dismiss the action content from the screen as the result of user’s intent to close it (the user doesn’t want to see it). Later e-Marketer will show you close-rate (percent of closed per shown) statistics that will indicate the performance of this action.
- dontShowSessions – If provided, e-Marketer will not show (return from eMarketerTracker.inst.getResult()) this action this number of sessions. By default the session is 1.5 hours, but you can force start of new session by calling eMarketerTracker.inst.startNewSession().
action.reportProductClick()
void reportProductClick(String productId)
If you present this action in a custom way (not through action.renderOnWebView()
), and this action is showing product recommendations, call this method to report user’s click on certain product. Later e-Marketer will show you contribution rate of this action and other statistics.
- productId – the “Internal ID” column in your products catalog, that you imported to e-Marketer.
action.reportArticleClick()
void reportArticleClick(String articleId)
action.reportError()
void reportError(String message)
If something went wrong with presenting this action to the user, it’s recommended to call this method. This will set e-Marketer state of this action to “not executed”, and you will see the error message in Live Visits dashboard in the e-Marketer panel.