---
title: "Create a custom goal model"
slug: "create-a-custom-goal-model"
abstract: "How to create a custom goal model including how to create a goal definition item, how to create a custom goal model and how to use the custom goal model."
---
# Create a custom goal model

This topic describes how to create a custom goal named `NewsletterSignup` that inherits `Goal`, and assumes the following requirements:

- The `NewsletterSignup` goal will be used with a single goal definition item
- The `NewsletterSignup` goal has an optional `CampaignId` property

<details>
<summary><h2>Create a goal definition item</h2></summary>

1. Open the Sitecore Content Editor.
2. Go to /sitecore/system/Marketing Control Panel/Goals.
3. Right-click on the Goals item and select **Insert** > **Goal**. 
4. Enter an item name when prompted - for example, Newsletter Signup.
5. Select the newly created definition, then click the **Review** tab, then select **Deploy**. This publishes the definition to the web database and deploys it to the Reference Data Service database.

</details>

<details>
<summary><h2>Create a custom goal model</h2></summary>

Create a new class named `NewsletterSignup` that inherits the `Goal` class. This class has a fixed definition ID, which means it cannot be instantiated with any other definition ID. The class has an optional property named `CampaignId` which can be set if the contact signed up for a newsletter as part of a campaign.

```csharp
using Sitecore.XConnect;
using System;

namespace Documentation
{
    public class NewsletterSignup : Goal
    {
        public static Guid NewsletterSignupEventDefinitionId { get; } = new Guid("3a7e9e7e-a2ac-4ac2-8f8e-26a9c8644b23");
        public Guid CampaignId { get; set; }

        public NewsletterSignup(DateTime timestamp)
            : base(NewsletterSignupEventDefinitionId, timestamp)
        {
        }
    }
}

```

</details>

<details>
<summary><h2>Define a custom goal in the model</h2></summary>

Define the new goal in your collection model using the `.DefineEventType` method. In the following example, the goal model has been added to a model named `SampleModel`. If you are using the model in a Sitecore context, the model class must be [registered in the client configuration file](https://doc.sitecore.com/xp/en/developers/93/sitecore-experience-platform/create-a-custom-model.html "Create a custom model").

```csharp
using Sitecore.XConnect;
using Sitecore.XConnect.Schema;

namespace Documentation
{
    public class SampleModel
    {
        public static XdbModel Model { get; } = SampleModel.BuildModel();

        private static XdbModel BuildModel()
        {
            XdbModelBuilder modelBuilder = new XdbModelBuilder("SampleModel", new XdbModelVersion(0, 1));

            modelBuilder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
            modelBuilder.DefineEventType<NewsletterSignup>(false);

            return modelBuilder.BuildModel();
        }
    }
}

```

> [!warning]
> If you do not register your goal model, you cannot use it. You will get errors such as ‘The type of this instance does not correspond to any type in the schema’.

</details>

<details>
<summary><h2>Use the custom goal model</h2></summary>

Use the xConnect Client API to [add your goal to an interaction](https://doc.sitecore.com/xp/en/developers/93/sitecore-experience-platform/add-interaction-events.html "Add interaction events"). The following example demonstrates how to instantiate the custom goal:

```

var newsletterGoal = new NewsletterSignup(DateTime.UtcNow);

var campaign = Guid.Parse("e7f411bc-09e6-4872-8961-1cf078e317e9"); // Sample campaign ID
newsletterGoal.CampaignId = campaign;

```

</details>

<details>
<summary><h2>Use a custom goal model with the tracker</h2></summary>

To use a custom goal model within the tracker, you must create an event conversion pipeline processor. For more information, see [Triggering custom events](https://doc.sitecore.com/xp/en/developers/93/sitecore-experience-platform/triggering-custom-events.html "Triggering custom events").

</details>