Browse Source

feate:测试数据采集NPM包相关

luoy 1 month ago
parent
commit
918dd30a43

+ 0 - 22
main.html

@@ -9,26 +9,4 @@
   这是一个空页面
   <button id="btn">点击我</button>
 </body>
-<!--inside <head></head>-->
-<script type='text/javascript'>
-var Countly = Countly || {};
-Countly.q = Countly.q || [];
-
-// server credentials 
-Countly.app_key = "YOUR_APP_KEY"; 
-Countly.url = "https://yourdomain.com";
-
-// Track sessions and page views automatically (recommended)
-Countly.q.push(['track_sessions']);
-Countly.q.push(['track_pageview']);
-
-// Load Countly script asynchronously
-(function() {
-  var cly = document.createElement('script'); cly.type = 'text/javascript';
-  cly.async = true;
-  cly.src = 'https://cdn.jsdelivr.net/npm/countly-sdk-web@latest/lib/countly.min.js';
-  cly.onload = function(){Countly.init()};
-  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(cly, s);
-})();
-</script>
 </html>

+ 0 - 1
react-test/package.json

@@ -7,7 +7,6 @@
     "@testing-library/jest-dom": "^6.6.3",
     "@testing-library/react": "^16.3.0",
     "@testing-library/user-event": "^13.5.0",
-    "countly-sdk-web": "^25.4.1",
     "react": "^19.1.0",
     "react-dom": "^19.1.0",
     "react-scripts": "5.0.1",

+ 0 - 11
react-test/src/index.js

@@ -3,17 +3,6 @@ import ReactDOM from 'react-dom/client';
 import './index.css';
 import App from './App';
 import reportWebVitals from './reportWebVitals';
-import Countly from "countly-sdk-web";
-
-Countly.init({
-  // server credentials
-  app_key: "YOUR_APP_KEY",
-  url: "http://yourdomain.com"
-});
-
-// Track sessions and page views automatically (recommended)
-Countly.track_sessions();
-Countly.track_pageview();
 
 const root = ReactDOM.createRoot(document.getElementById('root'));
 root.render(

File diff suppressed because it is too large
+ 9 - 769
vue-test/package-lock.json


+ 2 - 6
vue-test/package.json

@@ -9,17 +9,13 @@
   },
   "dependencies": {
     "core-js": "^3.8.3",
-    "countly-sdk-web": "^25.4.1",
+    "utm-params-extractor-test": "^1.0.9",
     "vue": "^3.2.13"
   },
   "devDependencies": {
     "@babel/core": "^7.12.16",
-    "@babel/eslint-parser": "^7.12.16",
     "@vue/cli-plugin-babel": "~5.0.0",
-    "@vue/cli-plugin-eslint": "~5.0.0",
-    "@vue/cli-service": "~5.0.0",
-    "eslint": "^7.32.0",
-    "eslint-plugin-vue": "^8.0.3"
+    "@vue/cli-service": "~5.0.0"
   },
   "eslintConfig": {
     "root": true,

+ 14 - 0
vue-test/public/index.html

@@ -14,4 +14,18 @@
     <div id="app"></div>
     <!-- built files will be auto injected -->
   </body>
+  <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.3.4/vconsole.min.js"></script>
+  <!-- <script src="https://cdn.jsdelivr.net/npm/@fingerprintjs/fingerprintjs@3/dist/fp.min.js"></script> -->
+  <script>
+    (async () => {
+
+      const v = new window.VConsole()
+      // console.info(window.screen)
+      // const fp = await FingerprintJS.load();
+      // const result = await fp.get();
+      // const visitorId = result.visitorId;
+      // console.log('------------(Visitor ID):', visitorId);
+
+    })();
+</script>
 </html>

+ 79 - 3
vue-test/src/components/HelloWorld.vue

@@ -1,8 +1,84 @@
 <template>
  <div>
   这是一个空页面
-  <button>
-   点击按钮
+  <button @click="generateAndAppendUtmParams">
+   点击按钮,发送数据
   </button>
  </div>
-</template>
+</template>
+<script setup>
+import UtmTracker from "utm-params-extractor-test";
+
+function generateAndAppendUtmParams() {
+  // 获取随机合法值的函数
+  function getRandomValue() {
+    return Math.random().toString(36).substring(2, 7);
+  }
+
+  // utm_source 合法取值范围
+  const utmSourceOptions = ['baidu', 'bd', 'google', 'safari', 'tx', 'qq', 'wx'];
+
+  // 随机选择一个 utm_source 值
+  const utmSource = utmSourceOptions[
+    Math.floor(Math.random() * utmSourceOptions.length)
+  ];
+
+  // 生成其他UTM参数的随机值
+  const utmParams = {
+    utm_source: utmSource,
+    utm_medium: getRandomValue(),
+    utm_campaign: getRandomValue(),
+    utm_term: getRandomValue(),
+    utm_content: getRandomValue()
+  };
+
+  // 构造带UTM参数的URL
+  let urlWithParams = window.location.href.split('?')[0] + '?';
+  const paramsArray = [];
+
+  for (const key in utmParams) {
+    paramsArray.push(`${key}=${encodeURIComponent(utmParams[key])}`);
+  }
+
+  urlWithParams += paramsArray.join('&');
+
+  // 更新当前页面的URL
+  window.history.pushState({}, '', urlWithParams);
+
+  // 触发按钮点击事件
+  fetchData();
+}
+
+const fetchData = () => {
+  const utm = UtmTracker.get()
+  console.log(utm);
+  const requestData = {
+    utm_source: utm.utm_source || '',
+    utm_medium: utm.utm_medium || '',
+    utm_campaign: utm.utm_campaign || '',
+    utm_term: utm.utm_term || '',
+    utm_content: utm.utm_content || '',
+    referrer: utm.referrer || '',
+    isMobile: utm.browser.isMobile || '',
+    browser: utm.browser.browser || '',
+    userAgent: utm.browser.userAgent || '',
+    osType: utm.browser.osType || '',
+    osVersion: utm.browser.osVersion || '',
+    timestamp: utm.timestamp || '',
+    url: utm.url || ''
+  };
+  console.log(requestData);
+  fetch('http://192.168.3.9:3000/api/insert', {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify(requestData)
+  })
+   .then(response => response.json())
+   .then(data => {
+     console.log(data);
+   })
+   .catch(error => {
+     console.error("Error fetching data:", error);
+   });
+}
+</script>

+ 0 - 12
vue-test/src/main.js

@@ -1,16 +1,4 @@
 import { createApp } from 'vue'
 import App from './App.vue'
 
-import Countly from "countly-sdk-web";
-
-Countly.init({
-  // server credentials
-  app_key: "YOUR_APP_KEY",
-  url: "http://yourdomain.com"
-});
-
-// Track sessions and page views automatically (recommended)
-Countly.track_sessions();
-Countly.track_pageview();
-
 createApp(App).mount('#app')

File diff suppressed because it is too large
+ 20 - 551
vue-test/yarn.lock


Some files were not shown because too many files changed in this diff