npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@itly/mparticle-web-sdk

v2.11.15

Published

mParticle core SDK for web applications

Downloads

6

Readme

mParticle Javascript SDK

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.

Documentation

Fully detailed documentation and other information about mParticle web SDK can be found at our doc site here

Include and Initialize the SDK

There are 2 ways to initialize the SDK, either via a snippet script in your HTML file, or via npm if you plan to self host. A summary of directions for both are available below, but you should review detailed directions for the snippet script and our self hosting options on our doc site.

Option 1. Load mParticle via Snippet

1. Customize the SDK

You can customize the SDK by setting the mParticle.config object prior to the SDK-download snippet.

window.mParticle = {
    config: {
        isDevelopmentMode: true,
        identifyRequest: {
            userIdentities: {
                email: '[email protected]',
                customerid: '123456',
            },
        },
        identityCallback: myIdentityCallback,
    },
};

2. Include the SDK

To integrate the SDK add the following snippet to your site after customizing mParticle.config, ideally in the <head> element. Replace YOUR_API_KEY with the API key for your mParticle Web workspace.

<script type="text/javascript">
    (function (apiKey) {
        window.mParticle = window.mParticle || {};
        window.mParticle.EventType = {Unknown:0, Navigation:1, Location:2, Search:3, Transaction:4, UserContent:5, UserPreference:6, Social:7, Other:8};
        window.mParticle.eCommerce = { Cart: {} };
        window.mParticle.Identity = {};
        window.mParticle.config = window.mParticle.config || {};
        window.mParticle.config.rq = [];
        window.mParticle.config.snippetVersion = 2.1;
        window.mParticle.ready = function (f) {
        window.mParticle.config.rq.push(f);
    };

        function a(o,t){return function(){t&&(o=t+'.'+o);var e=Array.prototype.slice.call(arguments);e.unshift(o),window.mParticle.config.rq.push(e)}}var x=['endSession','logError','logEvent','logForm','logLink','logPageView','setSessionAttribute','setAppName','setAppVersion','setOptOut','setPosition','startNewSession','startTrackingLocation','stopTrackingLocation'],y=['setCurrencyCode','logCheckout'],z=['identify','login','logout','modify'];x.forEach(function(o){window.mParticle[o]=a(o)}),y.forEach(function(o){window.mParticle.eCommerce[o]=a(o,'eCommerce')}),z.forEach(function(o){window.mParticle.Identity[o]=a(o,'Identity')});

       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/v2/' + apiKey + '/mparticle.js';
       var s = document.getElementsByTagName('script')[0];
       s.parentNode.insertBefore(mp, s);
   })('REPLACE WITH 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',
});

Option 2. Self host mParticle via npm

In your root directory:

npm i @mparticle/web-sdk
// index.js
import mParticle from '@mparticle/web-sdk'

let mParticleConfig = {
   isDevelopmentMode: true,
   identifyRequest: {
      userIdentities: { email: '[email protected]', customerid: 'h.jekyll.md' }
   },
   identityCallback: myIdentityCallback
}

mParticle.init('REPLACE WITH API KEY', mParticleConfig);

// Now you can log an event!
mParticle.logEvent('Play Movie', mParticle.EventType.Navigation, {'movie_length':'127 minutes','rating':'PG'});

Creating an Integration

If you configure mParticle via a snippet tag, the Javascript SDK is able to automatically include, initialize, and delegate API calls to 3rd-party Javascript SDKs. Otherwise you will install them via npm. For more instructions on installing via npm, view the documentation.

If you would like to add your company as a new Javascript integration, reference the following integrations as examples:

Running the Tests

Prior to running the tests please install all dev dependencies via an npm install, and build the mParticle.js file as well as the test file by running npm run build:

$ npm install
$ npm run build
$ npm run testKarma

The test script will run all tests using Karma and ChromeHeadless, and Firefox by default. To run tests using a different browser, use the command:

$ BROWSER=[browserBrand] npm run testBrowser

where browserBrand can be another browser such as Edge or IE.

Development Notes

This package comes with the NPM package pre-commit, which will run ESLint when you try to commit.

Support

[email protected]

License

The mParticle Javascript SDK is available under the Apache License, Version 2.0. See the LICENSE file for more info.