简体   繁体   English

iOS中的WebView中的Flurry Analytics

[英]Flurry Analytics in a WebView in iOS

In my iOS Application I want to use Flurry analytics. 在我的iOS应用程序中,我想使用Flurry分析。 On one of the application's screen there is UIWebView. 在应用程序的屏幕之一上,有UIWebView。 And the site is on the server but not in the code of App. 该站点位于服务器上,但不在App代码中。 And every time when I loading that screen, information going from the server to my screen and everything is OK. 每次我加载该屏幕时,信息都会从服务器传到我的屏幕,一切正常。 There is a lot of buttons on my WebView and I want track them when they are pressed. WebView上有很多按钮,我想在按下按钮时对其进行跟踪。 I read about how to implement flurry analytics into the code of App if the buttons are in the code of App, but if the buttons are on the side of server(html/css/JS) I can't understand how can I track events from the UIWebView over the App to Flurry. 如果按钮在App的代码中,我就读到了如何在应用的代码中实施波动分析,但是如果按钮在服务器端(html / css / JS),我不明白如何跟踪事件从应用程序的UIWebView到Flurry。

Flurry is writing this: Flurry在写这个:

Can I track Events (eg pressing of a button) with Flurry Analytics if my app is a wrapper to my mobile website? 如果我的应用程序是我的移动网站的包装,是否可以使用Flurry Analytics跟踪事件(例如,按下按钮)? The actions take place on the site server that the app is wrapping. 这些操作在应用程序包装的站点服务器上进行。


Yes, you can track these Events. 是的,您可以跟踪这些事件。 If the action you want to track (eg button pressing) exists in the app code, then simply log an Event on the app side. 如果您要跟踪的动作(例如,按下按钮)存在于应用程序代码中,则只需在应用程序端记录一个事件。 If the button exists on the mobile webpage shown in a Web View, you will need to inject a Javascript function that will fire off an additional custom URL when the button is pressed. 如果该按钮存在于Web视图中显示的移动网页上,则您需要注入Javascript函数,该函数将在按下按钮时触发其他自定义URL。 This URL will have a custom scheme, for example, “myapp://buttonclicked”. 该URL将具有一个自定义方案,例如“ myapp:// buttonclicked”。 Then in the app code, you will need to capture that URL before your Web View fires it. 然后在应用程序代码中,您将需要在Web View触发之前捕获该URL。 When you see that the URL is your specified URL (“myapp://...”), you can log an Event on the app side. 当您看到该URL是您指定的URL(“ myapp:// ...”)时,可以在应用程序端记录一个事件。

There are several ways to capture the custom URL before it is loaded by the Web View. 在Web视图加载自定义URL之前,有几种捕获自定义URL的方法。 In iOS you would need to implement the UIWebViewDelegate method webView:shouldStartLoadWithRequest:navigationType:. 在iOS中,您需要实现UIWebViewDelegate方法webView:shouldStartLoadWithRequest:navigationType:。 On Android, you could implement a WebViewClient with the shouldOverrideUrlLoading method. 在Android上,您可以使用shouldOverrideUrlLoading方法实现WebViewClient。

you can easily catch webview events through a delegate method 您可以通过委托方法轻松捕获webview事件

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)请求导航类型:(UIWebViewNavigationType)navigationType

bellow is that sample code, I used in on of my application: 下面是我在应用程序中使用的示例代码:

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
    navigationType:(UIWebViewNavigationType)navigationType  
{

    if([[[request URL] absoluteString] rangeOfString:@"payment_successful_mobile.php"].location != NSNotFound)
        return YES; 

    if([[[request URL] absoluteString] rangeOfString:@"index.php?file=c-my_campaingns"].location != NSNotFound)
    {
        [self onClickBackButton:nil];
        return NO;
    }
    if([[[request URL] absoluteString] rangeOfString:@"Timeout"].location != NSNotFound)
    {
        [self performSelectorOnMainThread:@selector(displayTimeOutMessage) withObject:nil waitUntilDone:NO];
        return NO;
    }
    return YES;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM