Sitecore XP Campaigns for Developers: One Simple Step to Make Your Client Happy
The Missed Opportunity
Sitecore XP Campaigns for Developers: One Simple Step to Make Your Client Happy
Photo by Joey Kyber on Unsplash
The Missed Opportunity
Some Sitecore XP projects barely use the platform’s marketing capabilities. Teams focus on templates, renderings, and integrations, while features like Campaigns stay untouched. The result is a technically complete solution that misses business potential.
For developers, this creates an opportunity. Small improvements in everyday components can unlock marketing value without requiring major architectural changes.
[embed]
Sitecore Campaigns Matter
Campaigns are one of the easiest ways to make user interactions measurable. They help track where traffic comes from, which channels perform best, and how specific initiatives contribute to business goals.
Instead of treating Campaigns as something only marketers use, developers can integrate them directly into functional components — making them part of the product experience.
Practical Example
The Idea
A standard “Share in Social Media” component usually generates links for platforms like LinkedIn, Facebook, or X. By attaching Sitecore Campaign parameters to those URLs, every shared link becomes trackable and a simple share action turns into measurable marketing data. The kind of improvement clients appreciate because it adds business visibility without adding complexity.
Demo: Building the Component
Consider a page with three buttons designed to generate and share links with a broad audience:

The objective is to ensure these links are fully functional by associating them with campaigns.
A straightforward approach is to create three corresponding campaigns:

And attach them directly to the links:
function shareTwitter() {
const shareUrl = window.location.href + "/?sc_camp={id_here}";
const shareTitle = "Designing Modern Web Experiences";
const url =
"https://twitter.com/intent/tweet?text=" +
encodeURIComponent(shareTitle) +
"&url=" +
encodeURIComponent(shareUrl);
popupCenter(url, "Share on Twitter", 600, 400);
}
The key challenge is maintaining synchronization of the Campaign items. This can be achieved either by using an item serializer to deploy campaigns from a defined root path:
/sitecore/system/Marketing Control Panel/Campaigns
Or by implementing a coded solution that programmatically ensures the required campaigns exist:
// https://github.com/srgarch/share-buttons-campaign/blob/66b9559affd66b56c9071249a2039e1a4bc6e189/Controllers/SocialShareController.cs#L70-L91
private ICampaignActivityDefinition EnsureCampaign(Guid campaignActivityId, string campaignName)
{
// Try to get the campaign activity definition with the specified ID and culture.
var campaignActivityDefinition = _definitionManager.Get(campaignActivityId, CultureInfo.GetCultureInfo("en"));
if (campaignActivityDefinition != null)
{
// Campaign with the same ID and culture already exists, so we can update it or return.
return campaignActivityDefinition;
}
// Create a new campaign activity definition with the specified ID, name, and culture.
campaignActivityDefinition = new CampaignActivityDefinition(campaignActivityId, $"{campaignName}-{campaignActivityId}", CultureInfo.GetCultureInfo("en"), campaignName, DateTime.UtcNow, "sitecore\\admin");
using (new SecurityDisabler())
{
_definitionManager.SaveAsync(campaignActivityDefinition).GetAwaiter().GetResult();
_definitionManager.ActivateAsync(campaignActivityId).GetAwaiter().GetResult();
}
return campaignActivityDefinition;
}
the _definitionManager comes via dependency injector:
// https://github.com/srgarch/share-buttons-campaign/blob/66b9559affd66b56c9071249a2039e1a4bc6e189/Controllers/SocialShareController.cs#L14-L23
ServiceLocator.ServiceProvider.GetDefinitionManagerFactory().GetDefinitionManager<ICampaignActivityDefinition>()
A sample controller component can then be used within a rendering:
// https://github.com/srgarch/share-buttons-campaign/blob/66b9559affd66b56c9071249a2039e1a4bc6e189/Controllers/SocialShareController.cs#L25-L38
public ActionResult FacebookButton()
{
// Predefined campaign name.
const string campaignName = "Facebook Share Campaign";
// Some predefined guid for the campaign activity.
var campaignActivityId = new Guid("68c51183-971d-485d-80c7-30b323da8733");
var facebookCampaign = EnsureCampaign(campaignActivityId, campaignName);
var shareUrl = $"{WebUtil.GetServerUrl()}/?sc_camp={facebookCampaign.Id:N}";
ViewBag.ShareUrl = shareUrl;
return View();
}
Presentation details configured accordingly:

Now when a share button is clicked, a link is generated in the following format:
https://www.linkedin.com/feed/?shareActive=true
&url=https%3A%2F%2Fsc1041.sc%2F%3Fsc_camp%3D5d41f1b476dd4f3bd10c0c39506355eb
&shareUrl=https%3A%2F%2Fsc1041.sc%2F%3Fsc_camp%3D5d41f1b476dd4f3bd10c0c39506355eb
The complete code and package with the items is available in the referenced GitHub repository:
메타데이터
- post_id
- ede99bf4019e
- slug
- sitecore-xp-campaigns-for-developers-one-simple-step-to-make-your-client-happy-ede99bf4019e
- url
- https://medium.com/@serg-at/sitecore-xp-campaigns-for-developers-one-simple-step-to-make-your-client-happy-ede99bf4019e
- canonical_url
- https://medium.com/@serg-at/sitecore-xp-campaigns-for-developers-one-simple-step-to-make-your-client-happy-ede99bf4019e
- author_url
- https://medium.com/@serg-at
- status
- ok
- fetched_at
- 2026-06-15 22:55:51