Ich habe eine native Android App, die in eine WebView für den Checkout-Prozess geht. Ich implementiere appflyer, um den Umsatz über die App zu verfolgen. Wie kann ich feststellen, welche Schaltfläche auf der Seite geklickt wurde und wie hoch der Artikelpreis für den Umsatz ist?Wie kann ich einen Wert für einen Klick in einem WebView erhalten?
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import com.appsflyer.AFInAppEventParameterName;
import com.appsflyer.AFInAppEventType;
import com.appsflyer.AppsFlyerLib;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class EventActivity extends AppCompatActivity {
ProgressDialog pDialog;
Boolean redirecting = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event);
String appsFlyerUID = AppCore.getInstance(getApplicationContext()).getAppsFlyerUID();
String idfa = AppCore.getInstance(getApplicationContext()).getMixpanelAdvertisingIdentifier();
Intent intent = getIntent();
try {
JSONObject event = new JSONObject(intent.getStringExtra("event"));
String eventId = event.getString("id");
String title = event.getString("title");
String startsAt = event.getString("starts_at");
String venue = event.getString("venue");
String city = event.getString("city");
String state = event.getString("state");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
Date newDate = format.parse(startsAt);
format = new SimpleDateFormat("EEEE, MMMM d @ h:mm a");
String date = format.format(newDate);
((TextView)findViewById(R.id.event_title)).setText(title);
((TextView)findViewById(R.id.event_date)).setText(date);
((TextView)findViewById(R.id.event_venue)).setText(venue + " - " + city + ", " + state);
String url = "http://tlapi.ticketliquidator.com/event_map/" + eventId + "?utm_campaign=" + idfa + "&utm_term=" + appsFlyerUID;
Map<String, Object> eventValue = new HashMap<String, Object>();
AppsFlyerLib.getInstance().trackEvent(getApplicationContext(), "View Event " + eventId,eventValue);
final WebView wv = (WebView) findViewById(R.id.event_webview);
wv.getSettings().setJavaScriptEnabled(true);
final Activity self = this;
wv.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
redirecting = true;
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
if(redirecting){
pDialog.dismiss();
}
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if(redirecting){
pDialog = new ProgressDialog(self);
pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pDialog.setMessage(" Loading...");
pDialog.setCancelable(true);
pDialog.show();
}
}
});
pDialog = new ProgressDialog(this);
pDialog.setMessage("Getting event...");
pDialog.show();
wv.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if(progress == 100)
pDialog.dismiss();
}
});
wv.loadUrl(url);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Dies ist meine Android-Klasse für das WebView. Ich versuche, Informationen von dieser Web-Seite zu ziehen ...
Ich muß nur wissen, welche Schaltfläche in den WebView geklickt wurde, und den Preis neben dieser Schaltfläche erhalten. Dann sende ich das zur Rückverfolgung an appsflyer.