0.1.1 • Published 7 years ago
hsl-matomo-tracking v0.1.1
HSL Matomo Tracking library
Development
yarn
yarn dev
Test
yarn test:with-lint
Example usage
- Install library via npm
yarn add hsl-matomo-tracking
import MatomoTracking from 'hsl-matomo-tracking';
const Matomo = new MatomoTracking(
'https://piwik.example.com/piwik.php', // endpoint of your Piwik / Matomo service
siteId, // int
'2138e7f8-1af8-11e8-accf-0ed5f89f718b' // userId UUID
);
// Data needs to be in array like that because library is using bulk requests
const result = await Matomo.postData([
{
action_name: "actionOne", // required
url: 'prefix://url/something',
},
{
action_name: "actionThree", // required
any_other_parameter_you_can_find_from: 'https://developer.matomo.org/api-reference/tracking-api',
},
]);
console.log(result); // result should be true if everything went well
Notice that there's recursive timeout loop function startTimeoutLoop
(started on class constructor by default) that calls itself every REQUEST_QUEUE_TIMEOUT
ms. Every time startTimeoutLoop is called it calls maybePostData
-function that send data to Matomo-backend if requestQueue includes data.
TODO
- Better schema validation
- Direct usage of
postToMatomo()
? - ...?
About
Based on https://github.com/krasimir/webpack-library-starter Webpack based boilerplate for producing libraries (Input: ES6, Output: universal library)
Features
- Webpack 3 based.
- ES6 as a source.
- Exports in a umd format so your library works everywhere.
- ES6 test setup with Jest.
- Linting with ESLint.
Process
ES6 source files
|
|
webpack
|
+--- babel, eslint
|
ready to use
library
in umd format
Have in mind that you have to build your library before publishing. The files under the lib
folder are the ones that should be distributed.
Getting started
- Setting up the name of your library
- Open
webpack.config.js
file and change the value oflibraryName
variable. - Open
package.json
file and change the value ofmain
property so it matches the name of your library.
- Build your library
- Run
yarn install
(recommended) ornpm install
to get the project's dependencies - Run
yarn build
ornpm run build
to produce minified version of your library.
- Development mode
- Having all the dependencies installed run
yarn dev
ornpm run dev
. This command will generate an non-minified version of your library and will run a watcher so you get the compilation on file change.
- Running the tests
- Run
yarn test
ornpm run test
Scripts
yarn build
ornpm run build
- produces production version of your library under thelib
folderyarn dev
ornpm run dev
- produces development version of your library and runs a watcheryarn test
ornpm run test
- well ... it runs the tests :)yarn test:watch
ornpm run test:watch
- same as above but in a watch mode
Readings
Misc
An example of using dependencies that shouldn’t be resolved by webpack, but should become dependencies of the resulting bundle
In the following example we are excluding React and Lodash:
{
devtool: 'source-map',
output: {
path: '...',
libraryTarget: 'umd',
library: '...'
},
entry: '...',
...
externals: {
react: 'react'
// Use more complicated mapping for lodash.
// We need to access it differently depending
// on the environment.
lodash: {
commonjs: 'lodash',
commonjs2: 'lodash',
amd: '_',
root: '_'
}
}
}