tag-manager icon indicating copy to clipboard operation
tag-manager copied to clipboard

Add a way to wait for tags to finish when adding a custom event

Open Demivan opened this issue 1 year ago • 4 comments

Google Tag Manager allows to wait for all tags triggered by the event to finish running.

This is useful when you want to redirect user, but don't want browser to cancel all pending network requests.

Example code:

dataLayer.push({
  event: 'login',
  eventCallback: function () {
    window.location = uri;
  },
  eventTimeout: 2000
})

Demivan avatar Apr 04 '23 11:04 Demivan

Hi @Demivan . Thank you for taking the time to create this issue. That sounds like an interesting enhancement. Do you have any documentation about that feature in GTM?

snake14 avatar Apr 04 '23 21:04 snake14

I actually don't have any official documentation. There are just few passing mentions of this functionality in the official docs.

Here are some external explanations of this functionality: https://www.simoahava.com/gtm-tips/use-eventtimeout-eventcallback/ https://www.simoahava.com/gtm-tips/hitcallback-eventcallback/

Demivan avatar Apr 04 '23 21:04 Demivan

Implementing this would require adding functionality for async tags to indicate that they have finished running. In GTM this is done using data.gtmOnSuccess and data.gtmOnFailure methods.

Demivan avatar Apr 04 '23 21:04 Demivan

Thank you @Demivan . That gives use some more background information to go on. This issue has been added to our list for product to review and prioritise.

snake14 avatar Apr 05 '23 00:04 snake14