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

Add possibility to sync container files with CDN

Open tsteur opened this issue 6 years ago • 10 comments

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?

tsteur avatar Sep 20 '18 21:09 tsteur

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 🚀

mattab avatar Sep 20 '18 23:09 mattab

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.

tsteur avatar Oct 01 '18 01:10 tsteur

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.

scysys avatar Oct 02 '18 10:10 scysys

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?

lockland avatar Sep 26 '19 15:09 lockland

@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 avatar Jun 11 '20 03:06 SARAVANA1501

@SARAVANA1501 it's currently not possible to store it in the DB (which would be likely bit slow)

tsteur avatar Jun 11 '20 04:06 tsteur

@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?

SARAVANA1501 avatar Jun 11 '20 04:06 SARAVANA1501

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 avatar Jun 11 '20 04:06 tsteur

@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?

krithikabalu avatar Jun 11 '20 04:06 krithikabalu

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.

tsteur avatar Jun 11 '20 06:06 tsteur