When building and operating a website with AnQiCMS, we often need to integrate various third-party statistical analysis services, such as Baidu Statistics, Google Analytics, etc.These services collect visitor data by embedding JavaScript tracking code on web pages.However, the anti-crawling feature built into the Anqi CMS is designed to protect original content from being maliciously crawled, which may sometimes cause unexpected "friction" with these statistical codes.Understanding this potential conflict and adopting the correct configuration method is the key to ensuring accurate website data statistics.
Understand potential conflicts: anti-crawling and statistical code
AutoCMS is a content management system that focuses on performance and security, one of its core functions is a powerful anti-crawling and watermark management.This includes the 'Built-in anti-crawling interference code', which aims to protect website content by identifying and interfering with abnormal access behavior.The statistical code usually exists in the form of external JavaScript scripts or inline scripts. When anti-crawling mechanisms are more sensitive, they may mistakenly judge these unfamiliar JavaScript codes that execute specific network requests as some form of crawling behavior, and thus interfere with, block, or remove them.At the same time, the content filtering function of Anqi CMS may also process the links of embedded external scripts, further increasing the risk that the statistical code will not take effect.
On the other hand, website traffic statistics and crawler monitoring are another important feature provided by the AnQi CMS, which helps us understand the performance of the website.But in order to make these features work with third-party statistical services, it is necessary to ensure that the external statistical code can execute smoothly without interference.
Ensure the key strategy for adding valid statistical code
To ensure that the statistical code can coexist harmoniously with the anti-crawling function of AnQi CMS while also ensuring the accuracy of data collection, we can start from the following aspects:
1. Utilize the dedicated statistics code tag of AnQi CMS
AnQi CMS provides a tag specifically designed for this kind of need{{- pluginJsCode|safe }}This tag is the most recommended and safest way to place statistical code. Its working principle is:
Firstly, in the "Function Management
其次,in your website template files (such asbase.htmlor specific page template that needs to be counted), find</head>before the</body>tag at a suitable position, insert{{- pluginJsCode|safe }}.
Here are the|safeThe filter is crucial. For security reasons, the AnQi CMS defaults to escaping all output variable content in HTML, which means<script>tags may be converted to<script>,causing the browser to fail to recognize and execute.|safeThe filter explicitly tells the system that this content is safe and does not require escaping, allowing the browser to correctly parse and run the statistical code.This method unifies the management of statistical codes, reduces the frequency of manual template modifications, and is also less prone to errors.
2. Considerations for manually embedding statistical codes in the template.
If you need to control the loading position or conditions of the statistical code more finely, you may need to embed it manually in the template file<script>Tags. In this case, be sure to use|safeFilter.
For example:
<script type="text/javascript">
// 您的百度统计代码或Google Analytics代码
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?YOUR_BAIDU_ID";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
This code should be embedded directly in the template, and it is necessary to ensure that the external Go template engine does not意外转义 its content. Although AnQiCMS's template system intelligently handles some content, it is for safety's sake to directly inscriptLabel's external usage|safeIt is a safe practice to filter the filter or ensure it is placed in a code block that will not be escaped.
Important reminder: |safeThe filter indicates to the system that this content is safe.This means that if the embedded code itself contains malicious or unsafe elements, the system will not provide protection.Therefore, please ensure that any code you embed comes from a completely trusted source.
3. Avoid 'misfire' in content filtering
The "Content Settings" in Anqi CMS provides the option of "Whether to automatically filter external links".This feature is designed to maintain the purity of content and prevent spammy external links.hm.src = "https://hm.baidu.com/hm.js?YOUR_BAIDU_ID")Load core statistics script.If the "Auto-filter external links" feature is enabled and set too strictly, it may mistakenly identify and remove the reference links of these statistical scripts, resulting in the inability to normally load the statistical code.
If the statistics code does not work, in addition to checking|safeFilter out, and also check this item in the "Content Settings".If your statistical service indeed requires loading external JS files, and you trust the security of these external links, consider adjusting this setting or setting it to not filter, to ensure that the statistical code can load smoothly.
Implementation and verification: ensure that everything is in place
After adding or modifying the statistics code, be sure to conduct a comprehensive test and verification:
- Clear cache:In the "Update Cache" feature of the Anqi CMS backend, perform cleanup operations to ensure that the website loads the latest template and configuration.
- Browser Developer Tools:Use the browser's developer tools (F12), check the "Network" tab to see if the statistics script is loaded successfully; check the "Console" tab to see if there are any error messages related to the statistics code.
- Count platform data:Log in to the backend of the statistics service you are using, check the real-time visitor data, and confirm whether the statistics code has started to collect data normally.
- Safe CMS traffic statistics:Refer to the "Data Statistics" function on the AnQi CMS backend, combine third-party statistical data for cross-validation, and ensure data consistency.
By implementing the above strategy and performing detailed verification, you can effectively integrate the third-party statistical code seamlessly into the Anqi CMS website. While enjoying the system security protection, you can accurately grasp the operation data of the website.
Common Questions (FAQ)
1. Why doesn't the statistics code work even though I followed the steps?Please ensure that you have cleared all the caches in the AnQi CMS backend.Then, use the browser developer tools (F12) to check the 'Network' tab to see if the statistics script file has been successfully loaded.If the loading fails, check if the URL is correct or if there are HTTP errors (such as 404, 403).Check the "Console" tab to see if there are any JavaScript error reports.{{- pluginJsCode|safe }}labels, and|safeFilter no omissions. If the statistical code is inline JS, it is also necessary to confirm that the content filtering settings have not removed it.
2. My website uses both Baidu Statistics and Google Analytics. How should I add the tracking code?Anqi CMS'spluginJsCodeLabels are typically designed to handle a whole block of JavaScript code. If you have two statistics codes, you can integrate them into one<script>In the block, then paste this integrated code in the "Third-party JS code" settings on the backend. For example:
"`html