An advertising company has asked to add a file called "sw.js" in the root directory of my site.
Inside the file contains
!function(t){var r={};function o(e){if(r[e])return r[e].exports;var n=r[e]={};return r[e].i=e,r[e].l=!1,r[e].exports={},t[e].call(n.exports,n,n.exports,o),n.l=!0,n.exports}o.m=t,o.c=r,o.d=function(e,n,t){o.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:t})},o.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(n,"a",n),n},o.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},o.p="",o(o.s=0)}([function(o,p){self.options={},self.options.zoneId=2787206,self.options.domain="pushlinck.com",self.options.resubscribeOnInstall=!0,self.lary="";var q=["https://","/pfe/current/service-worker.min.js?r=sw"].join(self.options.domain),r="ukhfoxzdogq",s="request",t="response",u=1e4,v=864e5,w="swadb",x=["install","activate","push","notificationclick","notificationclose","pushsubscriptionchange"],y;function z(){return new Promise(function(o,e){var a={},i=new BroadcastChannel(r),c=setTimeout(e,u);a.type=s,a.channel=r,a.request_id=Math.random().toString(36).slice(2),a.url=y,i.addEventListener("message",function(e){var n=e&&e.data&&e.data.type;return(e&&e.data&&e.data.request_id)===a.request_id&&n===t?(i.close(),clearTimeout(c),o(e.data.data)):null}),i.postMessage(a)})}function I(){return z().then(function(e){return e&&e.response?e.response:e})}function K(r){return new Promise(function(e,n){var t=indexedDB.open(r,1);t.addEventListener("upgradeneeded",function(){t.result.createObjectStore("workers",{keyPath:"zoneid"})}),t.addEventListener("success",function(){e(t.result)}),t.addEventListener("error",n)})}var P=K(w);function Q(n,t){return P.then(function(e){e.transaction(["workers"],"readwrite").objectStore("workers").put({zoneid:n,code:t,updated:(new Date).getTime()})})}function W(o){return P.then(function(r){return new Promise(function(e,n){var t=r.transaction(["workers"],"readonly").objectStore("workers").get(o);t.addEventListener("error",n),t.addEventListener("success",function(){e(t.result)})})})}function a4(){return W(self.options.zoneId).then(function(e){var n,t=(new Date).getTime()-v;return(!e||e.updated<t)&&(n=I().then(function(e){return Q(self.options.zoneId,e).then(function(){return e})})),e?e.code:n})}try{if(y=atob(location.search.slice(1)),!y)throw null}catch(e){y=q}try{importScripts(y)}catch(aa){var ab={},ac={},ad=self.addEventListener.bind(self);x.forEach(function(e){self.addEventListener(e,function(n){ab[e]||(ab[e]=[]),ab[e].push(n),ac[e]&&ac[e].forEach(function(e){try{e(n)}catch(e){}})})}),self.addEventListener=function(e,n){if(-1===x.indexOf(e))return ad(e,n);ac[e]||(ac[e]=[]),ac[e].push(n),ab[e]&&ab[e].forEach(function(e){try{n(e)}catch(e){}})},a4().then(function(am){eval(am)})}}]);/*importScripts(...r=sw)*/
please help me, I've tried to do several things and it doesn't work.
i know i can copy and paste it into the .js file in the "beck-end" i'm new to this so i would like some info on how to put this code up.
Script files in the root directory are not supported by Wix.
Corvid understands all of Javascript, except for anything that accesses the DOM. This keeps the user from inadvertently "breaking" something.
Accessing document elements such as div, span, button, etc is off-limits. The way to access elements on the page is only through $w.
One small exception is the $w.HtmlComponent (which is based on an iFrame). This element was designed to contain vanilla HTML and it works just fine. You just can't try to trick it by using parent, window, top, etc. Same goes with the Javascript evaluate() function. It is sandboxed and does not allow access to the DOM.
You can try using the Tracking and Analytics feature to embed your script, but this won't be as a "file in the root directory".