ebidel / appmetrics.js Goto Github PK
View Code? Open in Web Editor NEWA small (< 1kb) library for measuring things in your web app and reporting the results to Google Analytics.
License: Apache License 2.0
A small (< 1kb) library for measuring things in your web app and reporting the results to Google Analytics.
License: Apache License 2.0
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
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.
My timing events were not showing up on GA.
Forcing appmetrics to send integer values for time (ms) fixed this for me
https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#timingValue
A Math.round() in sendToAnalytics() will fix this in general:
ga('send', 'timing', category, metric, Math.round(duration));
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?
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.