实现后台及前台通过API访问UV埋点,所有代码全部保存
This commit is contained in:
@@ -13,6 +13,7 @@ use liliuwei\think\Jump;
|
||||
use think\facade\Route;
|
||||
use think\facade\Config;
|
||||
use think\facade\Env;
|
||||
use app\tracking\VisitorTracker;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
@@ -79,6 +80,23 @@ abstract class Controller
|
||||
}
|
||||
//固定一个版本号
|
||||
$this->assign('version', 128);
|
||||
|
||||
// ------------ 埋点:新增用户访问来源统计数据 ------------
|
||||
try {
|
||||
$visitorTracker = new VisitorTracker();
|
||||
$siteId = property_exists($this, 'site_id') ? $this->site_id : 0;
|
||||
$visitorTracker->shop_visit(['site_id' => $siteId]);
|
||||
if (property_exists($this, 'store_id')) {
|
||||
$storeId = $this->store_id;
|
||||
if (!empty($storeId)) {
|
||||
$visitorTracker->store_visit(['site_id' => $siteId, 'store_id' => $storeId]);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 埋点异常不影响正常业务
|
||||
log_write('埋点异常:' . $e->getMessage(), 'error');
|
||||
}
|
||||
|
||||
return View::fetch($template, $vars);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user