Authored by huzhiming

feat(oCPC搜索推广): 推广链接转化数据发送给百度服务器,埋点:OCPC推广链接打开并完成注册进行数据上报

1 'use strict'; 1 'use strict';
2 2
  3 +const request = require('request-promise');
3 const md5 = require('md5'); 4 const md5 = require('md5');
4 const uuid = require('uuid'); 5 const uuid = require('uuid');
5 const _ = require('lodash'); 6 const _ = require('lodash');
@@ -20,6 +21,34 @@ const UserService = require('./user-service'); @@ -20,6 +21,34 @@ const UserService = require('./user-service');
20 const LoginApi = require('./login-api'); 21 const LoginApi = require('./login-api');
21 const logger = global.yoho.logger; 22 const logger = global.yoho.logger;
22 23
  24 +class BaiduSDK {
  25 + /*
  26 + * @ description: 广告主回传转化数据接口, 上报百度
  27 + * @ author: huzhiming
  28 + * @ date: 2019-11-19 17:21:29
  29 + * @ version: v1.0.0
  30 + * 详情见文档:[http://ocpc.baidu.com/developer/d/guide/?iurl=api%2Fapi-doc%2Fapi-interface%2F]
  31 + */
  32 + static reportOcpcApi({
  33 + token = '7GULUkX90QLZU6cHO9OEqUsRKttGNqpN@O62eFfb91OUVhmkakV1bQHIxF8xURBvP',
  34 + conversionTypes = [{ logidUrl: '', newType: null }]
  35 + }) {
  36 + request({
  37 + method: 'POST',
  38 + uri: 'http://ocpc.baidu.com/ocpcapi/api/uploadConvertData',
  39 + body: {
  40 + token,
  41 + conversionTypes
  42 + },
  43 + json: true
  44 + }).then((result) => {
  45 + console.log(`[账号注册成功后上报 百度ocpc返回信息:${JSON.stringify(result)}`);
  46 + }).catch((error) => {
  47 + console.log(`[账号注册成功后上报 百度ocpc失败 错误信息:${error}`);
  48 + });
  49 + }
  50 +}
  51 +
23 module.exports = class extends global.yoho.BaseModel { 52 module.exports = class extends global.yoho.BaseModel {
24 constructor(ctx) { 53 constructor(ctx) {
25 super(ctx); 54 super(ctx);
@@ -125,6 +154,23 @@ module.exports = class extends global.yoho.BaseModel { @@ -125,6 +154,23 @@ module.exports = class extends global.yoho.BaseModel {
125 domain: config.cookieDomain 154 domain: config.cookieDomain
126 }); 155 });
127 156
  157 + /*
  158 + * @ description: feat(oCPC搜索推广): 推广链接转化数据发送给百度服务器,埋点:OCPC推广链接打开并完成注册进行数据上报
  159 + * @ author: huzhiming
  160 + * @ date: 2019-11-19 19:09:39
  161 + * @ version: v1.0.0
  162 + * bd_vid_path存值见:public/js/common.js 文件
  163 + */
  164 + const logidUrl = req.cookies.bd_vid_path;
  165 +
  166 + if (logidUrl) {
  167 + BaiduSDK.reportOcpcApi({
  168 + conversionTypes: {
  169 + logidUrl,
  170 + newType: 25
  171 + }
  172 + });
  173 + }
128 174
129 req.session.TOKEN_ = publicToken; 175 req.session.TOKEN_ = publicToken;
130 req.session.LOGIN_UID_ = uid; 176 req.session.LOGIN_UID_ = uid;
@@ -130,6 +130,17 @@ function getShoppingKey() { @@ -130,6 +130,17 @@ function getShoppingKey() {
130 if (window._yas) { 130 if (window._yas) {
131 window._yas(1 * new Date(), window._yasVersion, 'yohobuy_web', uid, '', ''); 131 window._yas(1 * new Date(), window._yasVersion, 'yohobuy_web', uid, '', '');
132 } 132 }
  133 +
  134 + /* 【加入ocpcApi代码】: 判断当前页面地址若百度sem推广链接,即将推广链接存到cookies,支付成功后将推广链接上报百度 ocpcapi
  135 + * @ description: 收集百度sem推广链接
  136 + * @ author: huzhiming
  137 + * @ date: 2019-11-18 16:55:17
  138 + * @ version: v1.0.0
  139 + * 详情见文档:[http://ocpc.baidu.com/developer/d/guide/?iurl=api%2Fapi-doc%2Fapi-interface%2F]
  140 + */
  141 + if (location.href.includes('bd_vid=')) {
  142 + setCookie('bd_vid_path', location.href, { path: '/' });
  143 + }
133 }()); 144 }());
134 145
135 // window.resize在width<1180时适配成990 146 // window.resize在width<1180时适配成990