SDK DocumentationRecipesAnnouncementsSupport Forum
AndroidiOSAnnouncementsSupport Forum
SDK Documentation

Event Handling

iOS Web - Event Handling

While reading the documentation, take a look at our Sample Code.

TBLWebPageDelegate

When fetching and displaying Taboola content, you may need to handle certain events. Taboola Web Integration provides a TBLWebPageDelegate for event handling.

Available Events

didClickPlacementName

An item in the placement was clicked.

👍

Use Case

Use this method to intercept the click event, and open organic content directly within your app.

- (BOOL)webView:(WKWebView *)webView didClickPlacementName:(NSString *)placementName itemId:(NSString *)itemId clickUrl:(NSString *)clickUrl isOrganic:(BOOL)organic customData:(NSDictionary *)customData{
    // Insert your code here...
    // Return 'NO' to handle the click event yourself - or 'YES' for Taboola to handle it.
    // Note: you can override the default behavior for *organic* content only.
    return YES;
}
func webView(_ webView: WKWebView!, didClickPlacementName placementName: String!, itemId: String!, clickUrl: String!, isOrganic organic: Bool, customData: [AnyHashable : Any]!) -> Bool{
    // Insert your code here...
    // Return 'false' if you are handling the click event yourself, or 'true' if you want Taboola SDK to handle the click event.
    // Note: you can override the default behavior for *organic* content only.
    return true;
}

📘

Callback params

  • webView - A reference to your web view component.
  • placementName - The name of the clicked placement - e.g.: "Feed without video".
  • itemId - The ID of the clicked item.
  • clickUrl - The Click URL of the clicked item.
  • organic - A boolean value, indicating if the clicked item is organic. (If not, then you cannot override the click behavior.)

📘

Return value

  • Return true (or YES for Obj C) to indicate that Taboola SDK should open the Click URL.
  • Return false (or NO for Obj C) to prevent Taboola SDK from opening the Click URL (allowing you to handle it).

🚧

You can override the default behavior for organic content only.

didLoadPlacementName

The Taboola placement rendered successfully within your web content.

- (void)webView:(WKWebView *)webView didLoadPlacementName:(NSString *)placementName height:(CGFloat)height {
    NSLog(@"%@", placementName);
    // Insert your code here...
}
class MyWebViewController: TBLWebPageDelegate {

    ...

    - (void)webView:(WKWebView *)webView didLoadPlacementName:(NSString *)placementName height:(CGFloat)height
        print("Placement name: \(String(describing: placementName)) has been loaded with height: \(height)")
        // Insert your code here...
    }
}

📘

Params

  • webView - A reference to your web view component.
  • placementName - The name of the placement that rendered - e.g. "Feed without video".
  • height - The height, in pixels, of the Taboola content rendered.

didFailToLoadPlacementName

The Taboola placement failed to render within your web content.

- (void)webView:(WKWebView *)webView didFailToLoadPlacementName:(NSString *)placementName errorMessage:(NSString *)error {
    NSLog(@"%@", error);
    // Insert your code here...
}
class MyWebViewController: TBLWebPageDelegate {

    ...
    func webView(_ webView: WKWebView!, didFailToLoadPlacementName placementName: String!, errorMessage error: String!) {
        print("Error: \(String(describing: error))")
    }
}

📘

Params

  • webView - A reference to your web view component.
  • placementName - The name of the placement that failed to render - e.g. "Feed without video".
  • error - The error message. (See below for possible values.)

Possible values for error:

ValueDescription
NO_ITEMSNo Taboola content was returned.
WRONG_PARAMSThe wrong tb_mode was submitted.
RESPONSE_ERROR
TIMEOUTA connectivity issue occurred.
UNKNOWN_ERRORAn unknown error occurred.
INTERNAL_1An internal server error occurred.

Listening for errors within the JS tag

Overview

Typically, event handling is performed within your application code, as described above.

Should you choose to perform event handling within your web content, see the instructions that follow.

Code

As described under Basic Integration, each placement is implemented via a JS tag in the <body> of your web content.

You can optionally add a noContent event listener to each of those JS tags.

<script type="text/javascript">

...

_taboola.push({
    // To handle a 'nocontent' error via JS, add this code snippet:
    listenTo: "nocontent",
    handler: function(data) {
        // your error handling code goes here  
    }
});
</script>

💁🏻

Need a hand?

Go ahead! Ask a question in our Support Forum.

Tip: Provide as much detail as possible, including your platform and SDK version.