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.