Click or drag to resize
ICampaignServiceSetCampaign Method
If CampaignInfo with given campaignCode exists and is running, sets both campaignCode and source to their properties (CampaignCode or CampaignSourceName respectively). Additionally performs logging of campaign hit to the analytics.

Namespace: CMS.WebAnalytics
Assembly: CMS.WebAnalytics (in CMS.WebAnalytics.dll) Version: 9.0.0
Syntax
C#
void SetCampaign(
	string campaignCode,
	string siteName,
	string source = null
)

Parameters

campaignCode
Type: SystemString
Campaign UTM code
siteName
Type: SystemString
Name of the site the campaign belongs to
source (Optional)
Type: SystemString
Name of the campaign source
Remarks
If Javascript logging is enabled, hit logging will be performed asynchronously on the following request.
Examples
Following example shows how to use the SetCampaign(String, String, String) method.
var campaignService = new CampaignService();

...

// stores myCampaign to the <see cref="P:CMS.WebAnalytics.ICampaignService.CampaignCode" /> and mySource to the <see cref="P:CMS.WebAnalytics.ICampaignService.CampaignSourceName" />
campaignService.SetCampaign("myCampaign", "mySite", "mySource");

...

// for all following requests of the same visitor
// returns myCampaign
public string GetCampaignCode() 
{
    return campaignService.CampaignCode;
}


// returns mySource
public string GetSourceName() 
{
    return campaignService.CampaignSourceName;
}
See Also