When using AnQiCMS, many users are concerned about how to conveniently integrate third-party JavaScript statistics codes into the website pages, such as Baidu Statistics, Google Analytics, etc.About this, AnQiCMS indeed provides built-in mechanisms and flexible template tags, allowing you to easily call and display these statistics codes on the website.

Use the built-in JS code call tag

AnQiCMS to meet the needs of website operators to integrate third-party scripts, especially for some services that require data submission or statistics through JavaScript, provides a dedicated built-in tag.In the background function management, there is an option called "Link Push", which includes the function of "360/Toutiao and other JS automatic submission".Although this feature was initially designed for JavaScript push links in search engines, its underlying implementation is a universal JavaScript code injection mechanism.

You only need to paste the complete JavaScript statistics code (including the one you get from the third-party statistics platform) into the input box of this feature in the background.<script>and</script>Label),system will store it. Subsequently, in the front-end template of your website, you can call and display this code through a specific tag. This tag is{{- pluginJsCode|safe }}.

This label is usually placed in the public template files of the website (for examplebase.html) of<head>or after the tags</body>Before the end tag.|safe

Flexible invocation is achieved through custom system parameters

In addition to the built-in tags for specific scenarios mentioned above, AnQiCMS also provides another more general method for managing and invoking custom JS code, which is to use the "Custom Parameters" feature in the "Global Function Settings

In the "Background Settings" -u003e "Global Function Settings" on the backend, you can add custom parameters.For example, you can create a parameter named “AnalyticsCode” or “BaiduTongji”, and paste your JS statistics code in the “Parameter Value” field.The advantage of this method is that you can create multiple independent custom parameters to store different JS code snippets, such as one for Google Analytics, another for Baidu statistics, or any other JS script that needs to be loaded globally.

When calling these custom parameters in the front-end template, you can use{% system with name="您自定义的参数名" %}tags, which also need to be paired with|safeFilter, for example:{% system analyticsCode with name="AnalyticsCode" %}{{analyticsCode|safe}}This method provides higher flexibility, allowing you to control the loading position and conditions of each JS code snippet as needed, making website management more refined.

The difference between the traffic statistics of AnQi CMS itself and external JS statistics

In summary, AnQi CMS provides specialpluginJsCodeLabels and flexible custom system parameters, both of which can fully meet your needs for calling JS statistics code on website pages.These methods are both intuitive and easy to operate, requiring only simple configuration in the background and the inclusion of corresponding tags in the template to seamlessly integrate third-party statistical code.


Common Questions (FAQ)

  1. Can I use multiple JS statistics codes on the website at the same time? For example, use both Google Analytics and Baidu statistics.

  2. Where is the most appropriate position to place the JS statistics code in the template?Generally speaking, it is recommended to place the JS statistics code in the public template file of the website (such asbase.htmlor the main layout file) of<head>Labels within the tag, the earlier the better, to ensure that the script runs as soon as the page loads and captures all access data. However, some large or complex statistical scripts may affect the page rendering speed, in which case, it can also be considered to place it in</body>Before the end tag, this can avoid blocking the rendering of page content. The specific position selection may need to be balanced according to the requirements of the statistical tool and your website performance needs.

  3. Why do you need to add{{- pluginJsCode|safe }}or{{自定义参数名|safe}}at English time, must be added|safethis English filter English? |safeThe filter is an important feature of AnQiCMS template engine, it tells the system that the content processed by this filter is "safe" HTML or JavaScript code and does not require automatic escaping. If missing|safe,The template engine, for security reasons, will escape HTML tags (such as<script>/</>), and special characters in JavaScript code to HTML entities (such as<will be escaped as&lt;),导致统计代码无法被浏览器识别为可执行的脚本,从而失效。因此,加上 English|safeIt is to ensure that the statistical code can be correctly executed by the browser as original JavaScript.