Authored by shuaiguo

Merge remote-tracking branch 'refs/remotes/origin/feature/baidu_ocpcapi' into release

  1 +const request = require('request-promise');
1 const _ = require('lodash'); 2 const _ = require('lodash');
2 const url = require('url'); 3 const url = require('url');
3 const helpers = global.yoho.helpers; 4 const helpers = global.yoho.helpers;
@@ -9,6 +10,34 @@ const cookie = global.yoho.cookie; @@ -9,6 +10,34 @@ const cookie = global.yoho.cookie;
9 const AuthHelperModel = require('../models/auth-helper'); 10 const AuthHelperModel = require('../models/auth-helper');
10 const config = global.yoho.config; 11 const config = global.yoho.config;
11 12
  13 +class BaiduSDK {
  14 + /*
  15 + * @ description: 广告主回传转化数据接口, 上报百度
  16 + * @ author: huzhiming
  17 + * @ date: 2019-11-19 17:21:29
  18 + * @ version: v1.0.0
  19 + * 详情见文档:[http://ocpc.baidu.com/developer/d/guide/?iurl=api%2Fapi-doc%2Fapi-interface%2F]
  20 + */
  21 + static reportOcpcApi({
  22 + token = '7GULUkX90QLZU6cHO9OEqUsRKttGNqpN@O62eFfb91OUVhmkakV1bQHIxF8xURBvP',
  23 + conversionTypes = [{ logidUrl: '', newType: null }]
  24 + }) {
  25 + request({
  26 + method: 'POST',
  27 + uri: 'http://ocpc.baidu.com/ocpcapi/api/uploadConvertData',
  28 + body: {
  29 + token,
  30 + conversionTypes
  31 + },
  32 + json: true
  33 + }).then((result) => {
  34 + console.log(`[账号注册成功后上报 百度ocpc返回信息:${JSON.stringify(result)}`);
  35 + }).catch((error) => {
  36 + console.log(`[账号注册成功后上报 百度ocpc失败 错误信息:${error}`);
  37 + });
  38 + }
  39 +}
  40 +
12 class Reg { 41 class Reg {
13 /** 42 /**
14 * 注册页面 43 * 注册页面
@@ -224,6 +253,24 @@ class Reg { @@ -224,6 +253,24 @@ class Reg {
224 253
225 delete req.session.phoneNum; 254 delete req.session.phoneNum;
226 255
  256 + /*
  257 + * @ description: feat(oCPC搜索推广): 推广链接转化数据发送给百度服务器,埋点:OCPC推广链接打开并完成注册进行数据上报
  258 + * @ author: huzhiming
  259 + * @ date: 2019-11-19 19:09:39
  260 + * @ version: v1.0.0
  261 + * bd_vid_path存值见:public/js/common.js 文件
  262 + */
  263 + const logidUrl = req.cookies.bd_vid_path;
  264 +
  265 + if (logidUrl) {
  266 + BaiduSDK.reportOcpcApi({
  267 + conversionTypes: {
  268 + logidUrl,
  269 + newType: 25
  270 + }
  271 + });
  272 + }
  273 +
227 return res.json({ 274 return res.json({
228 code: 200, 275 code: 200,
229 message: '注册成功', 276 message: '注册成功',
@@ -288,6 +288,17 @@ $.extend({ @@ -288,6 +288,17 @@ $.extend({
288 // 尝试打开 APP 288 // 尝试打开 APP
289 // require('./common/open-app'); 289 // require('./common/open-app');
290 290
  291 + /* 【加入ocpcApi代码】: 判断当前页面地址若百度sem推广链接,即将推广链接存到cookies,支付成功后将推广链接上报百度 ocpcapi
  292 + * @ description: 收集百度sem推广链接
  293 + * @ author: huzhiming
  294 + * @ date: 2019-11-18 16:55:17
  295 + * @ version: v1.0.0
  296 + * 详情见文档:[http://ocpc.baidu.com/developer/d/guide/?iurl=api%2Fapi-doc%2Fapi-interface%2F]
  297 + */
  298 + if (location.href.includes('bd_vid=')) {
  299 + setCookie('bd_vid_path', location.href, { path: '/', domain: '.yohobuy.com', expires: 90 });
  300 + }
  301 +
291 // 尝试打开 MINIAPP 302 // 尝试打开 MINIAPP
292 require('./common/open-miniapp'); 303 require('./common/open-miniapp');
293 }()); 304 }());
@@ -531,6 +542,7 @@ function givePoint(parameter) { @@ -531,6 +542,7 @@ function givePoint(parameter) {
531 } 542 }
532 }()); 543 }());
533 544
  545 +
534 // 暴露公共接口 546 // 暴露公共接口
535 window.cookie = cookie; 547 window.cookie = cookie;
536 548