Skip to content

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.

License

Notifications You must be signed in to change notification settings

giovaniortolani/ga4-unified-tag-for-webview-web-app-firebase-analytics-handler-global-variable-initialization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GA4 Unified Tag for Webview (Web & App) | Firebase Analytics Handler Global Variable Initialization

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.

Preface

This tag template is designed for GTM power users with advanced implementation practices that require a robust UI.

Examples

  • Using different interfaces for Android and iOS
    image The firebaseAnalyticsHandler is the JavaScript Handler. For Android, the native interface is in the AnalyticsWebInterface global variable; for iOS, it is in the firebase property within webkit.messageHandlers.

  • Using the same interface for both Android and iOS
    image The firebaseAnalyticsHandler is the JavaScript Handler. For both Android and iOS, the common native interface is exposed via WebInterface.postMessage.

Installation & Setup

1. Import the Template into GTM

  1. Download the tpl file.
  2. In GTM, navigate to Templates > Tag Templates.
  3. Click New > Import.
  4. 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.

2. Import the GA4 Unified Tag for Webview (Web & App) | Commands Tag template into GTM

Follow the instructions outline here.

3. Tag Configuration

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.

Author(s)

Giovani Ortolani Barbosa

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published