How to track your program's exceptions via Google Analytics

In the release v.0.5.6 of our desktop software analytics library, we added the ability to remotely track your program's exceptions in Google Analytics.

When an exception is caught in your program, instead of just logging it locally, you can additionally call latSendException() to send the incident and its details to your Google Analytics property.

From there, you can remotely monitor how your application runs and what kind (if any) of exceptions it throws.

By monitoring other parameters like the OS version or the screen resolution, you can understand if there are platform parameters that trigger the exception and understand the reason behind it.

This powerful view of what is failing at the users' computers, will enable you to quickly fix any errors, even before your users report them back to you.

Software exception catching and reporting via Google Analytics
Example report in Google Analytics showing the application's crashes and exceptions.

To see the application crash and exception report, go to:

  • your Google Analytics property ->
    • Behaviour ->
      • Crashes and exceptions

As always, the reporting is at the level of "reporting view" in your Google Analytics account. For the "Crashes and exceptions" menu to be there, your reporting view must be of the "Mobile App" type. If you do not already have a "Mobile App" view, create a new one.

Below is a source code example (part of the cpp-demo-main.cpp) showing how you can send application's crashes and exceptions to Google Analytics.

// And now, some exception handling....
// ---------------------------------------
try
{
	throw std::runtime_error("TEST THROW c++ exception"); // Emulate a C++ exception
	std::cout << "try {} block completed without exceptions thrown" << std::endl;
}
// Notes about the C++ try..catch statements
// Some things are called exceptions, but they are system (or processor) errors and not C++ exceptions.
// The following catch block only catches C++ exceptions from throw, not any other kind of exceptions (e.g. null-pointer access)
// In any case, if you manage to catch the exception or the system error, you can then use latSendException() to send it to Google Analytics
catch (const std::exception& ex)
{
	std::cout << "Exception caught; will send it to G.A." << std::endl;
	std::string excDesc("Error #18471a in " __FILE__ ": ");
	excDesc += ex.what();
	if (!telemetryDll.latSendException(excDesc.c_str(), 0))
	{
		std::cerr << "Error calling latSendException\n";
		return 205;
	}
}
catch (...)
{
	std::cout << "Exception caught; will send it to G.A." << std::endl;
	if (!telemetryDll.latSendException("Error #18471b in " __FILE__, 0))
	{
		std::cerr << "Error calling latSendException\n";
		return 206;
	}
}

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

plain text with line breaks

  • Allowed HTML tags: <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <br>
  • No HTML tags allowed.
  • Lines and paragraphs break automatically.