Ver código fonte

feat 腾讯广告上报

erekook 7 meses atrás
pai
commit
c594b9c814
5 arquivos alterados com 57 adições e 1 exclusões
  1. 1 0
      .gitignore
  2. 47 0
      app.js
  3. 1 1
      config/config.js
  4. 7 0
      package-lock.json
  5. 1 0
      package.json

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 docs
 .DS_Store
 node_modules
+miniprogram_npm

+ 47 - 0
app.js

@@ -12,6 +12,9 @@ import {
   addBrowsingHistory,
 } from "./api/api";
 import { apple } from "./config/config";
+import { SDK } from "@dn-sdk/miniprogram";
+
+SDK.setDebug(true);
 
 App({
   onLaunch(options) {
@@ -43,6 +46,15 @@ App({
     SendEvent("customAppletsShowEvent", {}, this);
   },
 
+  // 腾讯广告小程序sdk上报
+  sdkTrack(eventName, eventValue) {
+    try {
+      this.globalData.sdk.track(eventName, eventValue);
+    } catch (error) {
+      console.log("sdkTrack error:", error);
+    }
+  },
+
   // 登录方法
   login(promotionid) {
     return new Promise((resolve, reject) => {
@@ -85,7 +97,24 @@ App({
                 this.globalData.unionId = res.unionId;
                 wx.setStorageSync("unionId", res.unionId);
               }
+
               console.log("登录成功", this.globalData);
+
+              if (res.sdkUserActionSetId && res.sdkSecretKey) {
+                this.globalData.sdk = new SDK({
+                  // 数据源ID,必填
+                  user_action_set_id: Number(res.sdkUserActionSetId),
+                  // 加密key,必填
+                  secret_key: res.sdkSecretKey,
+                  appid: apple.appid,
+                });
+
+                this.globalData.sdk.setOpenId(this.globalData.openId);
+                if (res.newUser) {
+                  this.globalData.sdk.track("REGISTER");
+                }
+                this.sdkTrack("START_APP");
+              }
               userActive({
                 appId: apple.appid,
                 openId: res.openId,
@@ -142,6 +171,7 @@ App({
     uuid: "fuck",
     isShowDialog: false,
     novelManagerId: 0,
+    novel: null,
     novelId: "",
     chapterIndex: 0,
     unlockChapterNum: 1,
@@ -154,6 +184,7 @@ App({
     from: "",
     videoAd: null,
     queryData: {},
+    sdk: null,
   },
 });
 
@@ -232,6 +263,13 @@ async function onNovelPluginLoad(data) {
 
   function startRead(res) {
     console.log("开始阅读", res);
+    getApp().globalData.novel = res;
+    getApp().sdkTrack("VIEW_NOVEL", {
+      novel_id: res.book_id, // 小说id(字符串类型)
+      novel_name: res.title, // 小说名(字符串类型)
+      chapters: res.chapter_index, // 章数(第几章,整型)
+    });
+
     updateBrowsingHistory(res);
   }
 
@@ -348,6 +386,15 @@ function rewardVideoLoad() {
           novelManager.paymentCompleted({
             chapterIndex: getApp().globalData.chapterIndex,
           });
+
+          if (getApp().globalData.novel) {
+            getApp().sdkTrack("UNLOCK_PAID_EPISODES", {
+              novel_id: getApp().globalData.novel.book_id, // 小说id(字符串类型)
+              novel_name: getApp().globalData.novel.title, // 小说名(字符串类型)
+              chapters: [getApp().globalData.chapterIndex], // 解锁的章数,填写解锁的第几章(可多个)
+            });
+          }
+
           wx.showToast({
             title: "解锁成功",
             icon: "none",

+ 1 - 1
config/config.js

@@ -590,7 +590,7 @@ const appInfoObj = {
 };
 
 // @config 确定使用的小程序appid
-const current_appid = "wx3f464072571c1fd3";
+const current_appid = "wx04b705205757217b";
 export const apple = {
   ...appInfoObj[current_appid],
   appKey: "49TBR8Z1rA7PyqD30FV0v48AU",

+ 7 - 0
package-lock.json

@@ -8,6 +8,7 @@
       "name": "mini_read_space_front",
       "version": "1.0.0",
       "dependencies": {
+        "@dn-sdk/miniprogram": "^1.5.6",
         "gulp": "^5.0.0"
       },
       "devDependencies": {
@@ -2770,6 +2771,12 @@
         "node": ">=12.13.0"
       }
     },
+    "node_modules/@dn-sdk/miniprogram": {
+      "version": "1.5.6",
+      "resolved": "https://registry.npmmirror.com/@dn-sdk/miniprogram/-/miniprogram-1.5.6.tgz",
+      "integrity": "sha512-XOg5fyGf6p7a3JqS7EQWO+nc0lDeCmVFfHeiBXjubg+h84n0T9eVtQdOSKycqNZ+D7PXRvBxv2qQB3PCEzNRag==",
+      "license": "ISC"
+    },
     "node_modules/@eslint-community/eslint-utils": {
       "version": "4.7.0",
       "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.7.0.tgz",

+ 1 - 0
package.json

@@ -12,6 +12,7 @@
   },
   "private": true,
   "dependencies": {
+    "@dn-sdk/miniprogram": "^1.5.6",
     "gulp": "^5.0.0"
   },
   "devDependencies": {