SDK Reference
DEPRECATION NOTICE
On March 31, 2025, Taboola will sunset SDK 2.
Before then, please make sure to migrate to SDK 4 for Android.
Feed and Widget via Native
SDK Reference | Required | Description |
---|---|---|
public TaboolaWidget setPublisher(String publisher) | Mandatory | Sets your account name (publisher) in the Widget |
public TaboolaWidget setPlacement(String placement) | Mandatory | As a part of Taboola's integration different blocks of the UI are defined in your app to be displayed in various placements. Each of these blocks have a meaningful name. Taboola's configuration relies on the placement name to serve content in the UI correctly. |
public TaboolaWidget setMode(String mode) | Mandatory | Mode is an arrangement of content items that users will see in the Widget. This is the UI Layout of your Widget. |
public TaboolaWidget setPageType(String pageType) | Mandatory | The page type is a categorization of the content in the source and target pages in your app. Taboola representatives will give you the best values to improve the recommendations returned. |
public TaboolaWidget setPageUrl(String pageUrl) | Mandatory | If you have a web site with a page that has a parallel content to the native Android page you're showing the widget in, add that page's url. If you don't have such a page, put the classpath to the relevant Activity (for example: your.package.name.MyActivity1). Note: In any case, work closely with Taboola to enter the optimal values here. |
public TaboolaWidget setTargetType(String targetType) | Optional | Default: "mix". (This can also be set via XML as target_type). Change only if instructed to do so by your Taboola account manager. |
public boolean isItemClickEnabled() - @Deprecated | Optional | Default: true. (This can also be set via XML as item_click_enabled) |
public TaboolaWidget setItemClickEnabled(boolean enabled) - @Deprecated | Optional | Enables/disables click propogation inside TaboolaWidget. |
public TaboolaWidget setAutoResizeHeight(boolean shouldAutoResize) | Optional | Default: true. Determines whether TaboolaWidget can resize when the loaded content requires it to do so (this can also be set via XML as auto_resize_height) |
public TaboolaWidget setTaboolaEventListener(TaboolaEventListener taboolaEventListener) | Optional | Attaches a TaboolaEventListener to the TaboolaWidget to enable intercepting clicks and handle height resize events |
public TaboolaWidget setOptionalPageCommands(HashMap<String, String> optionalPageCommands) | Optional | Enables pushing commands to the TaboolaWidget, as used in the Taboola JavaScript API. This sets the TaboolaWidget attributes. You can use keys from class com.taboola.android.utils.Const (This is the same as setting every attribute individually via setMode(String mode), setPublisher(String publisher), etc.) |
public void fetchContent() | Mandatory | After initializing TaboolaWidget, call this method to fetch the recommendations |
public void refresh() | Optional | Refreshes the recommendations displayed on the TaboolaWidget. |
public void setLogLevel(Logger.Level logLevel) | Optional | Set the level of log output of the widget. (the default level is ERROR) |
public void reset() | Optional | Resets the TaboolaWidget- All content and pushed commands are cleared. New commands must be pushed before fetching data again. |
public void setInterceptScroll(boolean interceptScroll) | Optional | Set whether the widget should handle the scroll automatically (see the feed section). |
public void registerScrollToTopListener(ScrollToTopListener scrollToTopListener) | Optional | A callback that notifies when the widget is on the top of the screen and is scrolled up (used for feed handling). |
public void unregisterScrollToTopListener(); | Optional | A callback that notifies when the widget is on the top of the screen and is scrolled up (used for feed handling). |
public TaboolaWidget setOptionalWidgetStyle(String newCSSStyle) | Optional | Forces CSS rules over the TaboolaWidget online HTML template |
public TaboolaWidget setUserId(String userId) | Optional | An opaque, anonymized and unique identifier of the user in the publisher’s eco-system. This identifier should be identical across applications and devices (e.g. hashed e-mail, or login). |
public TaboolaWidget.setExtraProperties(<hashmap of key and values>) | Optional | Adding an option to pass a feature flag to the SDK. |
<hashmap>('user_type','value') | Optional | An agreed enum that represents the publisher user type category (“subscriber”, “registered”, “guest”, “other”) |
<hashmap>("hideScrollingBars","false") | Optional | Hides the scrolling bars of the taboolaWidget object. The default value is false - showing the scrolling bars |
<hashmap>("allowFileAccess","false") | Optional | Preventing the Android webview from accessing local files. The default value is false |
<hashmap>("hideScrollingBars","false") | Optional | Hiding the Android webview scrolling bars from showing when using Feed. The default value is false |
<hashmap>("darkMode","true") | Optional | Enabling/disabling dark mode. Please contact your account/solution manager before using this code |
public TaboolaWidget setViewId(String userId) | Optional | Adding a unique string of digits to the TaboolaWidget . Giving the same value to other TaboolaWidget object will help avoid duplications when there are more than one Taboola asset on the screen |
Feed and Widget via JS
public class TaboolaJs
SDK Reference | Required | Description |
---|---|---|
public static TaboolaJs getInstance() | This returns a singleton instance of the SDK. | |
public TaboolaJs init(Context applicationContext) | Mandatory | This initializes TaboolaJs and requires calling before any other method of the JS SDK. This is usually performed in the Application class in OnCreate(). |
public TaboolaJs registerWebView(WebView webView) | This registers WebView within Taboola JS SDK and requires to be registered before the page is (re)loaded. It injects android.webkit.JavascriptInterface with the name declared as TaboolaJs.INJECTED_OBJECT_NAME into the given WebView .Note: When WebView is no longer needed it must be unregistered to avoid leaks. See also: TaboolaJs.unregisterWebView(WebView) | |
public TaboolaJs registerWebView(WebView webView, OnRenderListener onRenderListener) | This registers WebView within Taboola JS SDK and requires to be registered before the page is (re)loaded. it injects android.webkit.JavascriptInterface with the name declared as TaboolaJs.INJECTED_OBJECT_NAME into the given WebView .Note: When WebView is no longer needed it must be unregistered to avoid leaks. See also: TaboolaJs.unregisterWebView(WebView) | |
public TaboolaJs unregisterWebView(WebView webView) | This unregisters WebView within the Taboola JS SDK. If the Android version is HONEYCOMB (Api 11) or higher then the previously injected android.webkit.JavascriptInterface is removed.See also: TaboolaJs.registerWebView(WebView) | |
public TaboolaJs setLogLevel(int logLevel) | This sets the log level for the SDK. logLevel constants are found in the com.taboola.android.utils.Logger class, for example Logger.DEBUG. | |
public TaboolaJs setOnRenderListener(WebView webView, @Nullable OnRenderListener onRenderListener) | This registers a listener to be called when recommendations have succeeded or failed to render (called separately for each placement). | |
public TaboolaJs setOnClickListener(TaboolaOnClickListener onClickListener) | The SDK enables the user to intercept recommendation clicks, and block the default click handling for organic items. Returning false in TaboolaOnClickListener.onItemClick(String, String, String, boolean) blocks the default behavior, and enables the user to display the recommendation content on their own.Note: The return value is ignored for non-organic items. The listener is called every time a user clicks a recommendation, immediately before triggering the default behavior. |
public interface OnRenderListener
SDK Reference | Required | Description |
---|---|---|
void onRenderSuccessful(WebView webView, String placementName) | The listener to be called when recommendations have succeeded or failed (called separately for each placement). | |
void onRenderFailed(WebView webView, String placementName, String errorMessage) | The listener to be called when recommendations have succeeded or failed (called separately for each placement). |
Updated 3 months ago