Was wondering if only gtm.js and analytics.js can be proxied via gtm server? Can't find any information about this on google docs. Also, getting an error 404 when trying to fetch it with server side gtm.
Was wondering if only gtm.js and analytics.js can be proxied via gtm server? Can't find any information about this on google docs. Also, getting an error 404 when trying to fetch it with server side gtm.
There is a bug where plugins/ua/ec.js will be fetched via https://your.domain/plugins/ua/ec.js
When that happens you have to pick that client request up and return the script manually (by writing a client template in on the server side container).
found a repo with the code example which shortened the hours I would had used otherwise. credit: https://gist.github.com/mbaersch/e94e2499ea5bb761bf81878d815fd890#file-fix-ecjs-client-tpl Here comes the important part:
const setResponseBody = require('setResponseBody');
const setResponseHeader = require('setResponseHeader');
const setResponseStatus = require('setResponseStatus');
const sendHttpGet = require('sendHttpGet');
const templateDataStorage = require('templateDataStorage');
const returnResponse = require('returnResponse');
const key = "ec.js";
if (require('getRequestPath')() === '/plugins/ua/ec.js') {
require('claimRequest')();
setResponseHeader('content-type', 'application/javascript');
const cachedBody = templateDataStorage.getItemCopy(key);
if (cachedBody) {
setResponseBody(cachedBody);
setResponseStatus(200);
returnResponse();
} else {
sendHttpGet('https://www.google-analytics.com/plugins/ua/ec.js', (statusCode, headers, body) => {
templateDataStorage.setItemCopy(key, body);
setResponseBody(body);
setResponseStatus(statusCode);
returnResponse();
});
}
}
Server-side GTM doesn't proxy js like normal GTM does. It's mostly for proxying network requests.
If you wonder if it can send enhanced ecommerce events then yes, it can.
If you wonder if it can deploy anything on the site (that includes any js files), then no, it can't. It doesn't manifest on the front-end in any way at all. It can proxy files, but all that does is rewrites the endpoint that you still have to include in your DOM.
Use front-end GTM to deploy anything on the front-end.
Stape.io have a File Proxy Client https://github.com/stape-io/file-proxy-client so you can proxy any file via your Server Side GTM container easily.
It does basically the same as what was described in the previous answer but more universal and ready to use.