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

Calendar 👁️ 58

In website operations, performing refined data statistics on different pages or different access scenarios is the key to optimizing content strategies 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 quite flexible mechanisms to achieve this.

Refined traffic tracking: How AnQi CMS implements template-level statistical code management

Run a website, we often need to use various statistical tools to understand visitor behavior, such as Google Analytics, Baidu Statistics, heat map code, or pixel code for specific marketing activities.But not all code is suitable for all pages, sometimes we hope to load a set of statistical code on the homepage, another set on the product detail page, and even different tracking strategies for mobile and PC endpoints.How does AnQiCMS support this level of template-based statistical code management?

From the architecture and functional design of AnQi CMS, it provides users with a multi-level flexibility to handle the deployment of statistical codes.

1. Understanding the template mechanism of AnQi CMS

Firstly, it is important to understand that the foundation of Anqi CMS handling statistical codes lies in its powerful template system. The default template structure usually includes abash.htmlA file that acts as the "skeleton" of a website, responsible for defining the common parts of a page, such as the header, navigation, and footer. The most common way to insert global statistical code is tobash.htmlof<head>or<body>Place unified statistics code tags before the end tag, such as{{- pluginJsCode|safe }}. This tag will output the content based on the JS auto-submit code you configure in the background "Link Push" or "Global Settings".

However, simply global insertion cannot meet all the refined needs. The advantage of Anqi CMS lies in its ability to allow for deeper customization and overrides of templates.

Second, the independence of pages, categories, and document templates

An enterprise CMS provides extremely flexible content models, which means we can create custom models for different content types (such as articles, products, events), and further more, forA single document, a single category, and even a single independent pageSpecify an entirely different template.

  • category templateIn the background "Document Category" settings, we can specify a dedicated "category template" for each category. For example, your blog categories can useblog/list.htmland the news category may usenews/list.html.
  • Document TemplateSimilarly, in the "Publish Document" or "Page Management" sections, each article, product, or standalone page can be assigned a "Document Template". For example, your "About Us" page can be set topage/about.htmland other independent pages may use the defaultpage/detail.html.

The strength of this mechanism lies in the fact that if a page or category uses a custom template, then this custom template has complete control. You can choose not to include the global in this custom template.{{- pluginJsCode|safe }}Labels are not used, instead, dedicated statistics code for the specific page or category is embedded. For example, on a landing page template specifically used for a marketing campaignpage/campaign.htmlIn Chinese, you can directly write the conversion tracking code for the activity without affecting the statistics of other pages.

III. Code independence under multi-site management

For users managing multiple websites, the multi-site feature of AnQi CMS provides a natural isolation.Each independent site has its own independent backend settings, template configuration, and content data.This means that even under the same Anqi CMS system, each site can be configured with completely different statistical codes without interfering with each other.Site A can use Google Analytics, Site B may prefer Baidu Statistics, and even have unique event tracking codes, all of which are achieved through independent backend configurations and template rendering for each site.

Four, by injecting custom parameters to inject statistical code

If you need more granular control, or want to perform A/B testing without modifying the existing template file, the custom parameter feature in Anqi CMS's 'Global Feature Settings' comes in handy.

You can add custom parameters in the "Global Settings" backend, for example, name a parameter asGoogleAnalyticsCodeand set your GA code snippet as its value. Then, in the template, you can use{% system with name="GoogleAnalyticsCode" %}This tag is used to retrieve and output this code.

Further, you can add custom fields to store the exclusive statistical code of a specific page in the "Other Parameters" section, and then use it in the template of that page,{% archiveDetail with name="YourCustomAnalyticsField" %}or{% pageDetail with name="YourCustomAnalyticsField" %}Call this method. This makes managing the statistical code more modular and easier to adjust without touching the core template logic.

Five, implement dynamic loading combined with template logic

For advanced users, even within a single template file, you can make conditional judgments using the powerful Django template engine syntax of Anqie CMS to dynamically load statistics code. For example, you can determine which segment of statistics code to load by judging the category ID, document ID, or URL path of the current page:

{% if archive.CategoryId == 10 %}
    <!-- 针对分类ID为10的页面的专属统计代码 -->
    <script>
        // Category 10 specific analytics
    </script>
{% elif archive.ModuleId == 2 %}
    <!-- 针对产品模型页面的专属统计代码 -->
    <script>
        // Product module specific analytics
    </script>
{% else %}
    <!-- 默认统计代码 -->
    {{- pluginJsCode|safe }}
{% endif %}

This way enables a template to intelligently load different statistical logic according to the context, greatly enhancing flexibility.

Summary

In summary, AnQi CMS indeed supports inserting different statistical code snippets into different templates. Whether by rewriting the entire page template, using the isolation of the multi-site function, or combining custom parameters with template tags through the backend, even applying conditional logic within the template, AnQi CMS provides operators with ample tools and flexibility to achieve precise tracking of website traffic and user behavior.

Related articles

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

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

## Flexible control of statistical code in AnQiCMS: no need to modify the template, easily turn on and off in the background Statistical codes (such as Baidu statistics, Google Analytics, CNZZ, etc.) are indispensable tools in modern website operations, helping 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 mistakes.AnQiCMS fully considers this user demand and provides a solution that does not require direct editing of template files

2025-11-07

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 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

How to avoid inserting the same statistics code twice when using the 'Statistics Code Tag'?

The website is in operation, traffic statistics are an indispensable link to understand user behavior and evaluate the effectiveness of content.AnQiCMS (AnQiCMS) provides a convenient "Statistical Code Tag" feature, allowing us to easily deploy various third-party statistical codes to the website.However, if you are not careful with the method, it is easy to inadvertently insert the same statistical code repeatedly, which not only may lead to distortion of traffic data but also may slow down the page loading speed, affecting user experience.

2025-11-07

Can the 'Crawler Monitoring' identify malicious crawlers or crawler attacks?

Good, as an experienced website operator, I will talk to everyone about the AnQiCMS (AnQiCMS) crawler monitoring function, as well as its actual role in identifying malicious crawlers and responding to attacks. --- ### Can AnQi CMS identify malicious crawlers and attacks?In today's internet environment, website operators often face various challenges, among which the management of crawlers (also known as spiders) is undoubtedly an important aspect.We all know that the friendly crawler of a search engine is the key to a website getting traffic, but at the same time

2025-11-07