angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.23k stars 6.7k forks source link

Google Tag Manager incompatible with MatButtonModule #17199

Closed patricknee closed 4 years ago

patricknee commented 4 years ago

What are you trying to do?

Use Google Tag Manager in an Angular Material application.

Google Tag Manager is designed to allow the insertion of tags (such as Google Analytics tags) non-programmatically, for example, by targeting a trigger to an action on a button identified by an element.class or an element.id.

What troubleshooting steps have you tried?

In a simple app using Angular and Material components, I have discovered that the text of the Mat-Button is put into a mat-button-wrapper element inside the

patricknee commented 4 years ago

I guess one potential fix would be for the interior span to be assigned an ID automatically so that it can also be targeted by a GTM trigger. The GTM trigger would target (button.id || span.id).

patricknee commented 4 years ago

Resolved:

The solution in Google Tag Manager:

Enable Variable-type Click Element.

Create two triggers:

1) Trigger Type: Click-All Elements, Some Clicks, Click ID - equals - "your-id"

2) Trigger Type: Click-All Elements, Some Clicks, Click Element - Matches CSS Selector - "button#your-id span" (see image)

Then in your Tag set two triggers, one to trigger 1, the second to trigger 2.

CSS Selector Sample
angular-automatic-lock-bot[bot] commented 4 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.