authgear / authgear-server

Open source alternative to Auth0 / Firebase Auth
https://www.authgear.com
Apache License 2.0
81 stars 37 forks source link

GTM Integration with AuthUI #1747

Open fungc-io opened 2 years ago

fungc-io commented 2 years ago

Message

Add Google Tag Manager to Authgear. GTM is a free tool to add tracking on a website with little coding.

Background

We would like to track the channel source of our signups in the Authgear marketing site. Currently the link click to the sign up page is tracked. However we lose track after that. This is a pain point experienced by other developers as well. It will be great if we can add native GTM integration to Authgear for other creators too. In addition, this is a popular integration among SaaS, it is the most common way to add tracking to an application.

Goal and Objectives

For Example:

{
  "event":"AuthgearSignup"
}

List of events:

User flow

  1. In Portal > Integration > Google Tag Manager
  2. Set the GTM Container ID (GTM-123456) then click save.
  3. Sign up and login events are fired.

To properly set the GTM event into GA or other analytics platform like Facebook events manager. They should read the docs, which will include steps like in this article Remind the user to set up cross domain tracking to measure the number accurately.

Design: https://www.figma.com/file/swXJYkdXuPsLyA5q0aHu1r/Authgear-UI---Fung?node-id=10%3A445

Appetite

2 weeks

Reference

Ref: https://support.google.com/tagmanager/answer/7679219?hl=en Ref: https://developers.google.com/tag-platform/tag-manager/web/datalayer Ref: https://support.google.com/tagmanager/answer/6164469?hl=en

View the comment below for Technical Problems and alternative approach.

chpapa commented 2 years ago

Updated draft (not shaped, still a few research need to be done)

Objective: Make it easy for users to integrate and track signup/login sources of users from other marketing landing pages**

Technical Problems

Alternative Approach

fungc-io commented 2 years ago

Portal Design can be found here: https://www.figma.com/file/swXJYkdXuPsLyA5q0aHu1r/Authgear-UI---Fung?node-id=10%3A445

Nav item "Integration" will be between "User Profile" and "Billing"

fungc-io commented 2 years ago

@louischan-oursky The tracking across domain feature is described here: https://support.google.com/tagmanager/answer/6164469?hl=en

louischan-oursky commented 2 years ago

Our integration with Google Tag Manager is declarative. The primary button on each page has data-authgear-event attribute. The value are listed in the following list.

To integrate, the developer should follow these steps.

  1. Create a user-defined variable of Variable Type "Data Layer Variable"
  2. Set "Data Layer Variable Name" to gtm.element.dataset.authgearEvent.
  3. Create a trigger of type "Click" that fires on "Some Clicks"
  4. Add a condition to the trigger "Click Element" "matches CSS selector" "[data-authgear-event]"
  5. Create a "GA4 Configuration" tag. Set its trigger to Page View and fire "Once per page"
  6. Create a "GA4 Event" tag. Set the "Event Name" to be the gtm.element.dataset.authgearEvent variable. Set the trigger to be the trigger we created above.
louischan-oursky commented 2 years ago

https://support.google.com/tagmanager/answer/6164469?hl=en

That link is for Universal Analytics. It seems that the latest version of GA is 4. I couldn't find the equivalent for version 4. This is how I add additional domains though.

  1. Create a web Data Stream with a valid URL.
  2. Edit the data stream and click "More Tagging Settings"
  3. Click "Configure your domains"
  4. Add any additional domains
fungc-io commented 2 years ago

I was testing the setup and found that the "Sign in with Google" do not trigger the Tag for "authgear.button.oauth"


GTM Variables when Sign in with email, tag was fired

gtm_signin

GTM Variables when Sign in with Google, tag was not fired

gtm_oauth_google

Integration method was the same as commented by @louischan-oursky https://github.com/authgear/authgear-server/issues/1747#issuecomment-1073446229

louischan-oursky commented 2 years ago

The solution is to create the form submission trigger to capture this "click". The form submission trigger has an option to wait for GTM to fire the event before submitting the form. However, I cannot figure out why GTM in this particular case mistakenly detects this as a regular click instead of a form submission.