This tag template implements the Javascript Handler in your webview. It creates a global object that provides an abstraction for calling the iOS or Android Firebase Analytics interfaces.
An alternative way to implement it is via the source code by your developers.
It's one of the required dependencies of the GA4 Unified Tag for Webview (Web & App) | Commands Tag implementation.
It must be added to the page before GTM starts sending events to Firebase. If added via the GTM template, use an Initialization trigger; if added via source code, ensure this code runs early in the page load process.
You do not need to use this GTM template if you have already added the handler via source code.
For more information, see the "Implement JavaScript handler" section in the Google reference article.
This tag template is designed for GTM power users with advanced implementation practices that require a robust UI.
-
Using
different
interfaces for Android and iOS
The
firebaseAnalyticsHandler
is the JavaScript Handler. For Android, the native interface is in theAnalyticsWebInterface
global variable; for iOS, it is in thefirebase
property withinwebkit.messageHandlers
. -
Using the
same
interface for both Android and iOS
The
firebaseAnalyticsHandler
is the JavaScript Handler. For both Android and iOS, the common native interface is exposed viaWebInterface.postMessage
.
- Download the
tpl
file. - In GTM, navigate to Templates > Tag Templates.
- Click New > Import.
- Select the template file and save it.
This template has been submitted to the Google Tag Manager Template Gallery. Once approved, you can search for it directly in the GTM UI.
Follow the instructions outline here.
If adding via the GTM template, use the Initialization trigger; if adding via the source code, ensure that this code runs early on the page, ideally before GTM loads.
Refer to the Examples section above for guidance.
Note: If you modify any of the JavaScript Handler or native interface names in the template, you must also update the "Accesses global variables" permissions in the Template Editor.