matomo-org / tag-manager

Free Open Source Matomo Tag Manager - A simple way to manage and maintain all of your (third-party) tags on your website.
https://matomo.org
GNU General Public License v3.0
170 stars 58 forks source link

Priority of tags does not apply if trigger is different #786

Closed DarkLink571 closed 3 months ago

DarkLink571 commented 5 months ago

When two or more tags are fired at the same time, the priority of the tags is not used if the tags don't have the same trigger.

Steps to reproduce:

I guess this is not the expected behaviour and I haven't found an open issue for this yet.

snake14 commented 5 months ago

Hi @DarkLink571 . Thank you for taking the time to create this issue. Reading through your description, I would say that's actually the expected behaviour. If both tags used the same trigger and the priority wasn't honoured, that would be an issue. However, if they use different triggers, there isn't really a clear way to enforce the priority as they could be triggered at very different times. Even being triggered at relatively the same time, since the triggers were different, the tags are processed separately. Do you have any insights on this @AltamashShaikh ?

AltamashShaikh commented 5 months ago

@snake14 You are correct, @DarkLink571 Can you please elaborate more on what seems to be incorrect for you ?

DarkLink571 commented 4 months ago

Hi @snake14 and @AltamashShaikh If the two different triggers will trigger under the same conditions, for example when I use two pageview triggers but with different extra conditions, I would assume all tags that should be fired on a pageview will be ordered by priority, independent of the trigger that triggers them.

AltamashShaikh commented 4 months ago

@DarkLink571 Can you share the screenshot of 2 triggers ?

DarkLink571 commented 4 months ago
ConversionPageview ConversionTag Pageview SetupTag

Here is an example of what I expected to work. The setup tag should fire on every page and it is important for it to always fire before the conversion tag.

AltamashShaikh commented 4 months ago

@DarkLink571 I just tried this created a function in my HTML file where we have included the MatomoTagManagerCode.

<script>
    function trackCustom(trackingType) {
        console.log(trackingType, 'trackingType');
    }
</script>

Now created 2 tags to fire on pageView trigger

  1. Custom HTML should fire first (priority: 1) -> trackCustom('pageView');
  2. Custom HTML should fire second (priority: 10) -> trackCustom('conversion');

I can see "Custom HTML should fire first" being executed first and "Custom HTML should fire second" after that.

Screenshot from 2024-05-24 20-03-59

Screenshot from 2024-05-24 20-08-17

Just FYI. the priority should be lower if you want it to execute first.

AltamashShaikh commented 4 months ago

Custom HTML should fire first tag_first

Custom HTML should fire second tag_second

DarkLink571 commented 4 months ago

This is not exactly what I meant. In this example, the setup of the tracking function should also be done in the Tag Manager and not be hardcoded. The pageview tracking may be included in this snippet (e.g. in some Google snippets the gtag is loaded and used in the same code-block). I left out the pageview tracking since it wasn't important for the example.

The important part is: Two different tags may fire on the same event but not the same trigger. The order of the tags cannot be controlled with the priority. In the example I gave, an error may occur because the tracking function is not defined despite the tag loading the function triggers on the same event and has a higher priority.

AltamashShaikh commented 4 months ago

@DarkLink571 If its a different trigger, even though the functionality is same, it won't work the way you are saying, we would recommend you to trigger the 2nd tag on a customEvent trigger and fire the customEvent after the first tag is fired.

snake14 commented 3 months ago

Hi @DarkLink571 . We are closing this issue as we won't be changing how it currently works.