How to use the `add` filter to dynamically add custom tracking parameters to `tag` links?

Calendar 👁️ 61

In website operation, we often need to track user behavior, evaluate the effectiveness of marketing through different channels.Adding tracking parameters dynamically to website links is an effective method.AnQi CMS is an efficient and flexible content management system that provides a powerful template engine and a rich set of filters, allowing us to easily meet this requirement.

Today, let's discuss how to use the Anqi CMS'saddfilter to dynamically add custom tracking parameters to the links of the "Tag (Tag)".

Why do we need to add tracking parameters to label links?

Tags (Tag) play an important role in the organization of website content, they not only help users discover related content but are also crucial for search engines to understand the structure of the website. Adding tracking parameters to tag links, such as UTM parameters, can help us:

  • Analyze the source of traffic in detail:Understand how users enter specific content pages through which tags.
  • Evaluate the effectiveness of marketing activities:If the tag link is used for external promotion, it can track the traffic and conversion it brings.
  • Optimize content strategy:By analyzing users' preferences for different tags, adjust and optimize the direction of content production.
  • A/B testing:Test the display form or parameters of links to different tags, and find out **practice.

AnQi CMS uses Django template engine syntax, its built-inaddfilters are the tools to achieve this function.

Get to knowaddFilter

in the AnQi CMS template world,addThe filter plays the role of a 'connector'.Its main function is to concatenate two values, whether it is adding numbers or concatenating strings.addThe filter is very useful because it can combine the original link string with the parameter string we define.

Its basic usage method is very intuitive:{{ 变量 | add: "要添加的内容" }}For example,{{ "安企" | add: "CMS" }}The result is安企CMSThis ability to concatenate strings is the basis for adding parameters to URLs.

Locate the tag link in the Anqi CMS

In Anqi CMS templates, tag links are usually obtained through the following two tags:

  1. tagListTags:Used to display multiple tag lists on the article detail page, sidebar, or a dedicated tag aggregation page.

    {% tagList tags with limit="10" %}
        {% for item in tags %}
            <a href="{{item.Link}}">{{item.Title}}</a>
        {% endfor %}
    {% endtagList %}
    

    here,{{item.Link}}That is the original link address of each tag.

  2. tagDetailTags:Used on the detail page of a single tag (such astag/detail.html) Get the detailed information of the current tag, including its link.

    <a href="{% tagDetail with name="Link" %}">前往此标签</a>
    

    Or

    {% tagDetail tagInfo with name="Link" %}
    <a href="{{tagInfo}}">前往此标签</a>
    

    here,{% tagDetail with name="Link" %}or{{tagInfo}}That is the link of the current tag.

In either case, the core is to obtain the original link variable of the tag and then utilizeaddFilter it.

Practice: Add tracking parameters dynamically to tag links.

Now, we are ready to manually add custom tracking parameters to these tag links.

Scenario one: TotagListAdd a fixed tracking parameter to the generated tag list

Suppose we want to add a fixed UTM parameter to all tag links, such as?utm_source=anqicms_tag&utm_medium=list. We can do it intagListthe loop, toitem.LinkapplyaddFilter:

{% tagList tags with limit="10" %}
    {% for item in tags %}
        <a href="{{ item.Link|add:"?utm_source=anqicms_tag&utm_medium=list" }}">
            {{ item.Title }}
        </a>
    {% endfor %}
{% endtagList %}

This, each tag link will become similarhttps://www.yourdomain.com/tag/seo.html?utm_source=anqicms_tag&utm_medium=listin the form of.

Scenario two: fortagDetailAdd a fixed tracking parameter to the individual tag link obtained

On a tag's detail page, if you want to add tracking parameters to the current page's tag link, the operation is similar:

