As an experienced website operations expert, I know the value of data for website growth.Whether it is to optimize user experience, improve conversion rate, or develop accurate marketing strategies, it is indispensable to conduct in-depth analysis of access data.The AnQiCMS (AnQiCMS) takes the operator's needs into full consideration from the beginning of its design, and its powerful and flexible functions make it extremely easy to integrate third-party statistical tools.
Today, let's talk about how to elegantly integrate the code of third-party statistical tools like Baidu Statistics and Google Analytics into your company's CMS website, allowing your website to transform from 'unknown' to 'detailed observation'.
How to easily embed third-party statistics tool code in Anqi CMS website and understand user behavior?
To gain a comprehensive understanding of the behavior patterns of users on your security CMS website, third-party statistical tools are undoubtedly your powerful assistant.These tools can collect and present key metrics such as visitor sources, page views, dwell time, and bounce rate, helping you make data-driven decisions.It is fortunate that Anqi CMS provides various methods, allowing you to easily integrate these statistics codes into your website.
The powerful template engine and flexible backend settings of Anqi CMS provide convenience for embedding various codes.通常,统计代码是一段JavaScript代码片段,它需要在您网站的每个页面加载时执行。<head>Region,<body>Start or<body>End position of
Understand the structure of AnQi CMS: paving the way for embedded statistics code
In AnQi CMS, the generation of web pages depends on its modular template system. All template files are stored in/templatedirectory, and named with.htmlwith the suffix. Common template files likebash.html(usually contains the public header and footer of the website)、partial/Code snippets under the directory, are all areas we may need to pay attention to.
The backend of Ruan'an Enterprise CMS provides an intuitive and convenient configuration entry for website operators.In the "Feature 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.
方法一:通过English CMS后台的便捷设置(推荐)
This is the most recommended and simplest method, suitable for most scenarios where statistical code needs to be globally embedded in a website.The AutoCMS provides a dedicated text box, allowing you to directly paste statistics code without touching any code file.
步骤一:获取您的统计工具代码
First, you need to log in to the backend of the third-party statistics tool (such as Baidu Statistics, Google Analytics) you have chosen, find and copy your website statistics code. Usually, this will be a piece of code with<script>Tag opening and closing JavaScript code block.
- Baidu Statistics:Login Baidu Statistics -> Manage -> Website List -> Get Code -> Copy the entire code snippet.
- Google Analytics (GA4):EnglishLogin to Google Analytics -> Manage -> Data Streams -> Select your Web Data Stream -> View code instructions -> Global website code (gtag.js) -> Copy the entire code snippet.
请确保您复制的是完整的代码块,包括English<script>and</script>Label.
步骤二:登录安企CMS管理后台English
Use your administrator account and password to log in to the backend of your security CMS website.
Step three: Find the "Link Push" feature
Click on the left navigation bar in the backend interface in turn“Function Management”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 of360/Top Stories auto-submit JSThis is the text area. This area is exactly prepared for this kind of general JS code. Paste the complete statistical code you copied in step one into this text box.
After pasting, please make sure to click the bottom of the page“Save”Button. The AnQi CMS will save this code in the database and automatically inject it into the website page each time the page is rendered. The AnQi CMS template rendering will call{{- pluginJsCode|safe }}This tag (based on the document)tag-tongji.mdensure that your code is safely output to the front end.
Step five: clear the cache and verify the effect
To ensure that the changes take effect immediately, please click the left navigation bar in the background.Update Cache.
Then, open your website's frontend page. You can verify whether the code has been successfully embedded in the following way:
- Browser Developer Tools:Press
F12Open the browser developer tools, switch to the “Elements” or “Sources” tab. Search for the unique string in your statistics code snippet (for exampleanalytics.js/gtag.jsor Baidu statisticshm.js),to see if it appears on the page<head>or<body>Tags inside. - statistical tool auxiliary plugin:Install Google Tag Assistant for Chrome or Baidu Statistics Debugger and other browser plugins, they can help you detect the statistics code running on your website.
Method two: Directly modify the template file (for advanced users and special requirements)
If you have more specific control requirements for the code, such as embedding it only on specific pages, needing to place it at a specific location on the page, or if your statistics tool code requires strict placement, then modifying the template file directly would be a more flexible choice.
步骤一:定位合适的模板文件
The template files of Anqi CMS are usually located in/template/您的主题名称/目录下。您需要根据统计代码的放置要求,找到最合适的模板文件:
- 全局头部:最常见的是主题目录下的
bash.html, orpartial/header.htmlThis kind of file. Usually used to place<head>code within the region. - Global footer:
bash.htmlbottom, orpartial/footer.htmlThis kind of file. Usually used to place<body>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 single page, you need to find the corresponding
index.html/{模型table}/detail.htmlorpage/detail.htmlin these files.
Step 2: Online template editing
Login to the AnQi CMS backend, click on the left-hand navigation bar of the“Template Design”then select“Website Template Management”. Here, you can directly edit your theme template files online.
Step three: Paste the statistics code carefully.
Open the template file you are sure to modify. Paste the code into the corresponding position according to the requirements of the statistics tool.
- placed in
<head>Inside the tag:Find<head>and</head>Paste the code between the two points. - placed in
<body>End tag before:Find</body>Label before, paste the code.
Please note that since the statistical code is standard JavaScript code, it usually does not conflict with the Django-like template syntax of Anq CMS. You can paste it directly without using{% raw %}or{% endraw %}each enclosed by tags.
Step four: Save and verify the effect
Click the bottom of the page after pasting the code“Save”button. Similarly, go to the left navigation bar in the background and clickUpdate Cache.
Finally, as in method one, verify whether the statistical code is working on your website page by using the browser developer tools or statistics helper plug-ins.
Operation Expert's温馨提示:Ensure the accuracy and correctness of the statistics data
No matter which embedding method you choose, the following suggestions will help you better manage and utilize the statistics data:
- Consideration of code placement:Most statistical tools recommend placing code in:
<head>Tags in, to ensure that the data can be captured at the beginning of page loading. However, if considering the page rendering performance, some non-essential tracking code can also be placed in</body>Before the end tag. - The importance of caching:In the AnQi CMS, it is recommended to clear the cache in time after any modification to the background configuration or template files to ensure that the latest content is loaded on the front-end page.
- Regular Inspection: