Retrieve marketing taxonomy data for use in aggregation processing


How to programmatically retrieve marketing taxonomy data for use in aggregation processing.

You can use the Marketing Operations API to query marketing definitions, such as campaigns, goals, or outcomes, but you can also retrieve data from marketing taxonomies to use in aggregation processing, or for creating custom reports based on classifications of marketing definitions.

Campaigns and other marketing definitions can be classified with specific taxons, represented by a TaxonUri class that provides information about the specific place where the taxon is located inside the taxonomy.

You can query a campaign by its ID so that you can use its taxonomic classification to aggregate data from the processing server, gaining a high level view of new aspects of customer engagement. You use the TaxonUri key to aggregate the data on in this case.

To retrieve a single marketing taxonomy classification asset to use in aggregation processing:

  1. Add the following project references:

    • Sitecore.Kernel.dll

    • Sitecore.Marketing.dll

    • Sitecore.Marketing.Taxonomy.dll

  2. Add the following namespaces:

    • using Sitecore.Marketing.Definitions;

    • using Sitecore.Marketing.Definitions.Campaigns;

    • using Sitecore.Marketing.Taxonomy.Model;

For example, the following code sample enables you to retrieve the marketing asset taxon associated with the campaign ID of IVisitAggregationContext. Additionally, you can retrieve the TaxonUri of the parent node of the asset taxon to use if you want to aggregate over more general classifications instead.

var campaignDefinitionManager = DefinitionManagerFactory.Default.GetDefinitionManager<ICampaignActivityDefinition>();
var campaign = campaignDefinitionManager.Get(campaignId, CultureInfo.InvariantCulture);
// if (campaign == null || campaign.MarketingAssetUri == null) {} //  don't forget to check for null: campaign is null if the definition has not been deployed to the processing server, and the marketing asset uri is null if the campaign hasn't been classified.
var assetTaxonUri = campaign.MarketingAssetUri; 
var parentTaxonSegments = assetTaxonUri.Segments.Take(assetTaxonUri.Segments.Count() - 1);
var assetParentTaxonUri = new TaxonUri(parentTaxonSegments, assetTaxonUri.Culture);