GithubHelp home page GithubHelp logo

ebidel / appmetrics.js Goto Github PK

View Code? Open in Web Editor NEW
1.4K 24.0 67.0 53 KB

A small (< 1kb) library for measuring things in your web app and reporting the results to Google Analytics.

License: Apache License 2.0

JavaScript 95.85% HTML 4.15%
metrics appmetrics google-analytics user-timing lib

appmetrics.js's People

Contributors

ebidel avatar hermanvos avatar jeffnappi avatar oliviertassinari avatar stefanjudis avatar swizec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

appmetrics.js's Issues

ES6 modules

It would be great to support it.
For now, the best way I see to use this module is by copy-pasting the content into one of my files.

Cannot run tests from fresh install

Actual behavior

After cloning and running yarn install && npm run test you get the following error:

[email protected] test /home/mike/projects/appmetrics.js
./node_modules/mocha/bin/mocha

/home/mike/projects/appmetrics.js/test/test.js:4
const assert = chai.assert;
^

ReferenceError: chai is not defined
at Object. (/home/mike/projects/appmetrics.js/test/test.js:4:16)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at /home/mike/projects/appmetrics.js/node_modules/mocha/lib/mocha.js:222:27
at Array.forEach ()
at Mocha.loadFiles (/home/mike/projects/appmetrics.js/node_modules/mocha/lib/mocha.js:219:14)
at Mocha.run (/home/mike/projects/appmetrics.js/node_modules/mocha/lib/mocha.js:487:10)
at Object. (/home/mike/projects/appmetrics.js/node_modules/mocha/bin/_mocha:459:18)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3

Expected behavior

I can easily run tests with yarn install && npm run test. Actually needing to set up a server for the project folder is cumbersome and limits the ability for CI/CD.

Fetching the most recent entry from the performance array

if the user has made more than one measurement for the given event. Can we pop and return the last entered performance entry?
Though it is not an issue, I think, returning the last entry will be flexible. Thus, opening this issue.

Easier way to log custom timed metrics

In the first paint example

/**
 * Returns the browser's first paint metric (if available).
 * @return {number} The first paint time in ms.
 */
function getFirstPaintIfSupported() {/* ... */}

// Take measurement after page load.
window.addEventListener('load', function() {
  const fp = getFirstPaintIfSupported();
  if (fp) {
    const metric = new Metric('firstpaint');
    //If I call log here
    metric.log(); // I get firstpaint -1 ms
    // No need to call start()/end(). Can send a value, directly.
    metric.sendToAnalytics('load', metric.name, fp);
  }
});

Of course I can manually generate the log, but it could be nice if the log could take an overridable duration parameter (like sendToAnalytics):

  log(duration = this.duration) {
    console.info(this.name, this.duration, 'ms');
    return this;
  }

Or maybe a way to set the duration itself for these types of events?

set duration(duration){
  this.customDuration = duration;
  return this;
}

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.