{# 假设这是 tag/detail.html 模板中 #}
<a href="{% tagDetail with name="Link" %}|add:"?utm_source=anqicms_tag&utm_medium=detail" }}">
    进入此标签的详情页
</a>

Or, if you first assign the link to a variable:

{% tagDetail tagLink with name="Link" %}
<a href="{{ tagLink|add:"?utm_source=anqicms_tag&utm_medium=detail" }}">
    进入此标签的详情页
</a>

Advanced: Add dynamic parameters (such as tag ID and name)

In order to track more accurately, we may want to add the ID or title of the tag itself as a parameter. At this point, we can use it multiple times.addThe filter performs concatenation and it is necessary to encode dynamic content in URLs to prevent special characters from破坏URL structure. Anqicms providesurlencodeA filter to handle this issue.

{% tagList tags with limit="10" %}
    {% for item in tags %}
        {# 构造动态参数,确保对动态内容进行url编码 #}
        {% set dynamic_params = "&tag_id=" | add:item.Id | add:"&tag_title=" | add:item.Title|urlencode %}
        <a href="{{ item.Link|add:"?utm_source=anqicms_tag"|add:dynamic_params }}">
            {{ item.Title }}
        </a>
    {% endfor %}
{% endtagList %}

In this example:

  • We first defined a basic UTM parameter?utm_source=anqicms_tag.
  • Then, by using continuouslyaddThe filter, to&tag_id=/item.Id/&tag_title=anditem.TitleConcatenate.
  • Pay special attention to,item.TitleAs a URL parameter value, it may contain spaces, Chinese characters, and other special characters, therefore it must be used|urlencodeThe filter needs to be encoded to ensure the validity of the URL.

The generated link may be similar to:https://www.yourdomain.com/tag/seo.html?utm_source=anqicms_tag&tag_id=123&tag_title=SEO%E4%BC%98%E5%8C%96.

Points to note

In actual operation, there are several key points to pay attention to:

  1. The question mark in a URL (?) is followed by a connector (&):The first parameter in a URL parameter is preceded by a question mark?, subsequent parameters are followed by a connector&. Simply useaddFilter, cannot automatically judge whether the URL already contains parameters.
    • Suggested solution:If you are sure that the original label link does not contain any parameters, you can use it directly.?If the original link is possible

Related articles

Can the `add` filter be used to concatenate array elements processed by the `slice` or `split` filters to form a new string?

When developing templates with AnQi CMS, we often need to flexibly process and display data.This includes string splitting, slicing, and element connection.AnQi CMS provides a rich set of filters (filters) to help us complete these tasks, such as `add`, `slice`, and `split`.Sometimes, we might consider concatenating array elements obtained after processing with `slice` or `split` filters using the `add` filter to form a new string.But is this idea feasible

2025-11-07

How does the `add` filter flexibly combine fixed text with variable content when building dynamic prompt information?

In Anqi CMS template design, building dynamic prompts with real-time interactive features is the key to improving user experience.Whether it is to display product inventory, user welcome messages, or article reading volume, we hope to seamlessly combine fixed text with continuously changing variable content.At this point, the `add` filter becomes a very practical and flexible tool.The `add` filter in the Anqi CMS template is very intuitive: it can add or concatenate two values.This process has high intelligence. If the two values being operated on are of numeric type, it will perform mathematical addition.

2025-11-07

Does the `add` filter support chained calls, such as `{{ var1|add:var2|add:var3 }}` to concatenate multiple variables?

When developing templates in Anq CMS, we often encounter situations where we need to combine, concatenate, or sum multiple variables.Among them, the `add` filter is a very practical tool that allows us to perform addition operations on numbers or concatenate strings.However, some users may be curious whether the `add` filter supports a chain-like call like `{{ var1|add:var2|add:var3 }}` to concatenate multiple variables at once?Familiarize yourself with the template syntax of AnQi CMS after deep study

2025-11-07

How to use the `add` filter to dynamically add 'Published on:' before the blog post's publish time?

When operating a blog, we often hope that the publication time of the articles can be presented in a more intuitive and brand style compliant manner.For example, adding 'Published on:' before the date can make it clear to the reader that this is a published article.AnQiCMS (AnQiCMS) with its flexible template engine makes such customization very simple.Today, let's discuss how to cleverly use the built-in `add` filter of AnQiCMS to dynamically add the phrase 'Published on:' before the publication time of blog posts.

2025-11-07

How to efficiently concatenate values of different fields in the custom content model (`archiveParams`) using the `add` filter?

In AnQi CMS, we often encounter the need to combine multiple field values of a custom content model into a text that is more expressive or conforms to a specific display format.For example, you may need to concatenate the "brand" and "model" of the product into a complete product name, or connect the "area code" and "phone number" of the contact.At this time, the `add` filter provided by AnQiCMS combined with the `archiveParams` tag can help us efficiently perform these operations.###

2025-11-07

How to combine the `add` filter with the `stampToDate` function to concatenate a formatted date and time string?

When managing content in AnQi CMS, we often need to display dates and times in a specific format.The system provides very convenient template tags and filters to handle these requirements.Today, let's talk about how to combine the `add` filter with the `stampToDate` function to concatenate a formatted date-time string, making our content display more flexible and diverse.### Get to know the `stampToDate` function: Format timestamps First, let's review the `stampToDate` function

2025-11-07

How to use the `add` filter to dynamically generate the complete path segment in the breadcrumb navigation (`breadcrumb`)?

In website operation, breadcrumb navigation is one of the key elements to improve user experience and website SEO performance.It clearly shows the user's position on the website and provides a convenient way to return to the previous level page.AnQi CMS provides a powerful and flexible template tag system, where the `breadcrumb` tag can help us easily implement breadcrumb navigation.But if we need to dynamically adjust the path text or links in the breadcrumb navigation, the `add` filter of Anqi CMS can play a unique role.`breadcrumb`

2025-11-07

Does the `add` filter cause garbled or incorrect output when concatenating Chinese and English mixed strings?

When using AnQiCMS for template development, we often need to concatenate different text content, such as dynamically generated titles, descriptions, etc.At this time, the `add` filter has become a powerful tool in our hands.However, when dealing with mixed Chinese and English strings, many friends may worry: Will such concatenation produce garbled characters or cause program errors?Today, let's discuss this issue in detail.

2025-11-07