問題描述
我們根據文檔中的說明在我們的網站中包含了 timeonsite 庫 timeonsitetracker
We included the timeonsite library timeonsitetracker in our website as per the instructions in doc
<script type="text/javascript">
var Tos;
(function(d, s, id, file) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s);
js.id = id;
js.onload = function() {
// save with XMLHttpRequest or sendBeacon
var config = {
trackBy: 'seconds',
developerMode: true,
callback: function(data) {
console.log('***');
console.log(data);
// give your endpoint URL/ server-side URL that is going to handle your TOS data which is of POST method. Eg. PHP, nodejs or python URL which saves this data to your DB
var endPointUrl = 'http://localhost:4500/tos'; // replace with your endpoint URL
if (data && data.trackingType) {
if (data.trackingType == 'tos') {
if (Tos.verifyData(data) != 'valid') {
console.log('Data abolished!');
return;
}
}
if (navigator && typeof navigator.sendBeacon === 'function') {
data.trasferredWith = 'sendBeacon';
var blob = new Blob([JSON.stringify(data)], {type : 'application/json'});
navigator.sendBeacon(endPointUrl, blob);
}
}
}};
if(TimeOnSiteTracker) {
Tos = new TimeOnSiteTracker(config);
}
};
js.src = file;fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'TimeOnSiteTracker', '//cdn.jsdelivr.net/gh/saleemkce/timeonsite@1.1.0/timeonsitetracker.min.js'));
</script>
刷新瀏覽器后,我在 Firefox Web 控制臺中看到了正確記錄的數據(啟用日志持久性,否則每次刷新時都會清除日志).
After refreshing the browser, I see the data logged (enabled log persistence otherwise log is cleared on each refresh) in Firefox web console correctly.
***
{
TOSId: 14650383319214848
TOSSessionKey: "8808159448467693499978"
TOSUserId: "anonymous"
URL: "https://localhost/index.html"
currentTime: "2021-03-30 16:25:17.908"
entryTime: "2021-03-30 16:24:36.911"
timeOnPage: 41
timeOnPageByDuration: "0d 00h 00m 41s"
timeOnPageTrackedBy: "second"
timeOnSite: 41
timeOnSiteByDuration: "0d 00h 00m 41s"
title: "home page - rental crown"
trackingType: "tos"
}
但此會話數據并未存儲在 MariaDB 中.不知道數據的去向.在刷新第二頁時,我再次在 Firefox Web 控制臺中看到更新的數據對象,但在 MariaDB 中沒有捕獲數據.它在 Chrome 中工作,但似乎沒有將數據正確存儲在數據庫中.知道如何解決 Firefox 中的問題嗎?
But this session data is not stored in MariaDB. There is no clue where the data goes. On refreshing second page, again I see the updated data object in Firefox web console but no data captured in MariaDB. It worked in Chrome but doesn't seem to store the data properly in DB. Any idea how to fix the issue in Firefox?
我遵循 此處的文檔.非常感謝您的幫助.
I followed the documentation here. And help is greatly appreciated.
推薦答案
我今天再次測試了這個.似乎 sendBeacon 在 Chrome、Firefox 等許多瀏覽器上都無法正常工作.Chrome 和Firefox 為此.
I tested this again today. It seems that sendBeacon was not working for sometime on many browsers like Chrome, Firefox and others. There were some open issues in both Chrome & Firefox for this.
但是今天,我在 Chrome 和 Chrome 上使用 timeOnSite tracker JS 再次測試了它.火狐.它似乎在頁面刷新、標簽關閉或瀏覽器關閉場景中成功地將數據發布到數據庫.
But today, I tested it again for with timeOnSite tracker JS on both Chrome & Firefox. It seems that it posts the data successfully to database on page refresh, tab close or browser close scenarios.
更新日期:2021 年 11 月 13 日
瀏覽器成功運行版本:
Browsers working successfully with version:
Chrome:95.0.4638.69
Chrome: 95.0.4638.69
火狐:94.0.1
但請注意,這可能不適用于舊瀏覽器或不完全支持 sendBeacon 的瀏覽器.因此,如果在此類瀏覽器上無法獲得實時站點數據,請使用請求對象回退到 localstorage 選項.
But be informed that this may not work in old browsers or browsers that don't support sendBeacon fully. So in case of not getting real-time time on site data on such browsers, fallback to localstorage option with request object.
var config = {
trackBy: 'seconds',
request: { // presence of request object denotes that data is to be saved in local storage
url: 'http://localhost:4500/tos'
}
}
這篇關于為什么從 Firefox 瀏覽器訪問時,現場時間數據沒有保存在數據庫中?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!