Hello! This is the public repo of the mParticle Javascript SDK. We've built the mParticle platform to take a new approach to web and mobile app data and the platform has grown to support 50+ services and SDKs, including developer tools, analytics, attribution, messaging, and advertising services. mParticle is designed to serve as the connector between all of these services - check out our site, or hit us at [email protected] to learn more.
Detailed documentation and other information about mParticle SDK can be found at http://docs.mparticle.com
Once you have signed up to the mParticle platform and have a key for your App, you can begin to use the SDK by embedding the following
script tag in your web page, replacing "YOUR_API_KEY"
with your key. Note that the mParticle JS SDK and all mParticle integrations will be minified when served.
<script type="text/javascript">
(function (apiKey) {
window.mParticle = window.mParticle || {};
window.mParticle.config = window.mParticle.config || {};
window.mParticle.config.rq = [];
window.mParticle.ready = function (f) {
window.mParticle.config.rq.push(f);
};
var mp = document.createElement('script');
mp.type = 'text/javascript';
mp.async = true;
mp.src = ('https:' == document.location.protocol ? 'https://jssdkcdns' : 'http://jssdkcdn') + '.mparticle.com/js/v1/' + apiKey + '/mparticle.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(mp, s);
})('YOUR_API_KEY');
</script>
You can then log events, for example, as follows:
mParticle.logEvent('Play Movie', mParticle.EventType.Navigation, {'movie_length':'127 minutes','rating':'PG'});
Similar to other mParticle SDKs, the Javascript SDK is able to automatically include, initialize, and delegate API calls to 3rd-party Javascript SDKs. If you would like to add your company as a new Javascript integration, reference the following integrations as examples:
- AdChemix
- Amplitude
- Appboy
- BingAds
- Device Match
- Google Analytics
- Inspectlet
- Intercom
- Kahuna
- Kissmetrics
- Localytics
- Mixpanel
- Optimizely
- SimpleReach
Prior to running the tests please install all dev dependencies via an npm install:
$ npm install
A suite of test cases can be run by serving the /test
directory from a web server (such as serve),
and pointing a web browser to index.html
. This will execute the tests and also display code coverage results. Note that serving the test
directory from the file system directly will not work.
You can also run the tests by executing the npm test script:
$ npm test
The test script will use the browser-sync module to serve test/index.html
, open the tests in a browser, and auto-refresh when a change is made to mparticle.js
or any of the test files.
This package comes with the NPM package pre-commit, which will run ESLint when you try to commit.
The mParticle Javascript SDK is available under the Apache License, Version 2.0. See the LICENSE file for more info.