As a website operator, we often need to adjust or replace the statistical code used on the website according to business development and data analysis needs.Whether it is to migrate from the old statistical platform to the new platform, or to introduce more refined data tracking, this process requires us to complete the switch efficiently and smoothly, to avoid any interference with the normal operation of the website.

The Anqi CMS fully considered these operational level flexibilities from the beginning, providing a very convenient "statistical code tag" feature, making it extremely simple and safe to replace existing statistical codes.Let's take a look at how to use this feature to implement a smooth switch in the statistical code.

Familiarize yourself with the 'Statistics Code Tag' of AnQi CMS

In AnQi CMS, there is no direct backend setting item called 'Statistics Code Tag', but this feature is cleverly integrated into the 'Link Push' module under 'Function Management', specifically reflected in the '360/Toutiao and other JS automatic submission' setting item.This name might lead people to believe that it can only be used for the statistics of 360 or Toutiao, but in fact, it is a universal JS code auto-submit box, which can be used for unified management for any statistics code based on JavaScript, such as Baidu Statistics, Google Analytics, Matomo, or any other JavaScript-based statistics code.

There will be a preset 'Statistics Code Tag' within the system (i.e.{{- pluginJsCode|safe }}),It will automatically insert any JS code you enter in this background setting box, securely and completely into the corresponding position of the website (usually on the<head>or<body>Tag inside), ensure that the code can be loaded and executed correctly.The benefit of this design is that you do not need to directly modify any template files, all code management is completed in the background, which greatly reduces the technical threshold and risk of errors in operation.

steps for a smooth transition of statistical code

When you need to replace the statistical code on the website, Anqi CMS provides the following simple and intuitive steps:

  1. Obtain the new statistical code:First, you need to go to the new statistics platform (such as Google Analytics 4, Baidu Statistics, etc.), find and copy the complete JavaScript statistics code provided. Make sure that the code you copy is complete, as it will usually include<script>and</script>.

  2. Log in to the Anqi CMS backend, locate the settings entry:Log in to your AnQi CMS admin interface. In the left navigation bar, find and click on "Function Management", then select the sub-menu "Link Push".

  3. Replace old code, paste new code:On the "Link Push" page, you will see a text box named "360/Toutiao and other JS automatic submission."}This text box should currently contain the statistical code your website is using. To smoothly switch, simply delete all the existing statistics code from this text box and then paste the new statistics code you copied in the first step.Please note that even if the new statistical code is just a line or a few lines, make sure it includes<script>and</script>.

  4. Save settings and update cache:After pasting the new code, be sure to click the "Save" or "Submit" button at the bottom of the page to make the changes effective.To ensure that the website front-end can immediately load the new statistical code, it is recommended that you click on the "Update Cache" function in the left navigation bar later and clear the website's cache.This can make the latest configuration take effect immediately.

  5. Verify that the statistical code is working:After completing the above steps, open your website's front-end page, and use the browser's developer tools (usually F12), to view the page source code or network requests.

    • View the source code:Search for the characteristics of the statistical code you have just pasted, to see if it has already appeared in the HTML of the page.
    • View network requests:In the network tab of the developer tools, filter the JS files, you can usually see the loading requests for statistics scripts (such asanalytics.js/gtag.jsorhm.jsetc).
    • Use the statistics platform to report in real time:Log in to the backend of the new statistics platform to view the real-time report function.If you can see that there are visitors browsing your website (which is yourself), then it means that the new statistics code has been successfully installed and is now working.

Why is this switching method smooth and efficient?

The 'Statistics Code Tag' feature of Anqi CMS can achieve smooth and efficient switching mainly due to its core advantages:

  • Do not touch the template file:You do not need to open an FTP client, nor do you need to face complex HTML/Twig template code; all operations are completed in the intuitive backend interface, greatly reducing the risk of误operation.
  • One-click full site update:Just replace the code once in the background and save, Anqi CMS can ensure that this new statistical code takes effect on all pages of your website without having to modify each page individually.
  • Centralized management, clear and concise:All statistical codes are managed in one place, so they can be quickly located when auditing, modifying, or removing, avoiding the situation where codes are scattered and difficult to maintain.
  • Rapidly respond to operational changes:Whether it is the change in data analysis requirements or the need to urgently deploy new tracking codes for market activities, this centralized management can allow you to respond quickly and ensure the continuity of data tracking.

In this way, even if you are not very familiar with programming and website development, you can easily manage and replace the statistical code of the website, making your content operation and data analysis work smoother.


Frequently Asked Questions (FAQ)

Q1: Can I use two different statistics codes (such as Baidu Statistics and Google Analytics) at the same time in the "JS Auto Submit" box?Of course you can. Just paste the two statistical codes one after another in the text box of '360/Toutiao and other JS automatic submission'.The 'Statistics Code Tag' of Anqi CMS will insert them into the website page in the order you paste.Make sure each statistics code block contains the complete<script>.

Q2: Can I use a specific tracking code only on certain pages instead of site-wide, can Anqi CMS achieve this?The 'Statistics Code Tag' of AnQi CMS is mainly used for the common statistics code throughout the site.If you have a page-level detailed statistical requirement, such as loading special code only on a specific event page, or excluding certain pages from loading general code, this usually requires a deeper template edit.You can make conditional judgments in the template file based on the current page ID, category ID, or other identifiers, and then manually insert or exclude specific code.Of course, this requires some knowledge of template development.

Q3: Why did I replace the statistical code and cleared the cache, but the front-end page still does not display the new code?There are several possible reasons:

  1. Browser Caching:Your browser may be caching an old version of the page. Try force refreshing the page (Ctrl+F5 or Cmd+Shift+R), or clear the browser cache and visit again.
  2. CDN cache:If your website uses a CDN service, the CDN nodes may cache old pages. You need to log in to the CDN service provider's backend and manually refresh the entire site cache.
  3. Code error: The statistics code you have pasted may contain syntax errors or be incomplete, causing it to fail to load. Please carefully check whether the code you copied from the statistics platform is complete and error-free.
  4. The background save did not take effect:Please confirm again that you have saved the changes in the Anqi CMS background, and the system prompts that the save was successful. Sometimes network issues can cause the save to fail.