Google Analytics
On this page
Alloy Navigator ships no analytics code. To track Self Service Portal usage with Google Analytics, you add your own Google tag to the portal as a custom script file and restart the portal. The portal runs every script file in its remix\client folder whose name starts with add_ and ends with .js, as the folder stood when the portal last started.
You do this on the web server that hosts the portal: you place the file in the portal instance's folder and restart the instance from the Web Configuration tool. Writing files on the web server is an on-premises task. For Alloy Navigator Cloud, see Administering Alloy Navigator Cloud.
Prepare Google Analytics
In Google Analytics, you need a Google Analytics 4 property with a web data stream for the portal, and the Google tag of that data stream. For Google's own screens, see Set up Analytics for a website and/or app in the Analytics Help.
- Sign in to Google Analytics. If you have no Google Analytics account yet, create one.
- Create a Google Analytics 4 property.
- In the property, add a data stream for the Web platform. As the website URL, enter the address of your Self Service Portal, and give the stream a name.
- Open the data stream, click View tag instructions, and select Install manually.
- Copy the data stream's Google tag.
The Google tag consists of two HTML <script> elements: the first loads gtag.js from the address in its src attribute, and the second contains the gtag commands with your Google tag ID, which usually starts with G-. You can also find the tag ID among the data stream's details; see Find your Google tag ID. For the structure of the tag, see Set up the Google tag with gtag.js.
Create the script file
Wrap the Google tag in a JavaScript file whose name starts with add_ and ends with .js, for example add_analytics.js. The portal serves the content of the file as JavaScript, so the file contains the tag's code without its HTML <script> elements: it adds the loader script to the page and runs the tag's commands.
var imported = document.createElement('script');
imported.src = 'https://www.googletagmanager.com/gtag/js?id=TAG_ID';
document.head.appendChild(imported);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TAG_ID');
In the file, replace the address after imported.src = with the src value of your Google tag's first <script> element, and replace TAG_ID in the gtag('config', ...) line with your Google tag ID.
In the Web Configuration tool
Place the script file in the portal folder
- In the Web Configuration tool, in the tree, expand the IIS site that hosts the portal and select the portal instance. The instance is named after its virtual directory.
- On the instance's information page, in the Web category, click the Physical path: line. The instance's folder opens.
- Copy the script file into the
remix\clientfolder under that path.
Restart the portal
- In the tree, right-click the portal instance and choose Restart, or click Restart on the instance's information page.
On IIS 7 or later, the tool restarts the instance's application pool and shows a message that the instance "has been restarted". The portal starts again with the next page request; while it starts, that request shows a temporary landing page. From then on, the portal serves the new script to its visitors. A script file placed in the folder does not reach visitors until the portal's server process has been ended and started again; the Restart command of the Web Configuration tool does this.
How the portal runs the script
- The portal combines all
add_*.jsfiles of the folder into one script,add.js. The files appear in reverse name order, each headed by a comment with its file name. A file the portal cannot read is skipped and logged. - Each portal page loads the combined script and passes the current page path in the script's
locationquery parameter. The page loads the script again whenever the first part of the path below the portal root changes, so the Google tag runs again on each such navigation. - The portal lets browsers reuse a cached copy of the combined script for five minutes, and serve a cached copy while it is being refreshed for up to eight hours after that.
Update or remove the script
Edit or delete the script file in the remix\client folder, then restart the portal from the Web Configuration tool again. The portal serves the scripts from copies of that folder that it re-creates at each start, so a change made in those copies is undone at the next start. The copies are under the machine's common application data folder, in Alloy Software\<encoded instance id>\Remix.