Target by campaign and referrer
Show an offer to visitors who came from one ad, email or site, by passing the page link's UTM values and the referrer as attributes.
Give visitors from your Black Friday ads the Black Friday offer, and everyone else your usual paywall. Your site reads where the visitor came from and passes it to the SDK as attributes. The SDK does not read the page link itself, and like every attribute, these values stay in the browser.
Audiences need the Pro plan or above.
Read the campaign from the page link and the referring site, keep them for the visit, and pass them to the SDK:
const link = new URLSearchParams(location.search);
const stored = sessionStorage.getItem('campaign');
const saved = stored ? JSON.parse(stored) : {};
// The referring site counts on the first page of the visit only; later pages are referred by your own site.
const from = !stored && document.referrer ? new URL(document.referrer).hostname : null;
const campaign = {
utm_source: link.get('utm_source') ?? saved.utm_source ?? null,
utm_medium: link.get('utm_medium') ?? saved.utm_medium ?? null,
utm_campaign: link.get('utm_campaign') ?? saved.utm_campaign ?? null,
referrer: stored ? saved.referrer ?? null : from !== location.hostname ? from : null,
};
sessionStorage.setItem('campaign', JSON.stringify(campaign));
UIKit.configure({ apiKey: 'pk_...', attributes: campaign });sessionStorage keeps the values when the visitor moves to another page of your site, where the link no longer has them. A value that is null is simply not set, so is set and is not set work.
Configure the placement, tab Audience, Add audience. Name it Black Friday ads. Condition: Campaign name is black_friday. Shows: your offer screen.
The other choices under Campaign (your site passes it) are Campaign source (utm_source), Campaign medium (utm_medium) and Referring site (referrer). They are saved as the attributes utm_campaign, utm_source, utm_medium and referrer, the same as Attribute from your site with those names.
Check it before you save: under the audiences, Test a visitor has a box for each field your audiences use. Type black_friday in Campaign name and it says which audience matches and what that visitor sees. Leave it empty to see what everyone else sees.
Save, then open your site with ?utm_campaign=black_friday on the link.
Comparisons ignore case, so Black_Friday matches black_friday. Use contains to catch a family of campaigns, such as every name with summer in it.
Apps have no page link. In an app, pass the campaign your attribution tool reports as the same attribute names, and the same audiences work.