Update campaign tracking after accepting cookie consent

Benjie Ward asked on June 7, 2021 11:13

I noticed that our campaign tracking stats were a lot lower than what was being shown in Google Analytics so did some investigating.

We have a cookie consent banner which after accepting, sets a cookie level and fires an event to GA in order to generate a page view.

I thought we could follow the same principle with kentico campaign tracking by firing off a request to /kentico.activities/kenticoactivitylogger/log similar to the javascript snippet which is included on every page. This seems to work in the fact it creates a record in the Activity table but the UTM parameters are not logged.

It appears that the code only seems to track the parameters if the various cookies (Campaign, Source, TrackedCampaigns etc) exist? (You can see this after refreshing the page as the cookies exist).

Is it possible to achieve this and use the campaign tracking functionality accurately? Do all of these cookies need creating at the point of setting the cookie level?

Recent Answers


Dmitry Bastron answered on June 7, 2021 16:55

Hi Benjie,

Unfortunately, campaign tracking currently works only by analyzing the URL of the page you are visiting. And to assign a campaign cookie Kentico requires a higher cookie level. In reality, it means, yes, the campaign tracking in CMS literally doesn't work. I have raised this issue with Kentico, but it might take a while until they implement this fix.

Practically, on one of the projects we have implemented the following customization:

  • on page load, if the URL contains UTM parameters, we save them in the session
  • if within the session on one of the subsequent page views the visitor agrees with the cookie level, we assign them the campaign from UTM parameters saved in the session (there is an API method for that in one of the marketing helpers or providers)
  • from that point campaign tracking actually kicks in
  • statistically, users tend to agree or deny cookies on the first page visit so your campaign shouldn't loose too much data tracked
0 votesVote for this answer Mark as a Correct answer

Benjie Ward answered on June 9, 2021 15:54

Thanks Dmitry, that was really helpful.

I've managed to get it working now by passing the URL parameters when making the request to set the cookie level and calling the CampaignService.SetCampaign method. This sets the various campaign cookies.

The subsequent call to the logger now includes the campaign values in the Activity table records so our statistics are accurate.

The problem with a lot of our campaigns is that traffic comes from social channels to a landing page where a user submits a form. This means that a lot of conversions are never tracked as a user bounces immediately after the form submits.

 [HttpPost]
    public ActionResult SetCookieLevel(int selectedValue)
    {
        CurrentCookieLevelProvider.SetCurrentCookieLevel(selectedValue);

        CookieHelper.SetValue(CookieLevelName, selectedValue.ToString(), DateTime.Now.AddYears(1));

        // if cookie level is visitor or above, set campaign parameters if they exist for accurate campaign tracking
        if (selectedValue >= CookieLevel.Visitor)
        {
            var campaignCode = Request["utm_campaign"];

            if (!string.IsNullOrEmpty(campaignCode))
            {
                var campaignSource = Request["utm_source"];
                var campaignContent = Request["utm_content"];

                // set campaign cookies
                CampaignService.SetCampaign(campaignCode, SiteContext.CurrentSiteName, campaignSource, campaignContent);
            }
        }

        return new HttpStatusCodeResult(HttpStatusCode.OK);
    }

To obtain the URL to replicate the call the activity logger in the subsequent request we use a global javascript variable which is set to the value of @Url.Action("Log", "KenticoActivityLogger")

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on June 10, 2021 18:46

Hi Benjie,

I think to cater for this scenario you'd need to slightly amend your UX: display more prominent cookie banner on page load and maybe just refresh the page on agreeing with cookies. By doing so, whoever lands on the website via campaign URL they'd accept cookies first, the page will reload keeping the URL parameters in and the tracking will be properly working for these users.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.