Hello
The problem that it presented lies when loading a web which works with Google Analytics in my webView does not generate the connection or visualization of the web from my webView as a visit. Let me explain myself better, I am doing a project where I require that in my Java app I can load a website referring to the same project within the app but that the visit of the same be counted in Google Analytics. I am new using WebView and WebEngine tool and I hope you guys can help me with my problem.
public class browser extends JFXPanel{
private WebEngine engine;
private String sysProxy, sysProxyPort;
public browser(){
Platform.runLater(new Runnable() {
@Override
public void run() {
WebView view = new WebView();
sysProxy = System.getProperty("https.proxy");
sysProxyPort = System.getProperty("https.proxyPort");
engine = view.getEngine();
setScene(new Scene(view));
}
});
setVisible(true);
}
private void setProxySystem(){
System.setProperty("https.proxy", sysProxy);
System.setProperty("https.proxyPort", sysProxyPort);
}
public void loadURL(final String url, String userAgent){
Platform.runLater(new Runnable() {
@Override
public void run() {
String tmp =toURL(url);
if(tmp == null){
tmp = toURL(url);
}
//engine.setUserAgent(userAgent);
engine.setOnError(new EventHandler<WebErrorEvent>() {
@Override
public void handle(WebErrorEvent event) {
System.out.println("ocurrio un error al conectar");
}
});
engine.load(tmp);
}
});
}
private String toURL(String str){
try {
return new URL(str).toExternalForm();
} catch (MalformedURLException ex) {
Logger.getLogger(browser.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
}
Actually
Google Analytics
implemented in a web page that you load in a WebView is independent of enabling it in the application.Within https://analytics.google.com/analytics/ , you must make sure to create your property and obtain the script that will be inserted in your web page to track through
Google Analytics
On the side of the
WebView
actually you only need to enable JavaScript so that the script mentioned above can work and perform data logging from the web page loaded inside theWebView
:Another method for performing data logging is described here:
Add Analytics to your Android App
I found this answer on the English site that implements Google Analytics using the class
GoogleAnalyticsTracker
:https://stackoverflow.com/questions/17988618/android-webview-app-and-google-analytics