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
174 stars 58 forks source link

How to handle tags that depend on the integration of an SDK #47

Open Findus23 opened 6 years ago

Findus23 commented 6 years ago

While researching ideas for tags, I came across many tags that need the inclusion of an SDK before events or other things can be done (most famously facebook)

Now if the SDK is only needed for one tag (e.g. the facebook customer chat plugin) one could simply add the SDK to the tag, but what if there are also other facebook-related tags?

How can embedding the SDK multiple times (and setting the options every time) be avoided?

tsteur commented 6 years ago

I reckon it depends. It is even the same for Matomo. There we currently load the JS file async and check when it is loaded. There I was thinking to either have a pre-checked option "bundle Matomo JS" or always bundle the matomo.js directly into the container as the Matomo Tag will always load the JS file anyway. Although we cannot bundle matomo.js/piwik.js when the Tag is configured to be loaded from a different Matomo instance URL as the content of that piwik.js might be different to the actual piwik.js on the current instance. See https://github.com/matomo-org/tag-manager/issues/2

Bundling doesn't really work for many SDKs anyway as they become out of date. Right now I don't know out of the box how to best handle it as it varies per SDK to detect whether some library has been loaded or not. One solution could be to add some methods to TagManager like TagManager.sdk.loadFacebookSdk() and there we would know whether it has been loaded yet or not.

tsteur commented 6 years ago

Do we already have such a particular case? I would suggest we wait until we have a case, then solve it in some way and see how it goes. Can always refactor over time.