How to dynamically enable or disable the 'Statistics Code Tag' without modifying the template file?

Calendar 👁️ 62

Flexible control of statistics code in AnQiCMS: No need to modify the template, easily turn on and off in the background

In modern website operations, statistical codes (such as Baidu Statistics, Google Analytics, CNZZ, etc.) are indispensable tools that help us understand user behavior and optimize website performance.However, frequently modifying the template file to add, update, or remove this code is not only inefficient but may also introduce errors due to operational errors.AnQiCMS (AnQiCMS) fully considers this user requirement and provides a convenient way to dynamically manage statistical codes without directly editing template files.

Unveiling the core mechanism: The 'magic placeholder' in the template and the linkage with background configuration

The AnQi CMS can realize this function due to its flexible template tag design and powerful backend management system.In AnQi CMS template files, there is usually a placeholder reserved for inserting this type of JavaScript code.This placeholder is{{- pluginJsCode|safe }}.

This tag plays a key role:

  • pluginJsCode: It is a variable whose content comes from the specific settings of the Anqi CMS backend.
  • |safe: This is a filter that tells the template engine,pluginJsCodeThe content in the variable is safe HTML or JavaScript code, it does not need to be escaped and can be output directly to the page.This is crucial for the normal execution of JavaScript code.
  • {{- ... }}: Here-The symbol is used to remove the whitespace on the line where the tag is located, making the final output code cleaner.

When the page is accessed, Anqi CMS will checkpluginJsCodeIs there content in the variable. If there is, it will be inserted into the page completely;If empty, no code will be output. And the content of this variable is completely determined by your backend configuration, thus achieving dynamic control.

The specific operation steps: three steps to easily manage statistical code management

To dynamically turn on or off the website's statistical code, the operation process is very intuitive:

Step one: log in to the background, locate the function entry

First, you need to log in to the admin backend of your Anqi CMS website. Find and click on it in the left navigation menu.“Function Management”In the expanded feature list, select."Link Push".

Step 2: Find the "360/Top Stories etc. JS Auto Submit" setting item

In the 'Link Push' page, you will see the '360/Toutiao and other JS automatic submission' settings area.Although the naming mentions 360 and Toutiao, this text box is actually universal, you can paste any JavaScript statistics code or third-party script that needs to be globally loaded here.

