As an experienced website operations expert, I know the value of data for the growth of the website.It cannot be separated from the in-depth analysis of access data whether it is to optimize the user experience, improve conversion rates, or formulate precise marketing strategies.AnQiCMS (AnQiCMS) took the operator's needs into full consideration from the very beginning of its design, its powerful and flexible features make it extremely easy to integrate third-party statistical tools.
Today, let's talk about how to elegantly embed the code of third-party statistics tools like Baidu Statistics and Google Analytics into your secure CMS website, so that your website can go from being 'unknown' to 'keenly aware of things'.
How to easily embed third-party statistical tool code in AnQi CMS website and insights into user behavior?
Want to fully understand the behavior track of users on your security CMS website, third-party statistical tools are undoubtedly your helpful assistant.These tools can collect and present key metrics such as visitor sources, page views, dwell time, bounce rate, and help you make data-driven decisions.Fortunately, AnQi CMS provides multiple ways for you to easily integrate these statistics codes into your website.
The powerful template engine and flexible backend settings of AnQi CMS provide us with the convenience to embed various codes.Statistical code is a JavaScript code snippet that needs to be executed on each page of your website when loaded.According to the requirements of the statistical tool, this code may need to be placed on the page.<head>Region,<body>The start or<body>End position of the.
Understanding the structure of Anqi CMS: paving the way for embedded statistical code
In AnQi CMS, the generation of website pages depends on its modular template system. All template files are stored in/templatethe directory, and.htmlsuffix. Common template files such asbash.html(usually includes the public header and footer of the website),partial/The code snippets under the directory are all areas we need to pay attention to.
The backend of Anqicms provides an intuitive and convenient configuration entry for website operators.In the 'Function Management' module, there is a dedicated area for embedding this kind of general JS code, which greatly reduces the technical threshold.
Next, I will introduce two mainstream embedding methods, whether you are pursuing simplicity and speed, or need fine-grained control, you can find a suitable solution for yourself.
Method one: Through the convenient settings of the Anqi CMS backend (recommended)
This is the most recommended and simplest method, suitable for most scenarios where it is necessary to embed statistical code globally on the website.The Anqi CMS provides a dedicated text box, allowing you to directly paste statistics code without touching any code files.
Step one: Get your statistics tool code
First, you need to log in to the backend of the third-party statistical tool you have chosen (such as Baidu Statistics, Google Analytics), find and copy the website statistical code. Usually, this will be a segment that starts with<script>Tag start and end JavaScript code block.
- Baidu Statistics:Log in to Baidu Statistics -> Manage -> Website List -> Get Code -> Copy the entire code snippet.
- Google Analytics (GA4):Log in to Google Analytics -> Manage -> Data Streams -> Select your Web Data Stream -> View code instructions -> Global website code (gtag.js) -> Copy the entire code snippet.
Make sure you copy the entire code block, including<script>and</script>.
Step two: Log in to the Anqi CMS management background
Log in to the admin panel of your Anqí CMS website using your admin account and password.
Step three: Find the "Link Push" feature
Click sequentially in the left navigation bar of the admin interface.“Function Management”and then select"Link Push". You will see settings such as "Baidu Search Active Push Interface",
Step four: Paste and save the statistics code
Scroll down the page and you will find a name called“360/Top News and others JS auto-submit”The text area. This area is specifically designed for this type of general JS code. Paste the statistics code you copied in step one completely into this text box.
After pasting, please be sure to click the bottom of the page.“Save”Button. AnQi CMS will save this code in the database and automatically inject it into the website page during each page rendering. The template rendering of AnQi CMS will call{{- pluginJsCode|safe }}This label (based on the documenttag-tongji.mdas stated), ensure that your code is safely output to the frontend.
Step five: Clear the cache and verify the effect
To ensure that the changes take effect immediately, please click on the left navigation bar in the background.“Update Cache”.
Then, open your website's frontend page. You can verify that the code has been successfully embedded in the following way:
- Browser Developer Tools: Press
F12Press the key to open the browser developer tools, switch to the "Elements" or "Sources" tab. Search for the unique string in your statistics code snippet (such asanalytics.js/gtag.jsOr Baidu Statisticshm.js), see if it appears on the page<head>or<body>Tag inside. - Statistical tool auxiliary plugin:Install Google Tag Assistant for Chrome or Baidu Statistics Debugger and other browser plugins, which can help you detect the statistics code running on your website.
Method two: Directly modify the template file (suitable for advanced users and special needs)
If you have a finer control requirement for the code, such as embedding it only on specific pages, needing to place it at a specific position on the page, or if your analytics tool code requires strict placement, then directly modifying the template file would be a more flexible option.
Step 1: Locate the appropriate template file
The template files of AnQi CMS are usually located/template/您的主题名称/in the directory. You need to find the most suitable template file according to the placement requirements of the statistical code:
- Global header:The most common is the theme directory under:
bash.htmlOrpartial/header.htmlThis type of file. It is usually used to place<head>the code within the area. - Global bottom:
bash.htmlat the bottom, orpartial/footer.htmlThis type of file. It is usually used to place<body>the code before the end tag, which helps improve page loading performance. - Specific Page:If it is only embedded on the homepage, article detail page, or a specific single page, you need to find the corresponding
index.html/{模型table}/detail.htmlorpage/detail.htmletc. files.
Step 2: Online Template Editing
Log in to the Anqi CMS backend, click the left-hand navigation bar's“Template Design”and then select“Website Template Management”. Here, you can directly edit your theme template files online.
Step three: Paste the statistical code carefully
Open the template file you are sure to modify. Paste the code into the corresponding position according to the requirements of the statistical tool.
- in
<head>Inside the tag:Find<head>and</head>Paste the code between them. - in
<body>Before the closing tag:Find</body>Before the label, paste the code.
Please note that the statistical code is standard JavaScript code and usually does not conflict with the Django-like template syntax of AnQi CMS. Paste it directly without any modification.{% raw %}or{% endraw %}tag wrapping.
Step 4: Save and verify the effect
After pasting the code, click the bottom of the page“Save”button. Similarly, go to the left navigation bar in the background and click“Update Cache”.
Finally, as in Method 1, verify that the statistical code has been activated on your website page by using browser developer tools or auxiliary plugins for statistical tools.
Operation expert's reminder: Ensure the statistics are accurate and error-free
No matter which embedding method you choose, these suggestions will help you better manage and utilize the statistics:
- Consideration of code placement:Most statistical tools recommend placing the code in
<head>Within tags, to ensure that data can be captured at the beginning of page loading. However, when considering the page rendering performance, some non-critical tracking code can also be placed in</body>Before the end tag. - The importance of caching:In Anqi CMS, any modifications to the background configuration or template files are recommended to clear the cache in a timely manner to ensure that the latest content is loaded on the front-end page.
- Regularly check: