When using AnQiCMS (AnQiCMS) to build and operate websites, 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 statistics code on web pages.However, the anti-crawling feature built into Anqi CMS is intended to protect original content from being maliciously crawled, and sometimes it may 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 statistics code

Anqi CMS, as a content management system that focuses on performance and security, one of its core functions is the powerful anti-crawling and watermark management.This includes the 'built-in anti-crawling interference code', which is designed to identify and interfere with abnormal access behavior to protect the website content.And statistical code usually exists in the form of external JavaScript scripts or inline scripts. When anti-collection mechanisms are sensitive, they may mistakenly identify these unfamiliar JavaScript codes that execute specific network requests as some form of collection behavior, thereby interfering with, blocking, or removing them.At the same time, the content filtering function of Anqi CMS may also process embedded external script links, further increasing the risk that the statistics code will not take effect.

On the other hand, website traffic statistics and crawler monitoring are another important features provided by Anqi CMS, which help us understand the performance of the website.But to make these functions work with third-party statistical services, it is necessary to ensure that the external statistical code can be executed smoothly without interference.

Ensure the key strategy is added effectively to the statistical code

In order to coexist harmoniously with the anti-crawling function of Anqi CMS and at the same time ensure the accuracy of data collection, we can start from the following aspects:

1. Use the special statistical code tag of AnQi CMS

AnQi CMS provides a tag specially 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:

First, in the Anqi CMS backend's "Function Management", there will usually be a setting item similar to "Link Push" or "Third-party JS Code" (for example, the part mentioned in the document as "360/Toutiao and JS automatic submission"), where you can paste the complete JavaScript statistics code provided by services such as Baidu Statistics and Google Analytics.

Next, in your website template file (such asbase.htmlor the specific page template you need to count</head>or after the tag</body>find the appropriate position before the tag and insert{{- pluginJsCode|safe }}.

Here|safeThe filter is crucial. Anqi CMS, for security reasons, defaults to escaping all output variable content, which means<script>tags may be converted to&lt;script&gt;, causing the browser to fail to recognize and execute.|safeThe filter explicitly tells the system that this content is safe, does not require escaping, and thus allows the browser to correctly parse and run the statistical code.This way of managing statistical codes uniformly reduces the frequency of manual template modifications and is also less prone to errors.

2. Notes on manually embedding statistical code in templates.

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>Label. In this case, it is essential to use it.|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 embedded directly in the template must ensure that the external Go template engine does not escape its content by mistake. Although the AnQiCMS template system intelligently handles some content, it is better to be safe than sorry and directly inscriptTag usage externally|safeFilter, or make sure it is placed in a code block that will not be escaped, is a safe practice.

Important reminder: |safeThe filter indicates that the content is safe. This means that if the embedded code itself has malicious or unsafe factors, the system will not provide protection.Therefore, make sure any code you embed comes from a completely trusted source.

3. Avoiding the 'injury' of content filtering

The Anqi CMS provides the option 'Whether to automatically filter external links' in the 'Content Settings'.This feature is designed to maintain content purity and prevent spam external links.However, some statistical codes may be accessed via external links such ashm.src = "https://hm.baidu.com/hm.js?YOUR_BAIDU_ID") Load the 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 statistics scripts, causing the statistics code to fail to load normally.

If the statistical code does not work, besides checking|safeOutside the filter, this item in the "Content Settings" should also be checked.If your statistical service indeed needs to load external JS files, and you trust the security of these external links, you can consider adjusting the setting, or set 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 statistical code, be sure to carry out a comprehensive test and verification:

  • Clear the cache:In the "Update Cache" feature of Anqi CMS backend, perform a cleanup operation 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 has loaded successfully; check the "Console" tab to see if there are any error messages related to the statistics code.
  • Data of the statistical platform:Log in to the background of the statistical service you are using, view real-time visitor data, and confirm whether the statistical code has started to collect data normally.
  • AnQi CMS traffic statistics:Refer to the "Data Statistics" function on the AnQi CMS backend, combine third-party statistical data for cross-validation to ensure data consistency.

By implementing the above strategy and meticulous verification, you can effectively integrate third-party statistical code seamlessly into the Anqi CMS website, while enjoying system security protection and accurately grasping the operation data of the website.


Frequently Asked Questions (FAQ)

1. Why did the statistics code not work even though I followed the steps?Firstly, make sure you have cleared all the cache on 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 loading fails, check if the URL is correct, or if there are any HTTP errors (such as 404, 403).At the same time, check the "Console" tab to see if there are any JavaScript error reports.In addition, confirm that you have used the template correctly{{- pluginJsCode|safe }}the tags, and|safeThe filter has no omissions. If the statistical code is inline JS, it is also necessary to confirm that the content filter settings have not removed it.

2. How do I add the tracking code for Baidu Statistics and Google Analytics to my website?Of Security CMSpluginJsCodeTags are typically designed to handle a full segment 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