TrackJS integrates seamlessly into your applications via a small JavaScript snippet. The installation method varies slightly depending on your application’s framework and build process. Generally, you’ll need to include the TrackJS script in your HTML, typically within the <head>
or just before the closing </body>
tag.
For most applications: You’ll obtain your unique application key from your TrackJS dashboard after creating a new application. Then include the following script, replacing YOUR_APPLICATION_KEY
with your key:
<script src="https://d16ntop171648.cloudfront.net/trackjs/track.js"></script>
<script>
.configure({
trackJstoken: 'YOUR_APPLICATION_KEY'
;
})</script>
Using a Package Manager (npm or yarn): While not strictly necessary for basic integration, using a package manager can streamline the process and help manage updates. Currently, there’s no official npm package, but you can still easily use the CDN method above.
Important Considerations: Ensure the TrackJS script is loaded after your main application JavaScript files to ensure proper error capturing. For optimal performance, consider placing it asynchronously (though not strictly required).
Beyond the application token, TrackJS offers extensive configuration options allowing customization to your specific needs. These options are set via the trackJs.configure()
method. Key configuration settings include:
token
(required): Your unique application key.application
: A string identifying your application (useful for filtering data in the dashboard).user
: An object containing user information (e.g., email
, id
). This helps contextualize errors.custom
: An object allowing you to add your own custom data to error reports. This is extremely useful for including debugging information or relevant context.console
: A boolean controlling whether errors are logged to the browser’s console.samplingRate
: A number between 0 and 1 representing the percentage of errors to be captured and sent to TrackJS. Useful for reducing data volume on high-traffic applications.Example of advanced configuration:
.configure({
trackJstoken: 'YOUR_APPLICATION_KEY',
application: 'My Awesome App',
user: { email: 'user@example.com', id: 123 },
custom: { environment: 'production', version: '1.2.3' },
console: false,
samplingRate: 0.1 // 10% sampling
; })
Refer to the full API documentation for a complete list of configuration options.
The simplest application to demonstrate TrackJS is a single HTML file with some JavaScript that intentionally throws an error. Create a file named index.html
with the following content:
<!DOCTYPE html>
<html>
<head>
<title>TrackJS Example</title>
<script src="https://d16ntop171648.cloudfront.net/trackjs/track.js"></script>
<script>
.configure({ token: 'YOUR_APPLICATION_KEY' });
trackJs
function myFunction() {
throw new Error("This is a test error!");
}
myFunction();
</script>
</head>
<body>
<h1>TrackJS Example</h1>
</body>
</html>
Replace YOUR_APPLICATION_KEY
with your actual key. Open this file in your browser. The error should be caught by TrackJS and displayed in your TrackJS dashboard.
trackJs.configure()
method to customize error reporting and add relevant context.TrackJS’s core functionality centers around robust error tracking. It captures JavaScript exceptions, AJAX errors, and unhandled promise rejections, providing detailed information to help developers quickly identify and resolve issues. This goes beyond simple stack traces, including:
TrackJS extends beyond error tracking to provide insights into your application’s performance. By monitoring key metrics such as page load times and long tasks, it helps identify performance bottlenecks. This performance monitoring enables you to proactively address slowdowns and improve the user experience. Key features include:
While not directly providing a full session recording, TrackJS provides valuable context through user-level data associated with errors and performance issues. By incorporating user identifiers in your configuration, you can see which users experienced particular errors or slowdowns, aiding in understanding user impact and prioritizing fixes. This helps target problem areas related to specific user workflows or segments.
TrackJS collects error and performance data responsibly. The amount of data collected can be controlled via the samplingRate
configuration option. Data collected includes:
TrackJS’s privacy policy should be carefully reviewed to understand its data handling practices.
Through the combination of error tracking and performance monitoring, TrackJS provides comprehensive insights into your application’s health and performance. These insights help you:
The dashboard provides various visualizations and filtering options, making it easy to analyze the data and gain valuable insights into your application’s behavior.
trackJs.configure()
The core configuration method. Use this to set various options affecting how TrackJS collects and reports data. All options are set as key-value pairs within an object.
Parameters:
options
(object): An object containing configuration options. See the Configuration section for a complete list of available options.Example:
.configure({
trackJstoken: 'YOUR_APPLICATION_KEY',
application: 'My App',
user: { id: 123, email: 'user@example.com' }
; })
Return Value: undefined
trackJs.add()
This method is generally not recommended for direct use. It’s primarily used internally by TrackJS to manage error contexts and should not be called explicitly by developers.
trackJs.remove()
Similar to trackJs.add()
, this method is generally not recommended for direct use and is primarily used internally by TrackJS.
trackJs.notify()
This method allows you to manually send a message to the TrackJS server, useful for logging custom events or application state information. This doesn’t capture an error in the same way as trackJs.capture()
, but adds a custom message to the context of your application’s activity.
Parameters:
message
(string): The message to send.data
(object, optional): Additional data to include with the message.Example:
.notify('User logged in', { userId: 123 }); trackJs
Return Value: undefined
trackJs.capture()
This method allows you to manually capture and report an error to TrackJS. Useful for handling errors that might not be automatically caught by TrackJS’s built-in exception handling.
Parameters:
error
(Error): A JavaScript Error
object representing the error.message
(string, optional): An optional message to accompany the error.data
(object, optional): Optional additional data to include with the error report.Example:
try {
// Some code that might throw an error
catch (error) {
} .capture(error, 'Custom error message', {context: 'specific function'});
trackJs }
Return Value: undefined
trackJs.send()
This method forces TrackJS to immediately send any pending error reports to the server. Generally, TrackJS handles sending asynchronously, so this method is usually unnecessary. However, it can be useful in situations where you need to guarantee data is sent before closing a connection or unloading a page.
Parameters: None
Example:
.send(); trackJs
Return Value: undefined
TrackJS doesn’t directly expose an API for handling specific error events within your application code. Error handling is largely implicit; the library catches and reports errors automatically. The configuration options, including custom data, provide control over what context is included in reports.
While TrackJS automatically captures many errors, you can add custom error handling to provide additional context or to handle specific errors differently. This typically involves using a try...catch
block to handle potential errors, adding any relevant information to trackJs.capture()
before re-throwing the error (if appropriate):
try {
// Code that might throw an error
catch (error) {
} const customData = {
userInput: document.getElementById('user-input').value,
action: 'button click'
;
}.capture(error, 'Custom Error Context', customData);
trackJs//Optionally rethrow if you want to handle the error in another way. Consider the implications of rethrowing vs. not.
//throw error;
}
Remember that even with custom handling, TrackJS will still attempt to catch any errors that escape your try...catch
blocks.
TrackJS is designed to be framework-agnostic, working effectively with most JavaScript frameworks. While there isn’t framework-specific SDKs, the core JavaScript snippet integrates easily into most environments. The key is ensuring the TrackJS script is loaded correctly within your application’s lifecycle.
General Approach: The standard integration method involves adding the TrackJS script tag to your HTML, typically within the <head>
or before the closing </body>
tag.
React, Angular, Vue, etc.: These frameworks typically handle JavaScript loading within their build process. Include the TrackJS script in your HTML template or your main application file according to your framework’s best practices. Pay attention to the timing of the script’s inclusion to ensure it executes after your application’s JavaScript.
Specific Framework Considerations:
samplingRate
configuration option to reduce the volume of data sent to your TrackJS dashboard.If you need to integrate TrackJS with a custom system or a less common framework, the flexibility of the TrackJS API allows for considerable customization. You could create a custom wrapper or integrate it into your existing logging or error-handling mechanisms.
The core interaction point is the trackJs.capture()
method, which allows you to manually send error information to TrackJS. You can send additional data providing context relevant to your custom environment. This will require a deeper understanding of your system’s architecture and error handling flows.
TrackJS is primarily focused on client-side JavaScript error tracking. There’s no direct server-side integration provided by TrackJS itself. While you can’t send server-side errors directly to TrackJS, you can integrate your server-side logging with a separate system and potentially correlate server-side events with client-side errors reported by TrackJS via shared identifiers like user IDs or session tokens. This may require custom logic to link server-side error logs and TrackJS data for a holistic view of application behavior.
Beyond the automatic error capture, TrackJS allows for highly customized error reporting. This involves using trackJs.capture()
to explicitly report errors, adding context beyond what’s automatically collected. This is crucial for scenarios where you need to include specific data relevant to the application’s state or user interaction that TrackJS might not otherwise capture. Remember that even with custom reporting, TrackJS’s built-in error handling remains active, catching any unhandled exceptions.
Enrich your error reports with custom data attributes using the custom
property in trackJs.configure()
or as part of the data
parameter in trackJs.capture()
. This allows you to include application-specific information crucial for debugging, such as user IDs, session IDs, feature flags, or other relevant contextual details. Careful planning of what data to include is essential, balancing the value of the additional context with data privacy and security considerations.
TrackJS’s dashboard provides robust filtering capabilities to efficiently analyze error data. You can filter by error message, browser, operating system, application version, and custom attributes. Effectively using custom data attributes (as described above) enhances filtering capabilities, allowing you to isolate errors affecting specific user segments or application features. The ability to effectively tag and filter errors is critical for managing and prioritizing error resolution in complex applications.
Protecting user privacy is paramount. When using TrackJS, carefully consider the data you include in error reports. Avoid including sensitive personal information (PII) such as credit card numbers, social security numbers, or precise geolocation data. If you need to include identifying information, consider using anonymized or hashed versions where possible. Review and comply with all relevant privacy regulations (GDPR, CCPA, etc.) and TrackJS’s own privacy policy.
TrackJS employs industry-standard security measures to protect the data it collects. However, it’s essential to be mindful of the security implications of the data you include in error reports. Avoid including sensitive API keys, database credentials, or other security-sensitive information. Use appropriate authentication and authorization mechanisms within your application to prevent unauthorized access to sensitive data. Refer to TrackJS’s security documentation for detailed information on their security practices.
To prevent overwhelming the TrackJS servers and to manage data volume, TrackJS may employ rate limiting. While generally not an issue for typical applications, extremely high volumes of errors could trigger rate limiting. If you’re experiencing high error rates, consider using the samplingRate
configuration option to reduce the number of errors sent to TrackJS. This reduces the load on the service while still providing a representative sample of errors for analysis. Contact TrackJS support if you believe you are encountering issues due to rate limiting.
No errors appearing in the dashboard: Double-check that you’ve correctly entered your application token in trackJs.configure()
. Ensure the TrackJS script is included correctly in your HTML and is loaded after your application’s JavaScript. Check your network settings to ensure your application can reach the TrackJS servers. Verify that the samplingRate
isn’t set to 0, effectively disabling error reporting.
Errors appear as “Uncaught Error” with no stack trace: This often indicates that the error occurred before TrackJS had a chance to fully initialize. Ensure the TrackJS script is loaded early in your HTML (ideally before other scripts).
Incorrect or incomplete error details: Verify that your source maps are correctly configured if you’re using minified or bundled JavaScript. Incomplete stack traces might also indicate issues with your JavaScript code or browser compatibility.
High error volume overwhelming the dashboard: Reduce the data volume using the samplingRate
configuration option to a value like 0.1 (10%) for production environments.
Console Logging: Add console.log
statements at various points in your code to track execution flow and identify potential error locations.
Browser Developer Tools: Use your browser’s developer tools (Network, Console, Sources tabs) to examine network requests, console logs, and the call stack of errors.
Simplify the Code: Create a minimal reproducible example to isolate the cause of the issue. This helps identify if the problem is with your application code or a conflict with TrackJS.
Check for Conflicts: Ensure there are no conflicts between TrackJS and other JavaScript libraries used in your application.
Test Environment: Replicate the issue in a controlled testing environment to better understand the context in which the error occurs.
When encountering errors, start by examining the details provided in the TrackJS dashboard. Pay close attention to:
If the error is not immediately obvious, use the debugging tips outlined above to investigate further. Refer to the TrackJS documentation and community forums for additional assistance.
TrackJS Documentation: The official TrackJS documentation provides comprehensive information on all aspects of the platform.
TrackJS Community Forums: Engage with other developers and find solutions to common problems.
TrackJS Support Team: Contact the TrackJS support team directly for personalized assistance. (Provide contact information if available – email address, support portal link, etc.)
The TrackJS dashboard provides a central location for monitoring and analyzing your application’s errors and performance. The specific layout might vary slightly over time, but generally, you’ll find sections for:
Overview: A summary of your application’s health, showing key metrics like error counts and performance statistics. This often provides a quick view of recent trends.
Errors: A detailed view of all captured errors, allowing you to filter and sort by various criteria (error message, browser, user, custom attributes, etc.). Clicking on an individual error provides detailed information, including stack traces, network requests, and custom data.
Performance: Displays performance metrics like page load times, long task durations, and potentially other key performance indicators (KPIs). This section helps identify performance bottlenecks affecting user experience.
Settings: Allows you to configure your application settings, including application details, user settings, and integration options.
Reports: (If available) Provides pre-built or customizable reports summarizing error and performance trends over time.
Navigation typically involves menus, filters, and interactive charts and tables. Familiarize yourself with the dashboard’s interface to effectively utilize its features.
TrackJS reports provide summarized views of your application’s error and performance data. Reports often include:
Error Summary: Totals and trends of error counts over specified time periods.
Error Breakdown: Distribution of errors across different browsers, operating systems, or custom attributes.
Performance Summary: Average page load times, long task counts, and other relevant performance metrics.
Impact Analysis: (If available) Provides insights into the user impact of errors and performance issues.
Trend Analysis: Displays changes in error rates and performance metrics over time.
Use reports to identify patterns, trends, and areas for improvement in your application’s reliability and performance.
Error analysis involves investigating individual errors and identifying root causes. The TrackJS dashboard facilitates this through:
Detailed Error Information: Access detailed stack traces, browser information, user context, and custom data for each error.
Error Grouping: Similar errors are grouped together, simplifying analysis and reducing noise.
Filtering and Sorting: Filter errors based on various criteria to isolate specific issues.
Trend Analysis: Track the frequency of errors over time to assess the effectiveness of bug fixes.
The goal of error analysis is to understand why errors occur, allowing you to develop effective solutions and prevent future issues.
Performance analysis focuses on identifying and addressing performance bottlenecks. TrackJS helps with this through:
Page Load Time Monitoring: Track the time it takes for your pages to load.
Long Task Identification: Pinpoint long-running JavaScript tasks that affect responsiveness.
Performance Trends: Analyze performance metrics over time to identify patterns and improvements/degradations.
Correlation with Errors: Explore if performance issues correlate with specific errors or user segments.
Performance analysis aims to improve user experience by optimizing your application’s speed and responsiveness.
Some versions of TrackJS might offer the ability to create custom dashboards. This allows you to tailor the dashboard view to your specific needs and preferences. Custom dashboards can focus on particular metrics, errors, or user segments. This feature can significantly improve the efficiency of your monitoring process by focusing on the most critical information for your application. Consult the TrackJS documentation for details on creating and managing custom dashboards if this feature is available in your plan.