Documentation Center

Custom Service Worker Location

Upload the service worker to a custom location.

While extremely lightweight, the aimtell-worker.js file you need to upload is rather instrumental in enabling the logic behind our platform and web push notifications in general. In short, it enables us to listen for incoming push notifications even when someone has left your website.

The need for the file to be in the root directory actually stems from the fact that the file must be in the same directory as the page where someone wants to subscribe to notifications (a security measure enforced by Google). That means, if you place it on, then visitors can only subscribe when visiting Having it at the root path allows visitors to subscribe while on any page.

That said, while the file itself is required, you can place out outside of the root directory and still allow visitors to subscribe while on any page. It requires a couple extra technical steps but if you have a developer handy they should be able to implement it without any hassle. Here's a guide on how that can be done:

In some cases, you might find yourself unable to add the aimtell-woker.js file to the home/root directory of your website. In these cases, you can override where Aimtell looks for these files by defining them in your javascript snippet like this:

Specifying the Aimtell Worker File

Overriding the worker file is a bit more complex. The location of the worker file directly impacts which pages on your site can ask for push notifications. This is the reason for requiring it in the root directory by default.

If you can't add it to the root directory, you need to do two steps:

1. Update the worker file to pass a custom header: "Service-Worker-Allowed: /"

For instance, if you are using PHP you could create a file called updated-aimtell-worker.js.php with the following:

header('Service-Worker-Allowed: /');
header('Content-Type: application/javascript');

2. Reference the newly created file in your tracking code snippet.

After creating the above file, simply declare it using:

_at.worker = '/another/path/updated-aimtell-worker.js.php';

So it would look like:

var _at = _at || {};
_at.domain = '';
_at.owner = '76c1231hffb19e';
_at.idSite = '2634';
_at.webpushid = '';
_at.worker = '/another/path/updated-aimtell-worker.js.php';
_at.attributes = {};

(function() {
var u='//';
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'trackpush.min.js'; s.parentNode.insertBefore(g,s);