The website is operational, traffic statistics are an indispensable link in understanding user behavior and evaluating content effectiveness.AnQiCMS (AnQiCMS) provides a convenient 'Statistics Code Tag' feature, allowing us to easily deploy various third-party statistics codes to the website.However, if you are not careful with the method, it is easy to inadvertently insert the same statistical code repeatedly, which not only may lead to distortion of traffic data, but may also slow down the page loading speed and affect the user experience.
How can we cleverly avoid inserting the statistics code repeatedly when using the 'Statistics Code Tag' of Anqi CMS?
Understand the working principle of the 'Statistics Code Tag'
Firstly, we need to clarify the positioning of the "statistical code tag" in the Anqi CMS. It usually refers to the way it is implemented through the template file by{{- pluginJsCode|safe }}Such a label to output the statistics script.The content of these scripts is configured through the "Link Push" feature under the "Function Management
After you paste Baidu statistics, Google Analytics, or other JS statistics code in the background management area,pluginJsCodeThe tag will automatically output this code on each page of the website.The purpose is to provide a unified entry for conveniently managing those third-party statistical scripts that need to be loaded on all pages.
Why does the situation of repeated insertion of statistical code occur?
The repeated insertion of statistical code usually originates from the following common mistakes:
- Misunderstanding the use of tags, manually inserted in multiple places:Some friends may think that the 'statistics code tag' is only applicable to a specific type of statistics code (such as only applicable to 360 statistics), and manually paste other statistics codes like Google Analytics.
base.htmltemplate file<head>or</body>before the end tag. IfpluginJsCodeit also outputs other statistical codes, which causes repetition. - carelessness when directly editing the template file:When developing or adjusting a website template, in order to quickly verify, we may directly in
base.htmlOr other hard-coded statistical codes in the common header / footer templates.If this code has already been configured through the "statistics code tag" in the background, or manually inserted elsewhere, it is easy to forget and cause duplication. - The连带effectsof template inheritance and introduction:AnQi CMS supports powerful template inheritance and import features (such as
extendsandincludetags). If the statistical code is placed in a template that is used by multiple sub-templatesincludeorextendsin a common code snippet, which in turn includes passing throughpluginJsCodethe output statistical code, which may cause the code to be rendered multiple times at different levels without knowing it.
Intelligent management, say goodbye to the trouble of repeated insertion
To completely avoid the repeated insertion of statistical codes, the core principle is:Single entry, centralized management.
Use the background 'Link Push' feature as the sole entry point for the statistics code:This is the most recommended and safest approach.The 'Function Management' section of AnQi CMS provides fields such as '360/Toutiao JS automatic submission'.You should paste all third-party statistical codes (such as Baidu Statistics, Google Analytics, CNZZ, etc.) that need to take effect throughout the site here.
{{- pluginJsCode|safe }}The unique data source for the tag. As long as all your statistics code goes through here and ensures that the template only contains one{{- pluginJsCode|safe }}tag (usually inbase.htmlof<head>or</body>before), it can effectively avoid repetition.Handle template files carefully, avoid hardcoding:Unless your statistics code has very special page-level requirements and cannot be met through backend centralized management, it is not recommended to hard-code statistics code directly in template files. If it is truly necessary, please strictly follow the following principles:
- Place it at the top level only
base.htmlIn:Statistical code should be placed at the top of the template inheritance chainbase.htmlin the file. - Choose the appropriate insertion position:Most statistical code is recommended to be placed in
<head>at the bottom of the tag, or</body>before the closing tag. Choose a fixed position and maintain consistency. - Only insert code that cannot be integrated in the background:Make sure the code you manually insert is the special code that is not provided in the background "Link Push" feature and must be operated in this way.
- Place it at the top level only
Regularly review and clean up the template code:Develop the habit of regularly checking template code, especially after version upgrades, template switching, or feature adjustments. Check
base.htmlas well as all theincludeorextendsThe public template fragment, make sure no forgotten, duplicate statistical code is hardcoded. You can view the page source in the browser and search for your statistical code keyword (such asgtag/baidu/cnzzEtc.), to quickly locate and check for duplicates.
By using these strategies, we can effectively manage statistical codes in the Anqi CMS, ensure data accuracy, and maintain the good running efficiency of the website.
Frequently Asked Questions (FAQ)
1. Should I add all the statistical codes through the 'Link Push' feature?Yes, it is strongly recommended to add all third-party statistical codes (such as Baidu Statistics, Google Analytics, ad conversion tracking codes, etc.) that need to take effect throughout the site uniformly through the relevant JS submission fields under the "Function Management" -> "Link Push" in the Anq CMS background.This is the simplest, safest, and most recommended approach, which can maximize the avoidance of code repetition and management chaos.
2. How do I place my statistics code at a specific position on the page, rather than in the global header or footer?If the statistics code has special placement requirements for page-level or component-level, and cannot be met through the backend global configuration, you can find the corresponding template file in 'Template Design' -> 'Template Editing' and manually insert it at the specific location.But please ensure that this part of the code does not duplicate the global code and make good comments to explain its particularity and placement reasons for future maintenance.{% if condition %}Logical judgment, avoid unnecessary loading.
3. Does my website using the Anqi CMS built-in traffic statistics and third-party statistics tools lead to data duplication?The traffic statistics provided by Anqi CMS (in "Data Statistics") are independent from third-party statistics tools (such as Google Analytics, Baidu Statistics).They usually adopt different data collection and processing mechanisms, so using them simultaneously will not cause data duplication.AnQi CMS collects its own access data and crawler monitoring, while third-party tools collect their own data.As long as the third-party statistical code itself is not inserted repeatedly, the data will not be confused.