Custom Service Worker 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.
That said, while the file itself is required, you can place it outside of the root directory and still allow visitors to subscribe while on any page. It requires a couple of extra technical steps but if you have a developer handy they should be able to implement it without any hassle.
Note: While you can upload the aimtell-worker.js to any path on your site with this technique, it must still be on your site. Meaning, if your site is https://yoursite.com, the worker can not be referenced on https://anothersite.com
Setting the Path in the Dashboard
The easiest way to point Aimtell at your custom worker is from the dashboard. You will still need to upload the worker file and, in most setups, add the custom header (see step 1 and the scope section below), but you won't need to edit your tracking code.
- Open the Quick Links dropdown in the header and choose Website Settings. This opens the Update Site page.
- Open the Misc Settings tab (its panel is titled Miscellaneous Settings).
- In Service Worker Path:, enter the full path to your worker, for example
/directory/path/aimtell-worker.js.php. - Optionally, set Service Worker Scope:. If no scope is set,
/is used.
Both fields are blank by default. There's no save button; your changes save automatically when you click out of the field.
A Service Worker Path set in the dashboard overrides _at.worker in your tracking code. If the field is blank, _at.worker is used (or /aimtell-worker.js by default). The worker file still has to be uploaded and reachable at that path. Whether it also needs the Service-Worker-Allowed header depends on the scope (see below).
Dashboard changes can take up to 24 hours to reach visitors, because the site config is cached on our CDN.
Caution: Only change these fields if you know what you're doing. A wrong path or scope can break the ability for visitors to opt in to notifications on your site.
Scope and the Service-Worker-Allowed Header
Our tracking script always registers the worker with a scope. If Service Worker Scope: is blank, it uses /. Clearing the field saves it as /.
Browsers reject a scope broader than the folder the worker file is in, unless the worker response sends the Service-Worker-Allowed header. So:
- Worker at the root (for example
/aimtell-worker.js): no header needed. - Worker in a subfolder with scope
/(the default): the worker must sendService-Worker-Allowed: /. Without it, registration fails and opt-ins break. - Worker in a subfolder with scope set to that folder (for example
/directory/path/): no header needed. Visitors can still opt in on any page, including the homepage, and pushes are delivered normally.
If you go with the folder scope, make sure visitors load at least one page inside that folder. The worker only receives subscriber details from pages it controls, so without that, automatic subscription renewals by the browser can't be matched to the subscriber.
For most sites, we recommend the header with scope /.
Setting the Path in the Tracking Code
Alternatively, you can set the worker location directly in your tracking code. In this example, the worker lives at https://yoursite.com/directory/path/aimtell-worker.js.
1. Upload the worker and have it send the header
Upload your worker file to the custom path. If the scope is broader than the worker's folder (the default scope is /), the file must also send this header:
Service-Worker-Allowed: /You can usually set this in your .htaccess file or with a server-side language.
For example, with PHP you can name the worker aimtell-worker.js.php instead and set the header inside it:
<?php
header('Service-Worker-Allowed: /');
header('Content-Type: application/javascript');
?>
importScripts('https://cdn.aimtell.com/sdk/aimtell-worker-sdk.js');Then upload it to https://yoursite.com/directory/path/aimtell-worker.js.php.
2. Confirm the file loads
Open https://yoursite.com/directory/path/aimtell-worker.js.php in your browser. You should see the Aimtell worker code.

3. Set _at.worker in your tracking code
Grab your Aimtell tracking code from the dashboard and add this line (or set the path in the dashboard as described above):
_at.worker = '/directory/path/aimtell-worker.js.php';The full snippet looks like this:
<script>
var _at = _at || {};
_at.domain = 'website.com';
_at.owner = '76c1231hffb19e';
_at.idSite = '2634';
_at.webpushid = 'web.16.aimtell.com';
_at.worker = '/directory/path/aimtell-worker.js.php';
_at.attributes = {};
(function() {var u='//s3.amazonaws.com/cdn.aimtell.com/trackpush/';
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);
})();
</script>That's it. Visit your site and you should see the opt-in prompt as expected.
