Use Google Analytics to track JavaScript errors __java

Source: Internet
Author: User
Google Analytics (Google Analytics) is not just a traffic statistics tool, you can also use it to measure the effectiveness of advertising campaigns, tracking how far users to the desired page flow (from the click Ads to the shopping cart to the checkout page), and based on the user's information to set the browser and language environment support.

But none of this is what our developers need. Today I'm going to introduce you to a very different technique for tracking JavaScript errors through custom events. Let's take a look at how to implement error checking:

Tracks basic JavaScript error messages
window.addeventlistener (' Error ', function (e) {
    _gaq.push ([
        ' _trackevent '),
        ' JavaScript Error ',
        e.message,
        e.filename + ':  ' + E.lineno,
        true
    ] ';

Trace AJAX error messages (JQuery API)
$ (document). Ajaxerror (function (e, request, settings) {
    _gaq.push ([
        ' _ Trackevent ',
        ' Ajax error ',
        Settings.url,
        e.result,
        true
    ];
};

Now, when you go into Google Analytics, you can see information about custom events while viewing other site statistics. Of course, you will tell marketers that these are not real mistakes, that is the function (laugh), that's another story. View error Reports

To have this function, first make sure that you have a Google Analytics account, check the steps: login to Google Analytics; Navigate the navigation panel on the left to find the behavior ; Click the event to view the overview;
There will be exceptions under the event category, click on the Event tab in the interface, click the dimension filter, and then you can see all the error messages that are tracked;

Custom Error Reporting

Google Analytics provides a powerful reporting customization feature, and you can customize error reporting to track information such as the operating system, browsers, and versions that generated the error. Setup steps: Find the custom feature, next to the Report tab; Click New Custom report; Generate Information = error tracking ; report Content => name = JavaScript error ; metr IC Group = all events ; dimension structure => event classification > operating system > Browser > Browser version > Event label; click Save;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.