User location

Cloudflare makes user location details available to Cloudflare Workers. Uniform enables you to use these details to configure personalization instructions.

tip

For more information on this topic, see the Cloudflare documentation for incoming request properties.

User location details are associated with a specific visitor. In Uniform, quirks give you a way to associate any information you want with a visitor. Quirks can then be used as conditions in personalization instructions.

Before you can configure personalization instructions that use user location and device details, quirks must be defined. The Cloudflare connector handles this for you.

  1. In Uniform, open your project.

  2. Navigate to the Integrations tab.

cloudflare-integration
  1. Click Cloudflare.
add-to-project
  1. Click Add to project.
integration-added

About this step

You will see Cloudflare listed as an installed integration.

  1. Navigate to Personalization > Quirks.
quirks

About this step

You will see a list of quirks that were added by the Cloudflare integration.

In the previous section you added quirks to your Uniform project, but just because a quirk is defined doesn't mean the value will be populated for your visitors. Values for the quirks defined by the Cloudflare integration are available from Cloudflare, but you must add some logic to your Cloudflare Worker to select the values you want to use.

The EdgeWorker uses the Cloudflare proxy edge handler function to run the personalization instructions. When you call this function, you can specify the user location and device details you want to make available as quirks.

The following code sample demonstrates how to do this:

import { createEdgeContext } from '@uniformdev/context-edge' import { createCloudflareProxyEdgeHandler } from '@uniformdev/context-edge-cloudflare' import { ManifestV2 } from '@uniformdev/context' import manifest from "./context-manifest.json"; export async function handleRequest(request: Request): Promise<Response> { //@ts-ignore if (!ORIGIN_URL) { console.error('ORIGIN_URL environment is not defined') return new Response('Configuration Error', { status: 500, }) } const handler = createCloudflareProxyEdgeHandler() const context = createEdgeContext({ request, manifest: manifest as ManifestV2, }) const { response } = await handler({ context, request, quirks: ['city', 'country'], //@ts-ignore originUrl: new URL(`https://${ORIGIN_URL}`).origin, }) return response }

Now you can create signals using the quirks you added.

configure-signal