Content targeting using cookies and logic from Edge Computing

Edit on GitHub

Content targeting through cookies is used by the marketing and editorial teams to provide different experiences for users. Using javascript functions (client-side processing) or functions on the application backend (server-side processing) for this task, cookies are created that guide the content management application to respond to the different content for each segment of users.

Through serverless functions and Edge computing logics it is possible to create, evaluate and carry out the variation of these cookies directly in Edge. These tasks, when processed in Edge, improve the customer’s experience, the performance of the applications, the assertiveness in the distributions and the cost of the entire operation as it has the advantage of not using an additional processing flow.

Content targeting with Azion Edge Functions

The Edge Function Cookie Targeting is a serverless function of Azion’s Edge Computing platform that allows you to create and manipulate cookies for flexible usage logics, whether for content segmentation, or for handling specific application contexts, business rules or some other scenario that the customer wants to evaluate.

Create different scenarios, defining variants and distribution percentages for each one, with greater assertiveness and without burdening resources and interactions at the source. Create processing logic in edge, expanding the possibilities of applying the function and obtaining many other advantages:

  • targeted cache,
  • absorption of access peaks,
  • high performance,
  • distributed processing logic,
  • registration of events via data streaming

Before you start, make sure that the Edge Functions service is active in your Azion account and that you already have the function in your Edge Functions Libraries. If not, contact our sales team to enable the service.

Understanding the process

When a request arrives at edge, the algorithm distributes it according to the defined probability, and then a cookie is set with the expiration time and the values specified for each variant.

Setting up a scenario

In order to demonstrate a practical application of a Function configuration, we will use, as an example, a scenario in which you want to randomly deliver four versions of a landing page, through the variation of cookies, for behavior analysis later in data analytics tools (Google Analytics, for example). In this case, we want to make a uniform distribution of the variants, assigning the same percentage of values to each one.

To configure your case through Edge Function Cookie Targeting, edit the Edge Application you want to evaluate, checking if the Edge Function option is enabled in the Main Settings tab. Next, go to the Functions tab and add a new Cookie Targeting function, providing a meaningful name to your custom function (for example, MyCookieTargeting), as it is through the name that your Function will be identified later in the Rule Engine configuration. Note that the function code will appear in the Code field, just for reading and understanding; in the Args tab, inform the parameters for the execution of your test. Below is the description of each field of the Args parameter:

{
    "cookie_name": Name of the cookie,
    "domain": domain
    "expires": maximum cookie expiration date,
    "max_age": time in seconds for when a cookie will be deleted,
    "path": subdomain of the cookie validity (“/” indicates that it is valid for every domain),
    "values": [
        {
            "cache_key": key for cache on Edge, specific to this variant (cannot be repeated). This attribute is optional, and when defined, Edges will ensure that the cache is differentiated for this item, by incorporating this value into the object's cache-key,
            "value": cookie value of the first variant,
            "weight": probability for the draw
        },
        {
            "cache_key": key for cache on Edge, specific to this variant (cannot be repeated).
            "value": cookie value of the second variant,
            "weight": probability for the draw
        },
        {
            "cache_key": key for cache on Edge, specific to this variant (cannot be repeated).
            "value": cookie value of the third variant,
            "weight": probability for the draw

        },
        ...
    ]
}

The following is an example of a basic Function configuration, maintaining a 25 percent (0.25) probability for all variants, remembering that the sum must always be 1.

{
"cookie_name": "mydomain_cookie",
    "domain": ".mydomain.com",
    "expires": "Wed, 21 Oct 2025 07:28:00 GMT",
    "max_age": 600,
    "path": "/",
    "values": [
        {
            "cache_key": "custom_a",
            "value": "A",
            "weight": 0.25
        },
        {
            "cache_key": "custom_b",
            "value": "B",
            "weight": 0.25
        },
        {
            "cache_key": "custom_c",
            "value": "C",
            "weight": 0.25
        },
        {
            "cache_key": "custom_d",
            "value": "D",
            "weight": 0.25
        }
    ]
}

Edit the parameters and click Save to save. In the Rules Engine tab, use the Default Rule or create a new rule with a validation criterion (criteria) to activate your function; in the Behavior section, select Run Function and choose the Function you created (MyCookieTargeting), and then click Save to finish.

Now it is time to configure your application to deliver a different version of the landing page for each variation of cookies (if mydomain_cookie = custom_a, then deliver landing_page_a, for example). Follow, in your data analytics tools (Google Analytics, for example), the evolution of conversion rates, abandonment and recurrence, among other metrics.


Didn’t find what you were looking for? Open a support ticket.