Step 3: Paste or clear the code to achieve dynamic control

  • Enable statistics code:Copy the JavaScript code you obtain from a statistics platform (such as Baidu Statistics, Google Analytics, etc.) (Make sure to include the complete<script>and</script>TagPaste into this text box. After pasting is complete, click save. Your website's front-end page will automatically load this statistics code.
  • Turn off the statistics code:If you wish to temporarily disable or completely remove the statistics code, simply clear the entire contents of the text box.After clearing, click save. The website front-end page will no longer load any statistical code.

By this method, you can always operate in the background interface without using an FTP tool or manually modifying any template files.

Why is it so convenient? The design philosophy of AnQiCMS

Anqi CMS is committed to providing efficient, customizable and easy-to-manage content solutions. This statistical code management method is a reflection of its "usability" and "flexibility":

  • Lower the technical threshold:Website operators do not need to have front-end development knowledge and can easily manage key code.
  • Improve operational efficiency:Respond quickly to changes in statistical requirements, such as temporarily closing a section of code for testing, or switching statistical scripts during different marketing campaigns.
  • Ensure system security and stability:Avoided syntax errors or code conflicts that may be introduced by manually modifying template files, keeping the website more stable.
  • Centralized management:All third-party scripts are managed in one place, making it convenient for auditing and maintenance.

Practical tips and注意事项

  1. Must include the complete<script>Tags:The JavaScript code snippet you paste must end with<script>and ends with</script>otherwise the code will not execute normally.
  2. Update the cache in time:After modifying and saving the code in the background, it is recommended to go to the 'Update Cache' feature to clear the website cache to ensure that the front-end page can immediately load the latest code settings.
  3. Code placement location:The template design of Anqi CMS determines{{- pluginJsCode|safe }}The actual output position of the tag. Typically, the statistical code will be placed before</body>or after the tag<head>In the tag. If you have specific requirements for the loading order or position of the code, you may need to refer to your template file to understandpluginJsCodeThe specific embedding point. However, for most general statistical codes, the default insertion position is sufficient.
  4. Test verification:After changing the statistical code, be sure to visit the website's front-end page and use the browser's developer tools (F12) to check the network requests and console logs to confirm that the statistical code is loaded and executed correctly.

Through the feature provided by Anq CMS, you can manage the website's statistics code as simply as managing article content, making website operations more relaxed and efficient.


Frequently Asked Questions (FAQ)

Q1: Can this feature only be used for the 360 and Toutiao statistical codes?

A1: No. Although the name of the function entry is "360/Toutiao and other JS automatic submission", this is just a demonstrative naming.In fact, you can paste any third-party statistics, monitoring, and advertising投放 JavaScript code (such as Baidu Statistics, Google Analytics, Tencent Analysis, website customer service, etc.) in this text box.It is a generic JavaScript code insertion point.

Q2: What if I need to insert multiple statistical codes? Can I paste them all in one text box?

A2: Absolutely. If you need to insert multiple statistics or third-party JS code, just paste them one by one in the order required into this '360/Toutiao and other JS automatic submission' text box.Make sure every piece of code includes the entire<script>and</script>Label. Anqi CMS will output these codes to the front-end page in the order you paste them.

Q3: Where will the statistics code be inserted into the page? It is in<head>Or<body>before the end?

A3: This depends on the specific design of the AnQiCMS template you are using. Usually, AnQiCMS will place{{- pluginJsCode|safe }}This tag in the template file.</body>Before the closing tag, or<head>Inside the tag. If you have specific requirements for the precise insertion location of the code, it is recommended to refer to the current template you are usingbase.htmlor find the common header/footer file,pluginJsCodeThe exact location of the label. Placing it</body>before is a good compatibility choice.

Related articles

Can the 'Traffic Statistics' monitor the use of in-site search keywords?

Can the traffic statistics of AnQi CMS monitor in-site search keywords?Practical Analysis and Operation GuideThese keywords not only reflect the real needs of users, help us find content blind spots, but are also valuable wealth for optimizing content strategy and improving user experience.So, for the users of AnQiCMS, can we use its built-in traffic statistics feature to understand the usage of these in-site search keywords?

2025-11-07

If the website has enabled multilingual, can the statistics code distinguish between different language versions for statistics?

Under the background of globalization, enabling multilingual functions on websites has become an important step for enterprises to expand into international markets.For operators, how to accurately grasp user behavior data on different language versions of websites to optimize content and marketing strategies is a practical and critical issue.Can the statistics code be distinguished for different language versions after the website has enabled the multilingual function in AnQiCMS (AnQiCMS)?The answer is affirmative, and Anqie CMS provides a flexible implementation foundation.

2025-11-07

Does the 'Data Statistics' feature provide user behavior path analysis?

When operating a website, we always hope to gain a deeper understanding of visitors, to master their every move, so as to continuously optimize website content and user experience.AnQi CMS is a system focused on enterprise-level content management and naturally has some achievements in data statistics.However, many friends may be curious whether its data statistical function covers such advanced dimensions as user behavior path analysis.From the core feature description of AnQi CMS, it clearly provides the feature of "traffic statistics and spider monitoring".

2025-11-07

How to view the current code content of the 'Statistics Code Tag' through the Anqi CMS backend?

When using AnQi CMS to manage a website, we often need to integrate various third-party statistical tools, such as Baidu Statistics, Google Analytics, or other advertising platform monitoring codes.These codes are usually referred to as 'statistical code tags', which help us track website traffic, user behavior, and other key data.Sometimes, in order to verify that the code is installed, updated, or to troubleshoot issues, we need to directly view the current statistical code content being used on the backend.

2025-11-07

Does the 'Data Statistics' function of Anqi CMS have a time limit for data storage (for example, only retain N days)?

During the operation of a website, the data statistics function is undoubtedly our 'all-seeing eye', helping us to understand the operation status of the website, understand user behavior, and continuously optimize content and strategies.Friends who use AnQiCMS may all be concerned about an important issue: whether the valuable data provided by it, such as website traffic and crawler access records, also have a storage time limit, such as being automatically cleared after N days?

2025-11-07

Does the statistics code tag support inserting different statistics code snippets in different templates?

In website operation, it is crucial to conduct refined data statistics on different pages or different access scenarios to optimize content strategy and user experience.This usually involves inserting specific statistical code snippets into different templates.For users of AnQiCMS, this is a very practical need, fortunately, the system itself provides a very flexible mechanism to achieve this.

2025-11-07

Does the traffic statistics data get affected by ad blocking plugins?

Does the traffic statistics of AnQi CMS affected by ad blocking plugins?In-depth analysis and response strategies In the process of using Anqi CMS to manage website content, everyone may pay attention to a core feature: traffic statistics.It can help us understand the website's visit situation and optimize content strategy.But a common problem also arises: Will the traffic data we see be affected by ad-blocking plugins?

2025-11-07

Does the 'Data Statistics' feature of AnQi CMS support custom event tracking?

In website operation, data statistics is an indispensable part of understanding user behavior and optimizing content strategy.It is particularly important for operators using AnQiCMS to understand the depth and breadth of its built-in data statistics function, especially the support for "custom event tracking". ### Overview of AnQi CMS built-in data statistics function AnQi CMS, designed specifically for small and medium-sized enterprises and content operation teams, provides basic and practical functions in data statistics.

2025-11-07