Agent Methods
The following methods are available on the TrackJS
namespace (since 3.0.0
) or the trackJs
namespace for earlier versions.
WARNING If you are referencing the agent as a separate script, you should perform a safety check for the existence of the TrackJS
namespace before calling any function. This will prevent your code from failing if the agent is blocked by a third-party.
addMetadata
Function
Add a key-value pair of data that will describe errors captured in this page view. You can use this to track any arbitrary data that is interesting for you, such as whether it is a paying customer, their transaction id, or anything else. These metadata key-values are sent with each error and give you the capability to filter the Dashboard in your own way.
If the metadata key already exists, it will be updated with the new value. See removeMetadata
.
param 1 | string Metadata key |
param 2 | string Metadata value for this page session. |
returns | undefined |
Since | 2.2.0 |
Example
attempt
Function
Invoke a function with a try-catch
wrapper and report any errors to TrackJS. Context to invoke the function and parameters can be passed as additional parameters.
param 1 | function Function to invoke |
param 2 | Object (Optional) Context to invoke the function on. IE, this . |
param …n | Any (Optional) Parameters to pass to the function when invoked. |
returns | * Output from the invoked function. |
Since | 1.2.0 |
Example
configure
Function
Update the Agent Config after install. Not all options can be updated, see the Changeable
flag in the Config SDK.
param 1 | Object Options to be updated |
returns | boolean true if successful |
Since | 1.0.1 |
Example
console.log
Function
Record a Telemetry event into the log with default severity. The TrackJS.console.log
function is a private clone of the global console.log
for context that is relevant for debugging, but should not be displayed in the browser console.
param …n | Any properties to be logged |
returns | undefined |
Since | 1.0.1 |
Example
console.debug
Function
Record a Telemetry event into the log with debug severity. The TrackJS.console.debug
function is a private clone of the global console.debug
for context that is relevant for debugging, but should not be displayed in the browser console.
param …n | Any properties to be logged |
returns | undefined |
Since | 1.0.1 |
Example
console.info
Function
Record a Telemetry event into the log with info severity. The TrackJS.console.info
function is a private clone of the global console.info
for context that is relevant for debugging, but should not be displayed in the browser console.
param …n | Any properties to be logged |
returns | undefined |
Since | 1.0.1 |
Example
console.warn
Function
Record a Telemetry event into the log with warning severity. The TrackJS.console.warn
function is a private clone of the global console.warn
for context that is relevant for debugging, but should not be displayed in the browser console.
param …n | Any properties to be logged |
returns | undefined |
Since | 1.0.1 |
Example
console.error
Function
Record a Telemetry event into the log with error severity. The TrackJS.console.error
function is a private clone of the global console.error
for context that is relevant for debugging, but should not be displayed in the browser console.
If the console.error
option is on, which is the default, this will also send an error report.
param …n | Any properties to be logged |
returns | undefined |
Since | 1.0.1 |
Example
install
Function
Installs the agent into the current document and start reporting errors with the provided Config options.
Before 3.0.0
, initializing the agent was automatic as soon as the script was loaded. Config was passed by creating a window._trackJs
object with the properties.
param | Config Options to install with. |
returns | boolean true if successful. |
Since | 3.0.0 |
Example
isInstalled
Function
Whether the agent has been installed into the current environment.
See install
.
returns | boolean |
Since | 3.4.0 |
Example
removeMetadata
Function
Removes a key, and any associated value, from the metadata store for this page session. The key will no longer be included with reported errors.
See addMetadata
.
param 1 | string Metadata key |
returns | undefined |
Since | 2.2.0 |
Example
track
Function
Reports an error to TrackJS immediately with the provided error. If the parameter is not an Error
, one will be generated using the serialized parameter as the message.
The reported error will include all Telemetry logged by the agent.
param 1 | Any Error to be reported |
returns | undefined |
Since | 1.2.0 |
Example
version
String
The version of the agent.
Since | 1.0.1 |
Example
watch
Function
Creates a wrapper around a function that automatically reports any errors that occur. Context for the function can be passed as additional argument.
param 1 | function Function to be wrapped. |
param 2 | Object (Optional) Context to invoke the function on. IE, this . |
returns | * Return value of the function. |
Since | 1.2.0 |
Example
watchAll
Function
Replaces all the functions on an object with watch wrappers of all the functions. This is useful for watching all the methods on a Class.
param 1 | function Function to be wrapped. |
param 2 | Object (Optional) Context to invoke the function on. IE, this . |
returns | * Return value of the function. |
Since | 1.2.0 |