Skip to content

Commit 8192744

Browse files
committed
Add WebView plugin (#1402)
* Add plugin based on my local webview tracker * Use webview tracker symlink * Correctly parse base64-encoded payloads * Parse string numbers * Add namespaces config option * Remove unused callback * Add docstring * Fix self-desc events * Use actual webview tracker * Run rush change
1 parent 4fffbca commit 8192744

File tree

15 files changed

+2433
-1823
lines changed

15 files changed

+2433
-1823
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-plugin-webview",
5+
"comment": "Add WebView plugin (#1402)",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-webview"
10+
}

common/config/rush/browser-approved-packages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@
166166
"name": "@snowplow/tracker-core",
167167
"allowedCategories": [ "libraries", "plugins", "trackers" ]
168168
},
169+
{
170+
"name": "@snowplow/webview-tracker",
171+
"allowedCategories": [ "plugins" ]
172+
},
169173
{
170174
"name": "@testing-library/dom",
171175
"allowedCategories": [ "libraries" ]

common/config/rush/pnpm-lock.yaml

Lines changed: 1836 additions & 1822 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/config/rush/repo-state.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
22
{
3-
"pnpmShrinkwrapHash": "d1933251824ef3eb837586f089856ce0f6036111",
3+
"pnpmShrinkwrapHash": "bf29537a7fb7a501d796ce47e6bdb37daa9b0507",
44
"preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f"
55
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "@snowplow/browser-plugin-webview",
3+
"entries": [
4+
]
5+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2024 Snowplow Analytics Ltd
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Snowplow WebView Plugin
2+
3+
[![npm version][npm-image]][npm-url]
4+
[![License][license-image]](LICENSE)
5+
6+
Browser Plugin to be used with `@snowplow/browser-tracker`.
7+
8+
This plugin is for use in WebViews. It forwards the events to the Snowplow Android, iOS, or React Native trackers via the [Snowplow WebView tracker](https://github.com/snowplow-incubator/snowplow-webview-tracker).
9+
10+
## Maintainer quick start
11+
12+
Part of the Snowplow JavaScript Tracker monorepo.
13+
Build with [Node.js](https://nodejs.org/en/) (18 - 20) and [Rush](https://rushjs.io/).
14+
15+
### Setup repository
16+
17+
```bash
18+
npm install -g @microsoft/rush
19+
git clone https://github.com/snowplow/snowplow-javascript-tracker.git
20+
rush update
21+
```
22+
23+
## Package Installation
24+
25+
With npm:
26+
27+
```bash
28+
npm install @snowplow/browser-plugin-webview
29+
```
30+
31+
## Usage
32+
33+
Initialize your tracker with the `WebViewPlugin`:
34+
35+
```js
36+
import { newTracker } from '@snowplow/browser-tracker';
37+
import { WebViewPlugin } from '@snowplow/browser-plugin-webview';
38+
39+
newTracker('sp1', '{{collector_url}}', {
40+
appId: 'my-app-id',
41+
plugins: [ WebViewPlugin() ],
42+
});
43+
```
44+
45+
For a full API reference, you can read the plugin [documentation page](https://docs.snowplow.io/docs/collecting-data/collecting-from-own-applications/javascript-trackers/browser-tracker/browser-tracker-v3-reference/plugins/webview/).
46+
47+
## Copyright and license
48+
49+
Licensed and distributed under the [BSD 3-Clause License](LICENSE) ([An OSI Approved License][osi]).
50+
51+
Copyright (c) 2024 Snowplow Analytics Ltd.
52+
53+
All rights reserved.
54+
55+
[npm-url]: https://www.npmjs.com/package/@snowplow/browser-plugin-webview
56+
[npm-image]: https://img.shields.io/npm/v/@snowplow/browser-plugin-webview
57+
[docs]: https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/javascript-tracker/
58+
[osi]: https://opensource.org/licenses/BSD-3-Clause
59+
[license-image]: https://img.shields.io/npm/l/@snowplow/browser-plugin-webview
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
reporters: ['jest-standard-reporter'],
4+
setupFilesAfterEnv: ['../../setupTestGlobals.ts'],
5+
testEnvironment: 'jest-environment-jsdom-global',
6+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "@snowplow/browser-plugin-webview",
3+
"version": "4.1.0",
4+
"description": "Automatically forwards events to Snowplow mobile trackers running in a WebView.",
5+
"homepage": "https://github.com/snowplow/snowplow-javascript-tracker",
6+
"bugs": "https://github.com/snowplow/snowplow-javascript-tracker/issues",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/snowplow/snowplow-javascript-tracker.git"
10+
},
11+
"license": "BSD-3-Clause",
12+
"author": "Snowplow Analytics Ltd (https://snowplow.io/)",
13+
"sideEffects": false,
14+
"main": "./dist/index.umd.js",
15+
"module": "./dist/index.module.js",
16+
"types": "./dist/index.module.d.ts",
17+
"files": [
18+
"dist"
19+
],
20+
"scripts": {
21+
"build": "rollup -c --silent --failAfterWarnings",
22+
"test": "jest"
23+
},
24+
"dependencies": {
25+
"@snowplow/browser-tracker-core": "workspace:*",
26+
"@snowplow/tracker-core": "workspace:*",
27+
"tslib": "^2.3.1",
28+
"@snowplow/webview-tracker": "^0.3.0"
29+
},
30+
"devDependencies": {
31+
"@ampproject/rollup-plugin-closure-compiler": "~0.27.0",
32+
"@rollup/plugin-commonjs": "~21.0.2",
33+
"@rollup/plugin-node-resolve": "~13.1.3",
34+
"@types/jest": "~28.1.1",
35+
"@types/jsdom": "~16.2.14",
36+
"@typescript-eslint/eslint-plugin": "~5.15.0",
37+
"@typescript-eslint/parser": "~5.15.0",
38+
"eslint": "~8.11.0",
39+
"jest": "~28.1.3",
40+
"jest-environment-jsdom": "~28.1.3",
41+
"jest-environment-jsdom-global": "~4.0.0",
42+
"jest-standard-reporter": "~2.0.0",
43+
"rollup": "~2.70.1",
44+
"rollup-plugin-cleanup": "~3.2.1",
45+
"rollup-plugin-license": "~2.6.1",
46+
"rollup-plugin-terser": "~7.0.2",
47+
"rollup-plugin-ts": "~2.0.5",
48+
"ts-jest": "~28.0.8",
49+
"typescript": "~4.6.2"
50+
},
51+
"peerDependencies": {
52+
"@snowplow/browser-tracker": "~4.0.1"
53+
}
54+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { nodeResolve } from '@rollup/plugin-node-resolve';
2+
import commonjs from '@rollup/plugin-commonjs';
3+
import ts from 'rollup-plugin-ts'; // Preferred over @rollup/plugin-typescript as it bundles .d.ts files
4+
import { banner } from '../../banner';
5+
import compiler from '@ampproject/rollup-plugin-closure-compiler';
6+
import { terser } from 'rollup-plugin-terser';
7+
import cleanup from 'rollup-plugin-cleanup';
8+
import pkg from './package.json';
9+
import { builtinModules } from 'module';
10+
11+
const umdPlugins = [nodeResolve({ browser: true }), commonjs(), ts()];
12+
const umdName = 'snowplowWebViewTracking';
13+
14+
export default [
15+
// CommonJS (for Node) and ES module (for bundlers) build.
16+
{
17+
input: './src/index.ts',
18+
plugins: [...umdPlugins, banner()],
19+
treeshake: { moduleSideEffects: ['sha1'] },
20+
output: [{ file: pkg.main, format: 'umd', sourcemap: true, name: umdName }],
21+
},
22+
{
23+
input: './src/index.ts',
24+
plugins: [...umdPlugins, compiler(), terser(), cleanup({ comments: 'none' }), banner()],
25+
treeshake: { moduleSideEffects: ['sha1'] },
26+
output: [{ file: pkg.main.replace('.js', '.min.js'), format: 'umd', sourcemap: true, name: umdName }],
27+
},
28+
{
29+
input: './src/index.ts',
30+
external: [...builtinModules, ...Object.keys(pkg.dependencies), ...Object.keys(pkg.devDependencies)],
31+
plugins: [
32+
ts(), // so Rollup can convert TypeScript to JavaScript
33+
banner(),
34+
],
35+
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
36+
},
37+
];

0 commit comments

Comments
 (0)