0

In my iOS Application I want to use Flurry analytics. On one of the application's screen there is UIWebView. And the site is on the server but not in the code of 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. 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.

Flurry is writing this:

Can I track Events (e.g. pressing of a button) with Flurry Analytics if my app is a wrapper to my mobile website? 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 (e.g. 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. This URL will have a custom scheme, for example, “myapp://buttonclicked”. Then in the app code, you will need to capture that URL before your Web View fires it. When you see that the URL is your specified URL (“myapp://...”), you can log an Event on the app side.

There are several ways to capture the custom URL before it is loaded by the Web View. In iOS you would need to implement the UIWebViewDelegate method webView:shouldStartLoadWithRequest:navigationType:. On Android, you could implement a WebViewClient with the shouldOverrideUrlLoading method.

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
Alex
  • 3
  • 4
  • Welcome to Stack Overflow. Just to let you know, your question as it stands does not provide enough detail. At a minimum, you should provide a relevant sample or two of the code you have. I invite to to browse the site to get a feel for the sorts of questions that are asked, and then come back and add the relevant details. – McMath Feb 23 '16 at 21:59

1 Answers1

0

you can easily catch webview events through a delegate method

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(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;
}
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
Usman Nisar
  • 3,031
  • 33
  • 41
  • D I need to change something on server? Because flurry is writing that I need to make some Javascript function that will fire off an additional custom URL when the button is pressed. – Alex Feb 25 '16 at 00:09
  • I think No need to change in log, just add a log in above delegate, and observe what URL are loaded on each button click – Usman Nisar Feb 25 '16 at 06:40