--- title: "Generating events" slug: "generating-events" updated: 2020-04-16T20:15:07Z published: 2020-04-16T20:15:07Z canonical: "onpremises.webtrends.help/generating-events" --- > ## Documentation Index > Fetch the complete documentation index at: https://onpremises.webtrends.help/llms.txt > Use this file to discover all available pages before exploring further. # Generating events ## Generating events through the native application WebViews embedded in a native app can generate Webtrends events using JavaScript helper methods that interact with the native app to generate and send events, or using the the Webtrends JavaScript tag in the embedded web content to generate and send events. Follow these instructions to use JavaScript helper methods. The native app must implement the Webtrends Mobile Library for Android, and contain embedded web content in a WebView. For more information, see the "Webtrends JavaScript Tag" documentation. 1. Add a custom WebViewClient to the WebView to handle communication from JavaScript in the embedded web content to the native application. - For a basic implementation, use the `extendsWebView` helper method in the `WTDataCollector` to add the Webtrends custom WebViewClient: ``` String URL = "file:///android_asset/WebContent/webViewContent.html"; WebView wv = (WebView)findViewById(R.id.webView1); wv.getSettings().setJavaScriptEnabled(true); wtdc.enableWtInWebView(wv); wv.loadUrl(URL); ``` - If your application uses its own custom WebViewClient, you should not use the `enableWtInWebView` helper method. Instead, ensure that the WTWebViewClient also gets invoked by following these steps: ``` import android.webkit.WebView; import com.webtrends.mobile.analytics.android.webViewExtension.WTWebViewClient; public class MyCustomWebViewClient extends WebtrendsWebViewClient{ @Override public void onLoadResource(WebView view, String url){ super.onLoadResource(view, url); } } String URL = "file:///android_asset/WebContent/webViewContent.html"; WebView wv = (WebView)findViewById(R.id.webView1); wv.getSettings().setJavaScriptEnabled(true); wv.setWebViewClient(new MyCustomWebViewClient()); wv.loadUrl(URL); ``` 1. Modify your custom WebViewClient to extend WTWebViewClient instead of WebViewClient. 2. If you are overriding `onLoadResource`, call `super.onLoadResource`. 3. Set your custom WebViewClient on your WebView. 2. Add `WebtrendsMobileLib.js` to the content that will be loaded in the WebView. `WebtrendsMobileLib.js` is delivered as part of the Webtrends Mobile Library for Android. 3. Use the WebtrendsLib to generate events. In the embedded web content, use the JavaScript helper functions of the webtrendsLib object to generate events through the native app. A JavaScript helper function exists for each of the event helper functions exposed in the native Webtrends SDK. The JavaScript helper functions take the same arguments as the native helper functions. ```