China CDN Deployment Extension

The China CDN Deployment extension is a Pre Loader extension that runs before the Data Layer Processing. This extension determines a user’s location (inside or outside China), which allows web site content to be sent to the user from the appropriate CDN.

You can use this extension when you cannot modify the source code for a web site to add logic to determine the user’s location.


  • To create a draft of a China CDN Deployment extension, you need the Manage JavaScript Code Extensions account-level permission.

How it works

The China CDN Deployment extension consists of a code editor pre-filled with JavaScript code that is executed during the pre-loader scope. This code contains logic to do the following:

  • Determine the users location based on the users browser language, timezone, and IP address.
  • Set a cookie with the best CDN for that user.

All subsequent site visits read the cookie value, if it is present, and fetch all utag content from the most specified CDN. Setting the cookie in the pre-loader scope means that the initial page request is served from the appropriate CDN.

Configuring the extension

When you add the China CDN Deployment extension to a profile, an Ace Editor window is displayed, which contains the default code for the extension. You can configure the domainMap, languageMap, and gmtMap variables for the extension. In addition, you can specify the matchLogic to determine a user’s location.

Setting up domain mapping

If you have multiple domains associated with a profile, you use the domainMap variable to direct all domain traffic to a specific CDN.

domainMap = {
    '': 'cn'

Adjusting language mapping

The languageMap variable lists the most common Chinese language variations and maps them to a single CDN.

languageMap = {
    'zh': 'cn',
    'zh-HK': 'cn',
    'zh-CN': 'cn',
    'zh-TW': 'cn'

Adjusting timezone mapping

The gmtMap variable specifies the Chinese time zone.

gmtMap = {
    '-480': 'cn'

Adjusting the match logic

The default matchLogic variable for all defined variables requires them to all be true. Set it to or if only some of the variables need to be true.

matchLogic = 'and'; // 'or'

Turning IP location detection on or off

  • If locationTest is true, fetch the users IP address and return a location.
  • If locationTestForce is true, runs the location logic every time regardless of the cookie value or other match logic results.
  • Both variables default to true to provide optimal location detection for every user session.
 var locationTest = true; // Use location test logic
 var locationTestForce = true; // Use location test in all scenarios

The retestTime variable is specified in milliseconds and specifies when the retest is done to determine the user’s location. The default is one day.

var retestTime = 86400000; // 1 day

Was this page helpful?

This page was last updated: January 7, 2023