JavaScript Agent injection

To instrument a website, two script tags have to be injected: an inline tag and a tag with a src-attribute. The inline tag has to be injected as the very first script and consists of essential instrumentation parts of the JavaScript Agent. For best capturing experience it is recommended that also the second tag is injected right after the inline part, but before any other JavaScript.

Asynchronous injection

For AppMon 6.5 and later, the JavaScript Agent injects asynchronously by default using the defer script tag attribute (see MDN Documentation for details).

Asynchronously loaded scripts do not block page loads, but there are a few drawbacks. Since the Agent cannot redefine any library variables if they already have been initialized (like jQuery or AngularJS), it is strictly recommended that defer is also used for any third party frameworks to be instrumented. The JavaScript Agent must be available before those frameworks start initializing, otherwise it is not possible to capture actions triggered by scripts. You can always disable asynchronous injection by clearing the Load the JavaScript Agent asynchronously check box in <System Profile> > User Experience > Web applications.

Automatic injection

The following is a sample tag combination automatically injected by the Agent as first of script tags in <head> at delivery of the web page ‐ with settings according to the configuration in System Profile > User Experience:

<script type="text/javascript">(function(){var a=window;a.dT_?a.console&&a.console.log("Duplicate agent injection detected, turning off redundant initConfig."):window.dT_||(window.dT_={cfg:"tp=0,50,10|lab=1|reportUrl=dynaTraceMonitor|agentUri= /ajax/dtagent_pqtx_7000000001289.js|auto=1|domain=#DOMAIN#|rid=RID_1640928385| rpid=1646377341|app=#APP#"})})();...</script>
<script type="text/javascript" src="/dtagent_bdpx_7000000001289.js"></script>

The first tag (without src-attribute) is the agent's initialization code. It must be delivered inline and is executed synchronously. It performs early-wrapping of native browser functions and third party libraries if available to ensure capturing can be done reliably.

The second tag requests the part of the JavaScript Agent that can be loaded asynchronously and therefore won't block a page from being loaded. The filename defines it's version and which parts of the Agent should be delivered:

  • dtagent is the JavaScript Agent Name set in System Profile > User Experience > Global Settings.
  • 7000000001289 is the AppMon Agent version (major, minor, revision, buildnumber).
    Each part of the version string consists of four characters, trimming leading zeroes, such that it is read like this: 7 0000 0000 1289, which translates to 7.0.0.1289.
  • bdpx is the feature hash, and shows information captured by the Agent, such as bandwidth, dojo, perceived render time and basic XHR detection.

Disabling JavaScript Agent Injection for a Specific Files / Locations

You can disable JavaScript Agent injection for specific files and/or locations.

To disable injection:

  1. Right click your system profile and select Edit System Profile > Agent group > Sensor Configuration item > User Experience, and click Properties.
  2. In the URI-specific injection behavior area, click +.
  3. Specify the file or location to be excluded from the injection, in the Condition and URI pattern fields. See User Experience sensor properties for parameters description.
  4. From the Injection Rule list, select do not inject on this agent, to allow agents from other groups to inject here or do not inject on this and subsequent agents, to completely disable agent injection.

Manual injection

If the preferable auto-injection is not possible you need to insert the initialization tag manually at design time as first script tag in <head>. Since the initialization tag and it's contained code varies depending on your application settings, it can easily be retrieved by using the Server REST Interfaces API using https://<AppMonServer>:8021/api/v1/profiles/<SystemProfile>/applications/<application>/javascriptagent/initcode

The initialization code performs operations to load the JavaScript Agent (either with or without the defer attribute) and updates it's configuration if required. It is not necessary to update the initialization tag every time you change the UEM configuration, though adjustments are applied faster for new visitors if you do so.