@blocklet/tracker 1.16.13-beta-2eb54cbc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +29 -0
- package/index.js +27 -0
- package/package.json +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2018-2020 ArcBlock
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Blocklet Tracker
|
|
2
|
+
|
|
3
|
+
A library to facilitate blocklet tracking, sending tracking data to a backend, can only be used in browser.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Import the library in your blocklet's `index.jsx` file.
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
import '@blocklet/tracker';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then you can use the `window.tracker` object to send tracking data to a backend.
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { useEffect } from 'react';
|
|
17
|
+
import { useLocation } from 'react-router-dom';
|
|
18
|
+
|
|
19
|
+
export default function App() {
|
|
20
|
+
|
|
21
|
+
const location = useLocation();
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (window.tracker && typeof window.tracker.pageView === 'function') {
|
|
25
|
+
window.tracker.pageView(`${location.pathname}${location.search}`);
|
|
26
|
+
}
|
|
27
|
+
}, [location]);
|
|
28
|
+
}
|
|
29
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
(function injectAnalytics(window) {
|
|
2
|
+
const tracker = {};
|
|
3
|
+
|
|
4
|
+
tracker.pageView = function trackPageView(pageName) {
|
|
5
|
+
sendTrackerRequest('pv', pageName);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
tracker.event = function trackEvent(eventName) {
|
|
9
|
+
sendTrackerRequest('evt', eventName);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function sendTrackerRequest(type, data) {
|
|
13
|
+
if (typeof data !== 'string') {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const xhr = new XMLHttpRequest();
|
|
18
|
+
xhr.open('GET', `/.well-known/analytics/${type}/${data.startsWith('/') ? data.slice(1) : data}`, true);
|
|
19
|
+
xhr.setRequestHeader('Content-Type', 'text/html');
|
|
20
|
+
xhr.send();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
window.tracker = tracker;
|
|
24
|
+
if (window.blocklet) {
|
|
25
|
+
window.blocklet.tracker = tracker;
|
|
26
|
+
}
|
|
27
|
+
})(window);
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blocklet/tracker",
|
|
3
|
+
"version": "1.16.13-beta-2eb54cbc",
|
|
4
|
+
"description": "A library to track page views and events for blocklets",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"blocklet"
|
|
10
|
+
],
|
|
11
|
+
"author": "wangshijun <wangshijun2010@gmail.com>",
|
|
12
|
+
"homepage": "",
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"main": "index.js",
|
|
15
|
+
"files": [
|
|
16
|
+
"index.js"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/ArcBlock/blocklet-server"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"lint": "eslint index.js",
|
|
24
|
+
"lint:fix": "npm run lint -- --fix"
|
|
25
|
+
},
|
|
26
|
+
"gitHead": "7adf96c2eb31762d8eb14b8121fce9865d6a458c"
|
|
27
|
+
}
|