tag-manager
tag-manager copied to clipboard
Add possibility to sync container files with CDN
In the beginning we would probably only support one CDN, for example Amazon CloudFront. But we would make it pluggable so any adapters can be added. @mattab as this could be useful for matomo.js tracker file as well, should be maybe instead add this feature to core and tag-manager would simply use the core feature?
It would be ideal in core 👍 considering all that we have achieved in the last few years, I feel the CDN support is the last missing piece to guarantee optimal performance at all levels in matomo 🚀
I presume many/most CDNs don't need to upload a file to the CDN but they fetch it automatically. Possibly more interesting be a feature to invalidate the cache on a CDN.
I already using it with an CDN. On the most CDN´s it makes no sense in my opinion to upload these files. They automatically fetch it and it´s just working.
Sure, an feature to invalidate the cache would be great, but it saves just an minute to login to the CDN and invalidate the cache.
I already using it with an CDN. On the most CDN´s it makes no sense in my opinion to upload these files. They automatically fetch it and it´s just working.
Sure, an feature to invalidate the cache would be great, but it saves just an minute to login to the CDN and invalidate the cache.
Hello @scysys Do you have a tutorial to do this configuration? What CDN are you using in your scenario?
@tsteur Instead save the script in CDN, Can we store the script in database and enable the endpoint to serve the script from db?
@SARAVANA1501 it's currently not possible to store it in the DB (which would be likely bit slow)
@tsteur We are trying to host tag manager in load balancing environment, I would like to contribute to this, Would you give me the technical details for CDN sync?
If you are familiar with PHP you would want to create a plugin and then listen to this event:
-
TagManager.containerFileChanged
which has an argument$file
So you could listen to that event using a method like
syncWithCdn($pathToFile) { ... do the sync logic ... }
eg like
class CDN extends \Piwik\Plugin
{
public function registerEvents()
{
return array(
'TagManager.containerFileChanged' => array('function' => 'onStaticFileChanged', 'after' => true),
);
}
public function onStaticFileChanged($file)
{
$s3Client = new S3Client();
$s3Client->putObject(basename($file), file_get_contents($file));
}
}
This is not tested but something like this should do
@tsteur can you please elaborate on "it's currently not possible to store script in the DB"? If we are able to store scripts in db and serve them through endpoint, wouldn't matomo tagmanager be independently supporting multi_server_environment?
You could also store it in DB and develop your own endpoint to serve it. It just be significantly slower compared to a CDN plus it puts more load on your DB.