Skip to content

Commit fed5c17

Browse files
feat: Add Web Snippet Sample App
1 parent aebb619 commit fed5c17

File tree

8 files changed

+780
-0
lines changed

8 files changed

+780
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18.15.0
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<img src="https://static.mparticle.com/sdk/mp_logo_black.svg" width="280"><br>
2+
3+
![ts](https://badgen.net/badge/Built%20With/TypeScript/blue)
4+
5+
# The Core Snippet Sample App
6+
7+
This sample Web application will provide you with a hands-on way to understand how mParticle collects and forwards data, so you can easily implement data collection in your own projects. Throughout this application, the mParticle Web has been set up to initialize mParticle via a "snippet", capture user events and identities and forward them to mParticle.
8+
9+
By using this sample app, you will quickly learn how to:
10+
11+
- Set up mParticle's Web Snippet
12+
13+
- Collect and forward data with mParticle
14+
15+
- View incoming data events and debugging information in real time
16+
17+
- Implement data collection with mParticle's SDKs
18+
19+
## Getting Started
20+
21+
1. Open the root of this project in your IDE or Editor of choice
22+
23+
2. Install package dependencies using `npm install`
24+
25+
3. Locate `src/snippet.js` file and find the part of the code that says `REPLACE WITH API KEY`.
26+
27+
4. Update `REPLACE WITH API KEY` environment variable with with your mParticle Web API Key.
28+
29+
- If you do not have a Web API key, visit your [mParticle Workspace](https://app.mparticle.com/setup/inputs/apps), then navigate to **Setup > Inputs** in the left column to generate one.
30+
31+
5. Run the project using `npm serve`
32+
33+
This will spawn a development server which listens on port `8080` by default. Manually navigate your browser to the address that is displayed in your console. `http://127.0.0.1:8080/` by default.
34+
35+
## Events used in this app
36+
37+
To make things simple yet declarative, this application has been built in such a way to keep event tracking close to the components that might logically trigger them rather than a fully DRY implementation. We've opted to be more repetitive so examples are consise and documented as necessary.
38+
39+
Please feel free to also visit our [Doc Site](https://docs.mparticle.com/) to gain more familiarity with some of the more advanced features of mParticle.
40+
41+
## Debugging The Web SDK
42+
43+
To use this application to debug or develop the Web SDK, please check out the [mParticle Web SDK Repository](https://github.com/mParticle/mparticle-web-sdk).
44+
45+
You can run this project in conjunction with the Web SDK using `npm link` to simulate importing the Web SDK into this project.
46+
47+
To do this:
48+
49+
- It is recommended that you use [Node Version Manager (NVM)](https://github.com/nvm-sh/nvm) to make sure both your Web SDK and Sample app are on the EXACT same version of Node.
50+
51+
1. Clone the [mParticle Web SDK Repository](https://github.com/mParticle/mparticle-web-sdk) in a seperate folder on your computer.
52+
53+
2. Within your local copy of Web SDK directory:
54+
55+
- run `npm install` to install any necessary dependencies.
56+
- run `npm link` so that npm registers your current Web SDK directory.
57+
- run `npm run watch` so that mParticle rebuilds your dev instance of the SDK whenever you make a code change.
58+
59+
3. Within the `core-sample-apps/core-snippet-sample-app` directory
60+
61+
- run `npm link @mparticle/web-sdk` to link this sample app with your local instance of the Web SDK.
62+
- run `npm run serve` to activate your simple web server and navigate to the address in your console. Default should be `http://127.0.0.1:8080`
63+
- run `npm install` to install any necessary dependencies.
64+
- Modify `index.html` so that `src/snippet.js` is commented out and that the "Local Development" script tags are enabled.
65+
- Update `REPLACE WITH API KEY` within index.html with with your mParticle Web API Key.
66+
67+
## Support
68+
69+
70+
71+
## License
72+
73+
The mParticle Web SDK is available under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). See the LICENSE file for more info.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>mParticle Core Web Snippet Sample App</title>
5+
6+
<!-- Load mParticle Bundle -->
7+
<script type="text/javascript">
8+
// configure the SDK
9+
window.mParticle = {
10+
config: {
11+
// If you are doing local development, set this to false
12+
requestConfig: true,
13+
14+
flags: {},
15+
16+
logLevel: 'verbose',
17+
18+
isDevelopmentMode: true,
19+
identifyRequest: {
20+
// userIdentities: {
21+
// // email: '[email protected]',
22+
// // customerid: '123456',
23+
// },
24+
},
25+
// identityCallback: function (result) {
26+
// // Do something once an identity call has been made.
27+
// // For more information, see https://docs.mparticle.com/developers/sdk/web/idsync/#sdk-initialization-and-identify
28+
// console.log(result);
29+
// },
30+
// dataPlan: {
31+
// planId: 'my_plan_id',
32+
// planVersion: 2,
33+
// },
34+
},
35+
};
36+
</script>
37+
</head>
38+
<body>
39+
<h1>mParticle Core Web Snippet Sample App</h1>
40+
41+
<p>View the developer console for debug information</p>
42+
43+
<button id="js-log-event">Fire Event</button>
44+
45+
<!-- Disable the following to override the CDN Snippet for local development -->
46+
<script src="src/snippet.js"></script>
47+
48+
<!-- Local Development: Enable the following to override the Snippet -->
49+
<!-- <script src="node_modules/%40mparticle/web-sdk/dist/mparticle.js"></script>
50+
<script src="src/events.fns.js"></script>
51+
<script src="src/sideloadedKits.js"></script>
52+
<script>
53+
setTimeout(function () {
54+
console.log('init mParticle', window.mParticle.config);
55+
window.mParticle.init(
56+
'REPLACE WITH API KEY'
57+
window.mParticle.config
58+
);
59+
}, 100);
60+
</script> -->
61+
</body>
62+
</html>

0 commit comments

Comments
 (0)