Skip to main content
Full Circle Insights

Building a Campaign Attribution Plugin Part 1 – Defining the Classes

Note: This document refers to campaign attribution models for both the Full Circle Campaign Attribution and Full Circle Response Management applications. Models designed to work in one application, won't work in the other. Fortunately, the two applications have very similar campaign attribution systems. This allows you to build custom attribution models that require few modifications in order to work in both applications. More on these modifications further down in the document.

Implementing ICampaignAttributionType and ICampaignAttributionConfiguration

In this example we'll create a class named SimpleOpConfiguration containing two inner classes that implement ICampaignAttributionType and ICampaignAttributionConfiguration.

Response Management Compatibility Modifications: This model is designed to be run by the Full Circle Campaign Attribution application, that's why it uses the 'FCCI' namespace prefix. If you wanted to modify this model to work in Response Management, you'd use 'FCRM' as the prefix instead.

global with sharing class SimpleOpConfiguration {
     
    private static String CONFIG_TYPE_CLASS_NAME = 'SimpleOpConfiguration.OpConfigurationType';
    private static String CONFIG_CLASS_NAME = 'SimpleOpConfiguration.OpConfiguration';
    private static String CONFIG_TYPE_DESCRIPTION = 'Model type description'; 
    private static String MANUFACTURER = 'Your company name';
    private static String COPYRIGHT = 'Copyright © 2015, Your company';
    
    global class OpConfigurationType implements FCCI.FCI_CampaignInfluenceAPI.ICampaignAttributionType
    {              
        // Implementation shown below
    }
   
    global class OpConfiguration implements FCCI.FCI_CampaignInfluenceAPI.ICampaignAttributionConfiguration, FCCI.FCI_CampaignInfluenceAPI.ICampaignAttributionWeightingInfo
    {
        // Implementation shown below               
    }
}

Implementing ICampaignAttributionType

Implementing this interface is made easy with our system's APIs. Your model can implement methods GetConfiguredInstances, CreateConfiguredInstance, and DeleteConfiguredInstance the same way as in the example below.

global class OpConfigurationType implements FCCI.FCI_CampaignInfluenceAPI.ICampaignAttributionType
{              
    global String GetUniqueName() { return CONFIG_TYPE_CLASS_NAME;} // Must always return the configuration type's class name
    global String GetDescription() { return CONFIG_TYPE_DESCRIPTION;}
    global String GetManufacturer() { return MANUFACTURER;}
    global String GetCopyright() { return COPYRIGHT;}
          
    // Return a list of all configured instances for this configuration type      
    global List<FCCI.FCI_CampaignInfluenceAPI.ICampaignAttributionConfiguration> GetConfiguredInstances()
    {
        return FCCI.FCI_InfluenceConfigurationPluginAPI.GetConfiguredInstances(CONFIG_TYPE_CLASS_NAME);
    }    
         
     // Create a new configured instance of a model with the specified name and description
    global void CreateConfiguredInstance(String name, String description)
    {        
        FCCI.FCI_InfluenceConfigurationPluginAPI.CreateConfiguredInstance(name, description, CONFIG_TYPE_CLASS_NAME, CONFIG_CLASS_NAME);
    }
         
    // Delete a configured instance with the specified name
    global void DeleteConfiguredInstance(String name)
    {
        // Delete any custom settings records used to support the model or any other necessary database changes
        // API call deletes the configured instance from the system
        FCCI.FCI_InfluenceConfigurationPluginAPI.DeleteConfiguredInstanceFromSystem(name) ;
    }
} 

Implementing ICampaignAttributionConfiguration and ICampaignAttributionWeightingInfo

The class below implements both ICampaignAttributionConfiguration and ICampaignAttributionWeightingInfo. When the system instantiates this class, it will invoke its OpportunityDetermineAttribution method. In there, you would calculate attribution and record your calculations by populating the OpportunityRevenue collections passed as arguments.

Response Management Compatibility Modifications: Besides changing the namespace prefix to 'FCRM', you'll need to replace FCCI__FCI_Influence_Detail__c with FCRM__FCR_Influence_Detail__c.

global class OpConfiguration implements FCCI.FCI_CampaignInfluenceAPI.ICampaignAttributionConfiguration, FCCI.FCI_CampaignInfluenceAPI.ICampaignAttributionWeightingInfo
{
    private String name;
    global void SetUniqueName(String uniquename) { name = uniquename; }
    global String GetUniqueName() { return name;}          
    private String customdescription;
    public void SetDescription(String description) { customdescription = description; }
    public String GetDescription() { return customdescription; }       
    global String GetConfigurationTypeName() { return CONFIG_TYPE_CLASS_NAME; } // Must always return the configuration type's class name       
    global String GetManufacturer() { return MANUFACTURER;}
    global String GetCopyright() { return COPYRIGHT;}
    public PageReference GetConfigurationPage() { return new PageReference('/'); }   
    public FCCI.FCI_CampaignInfluenceAPI.WeightingInfo m_WeightingInfo;
    public FCCI.FCI_CampaignInfluenceAPI.WeightingInfo GetWeightingInfo() { return m_WeightingInfo; }
    public Boolean GetSupportsAccountInfluence() { return false; }
    public Boolean GetSupportsOpInfluence()  { return true; }
    global Set<String> GetCMFieldsToQuery() { return new Set<String>{}; }
    global Set<String> GetOpportunityFieldsToQuery() { return new Set<String>{}; }
    public Set<String> GetAccountFieldsToQuery() { return new Set<String>{}; }
     
    public string AccountDetermineAttribution(
        Map<ID, Account> accounts,
        Map<ID, Map<ID, Opportunity>> opportunities,
        Map<ID, List<FCCI.FCI_CampaignInfluenceAPI.OpportunityRevenue>> OpenOpportunityRevenue,
        Map<ID, List<FCCI.FCI_CampaignInfluenceAPI.OpportunityRevenue>> ClosedOpportunityRevenue,
        Map<ID, List<FCCI.FCI_CampaignInfluenceAPI.OpportunityRevenue>> LostOpportunityRevenue,
        String state)
    {
        return null;
    }
           
    public string OpportunityDetermineAttribution(
        Map<ID, Opportunity> opportunities,
        Map<ID, Map<ID,CampaignMember>> CreatingContactResponses,
        Map<ID, Map<ID, CampaignMember>> PrimaryContactResponses,
        Map<ID, Map<ID, CampaignMember>> OtherContactResponses,
        Map<ID, List<FCCI.FCI_CampaignInfluenceAPI.OpportunityRevenue>> OpenOpportunityRevenue,
        Map<ID, List<FCCI.FCI_CampaignInfluenceAPI.OpportunityRevenue>> ClosedOpportunityRevenue,
        Map<ID, List<FCCI.FCI_CampaignInfluenceAPI.OpportunityRevenue>> LostOpportunityRevenue,
        String state)
    {  
        return null;
    }
         
    public void DetailObjectUpsert(String influencetype, List<FCCI__FCI_Influence_Detail__c> influenceobjects, Map<ID, CampaignMember> allcms, Map<ID, Opportunity> allops ) { return; }
       
    public String Start() { return null; }
    public void Finish(String state) {}  
                 
}


All that remains is to implement the attribution functionality inside of the OpportunityDetermineAttribution method. How this is done will be covered later in this document. 

Implementing the model configuration page

The ICampaignAttributionConfiguraiton.GetConfigurationPage method can return a PageReference object to the configuration page for your attribution model. Before returning the configuration page, be sure to set the two parameters that define the names, i.e. class names, of the configuration and its configuration type.

A simple implementation of our model's configuration page controller is as follows:

public with sharing class SimpleOpModelConfigPageController {
     
    public String configName {get;set;}
    public String configTypeName {get;set;}
    public String configDesc {get;set;}
    public String newConfigDesc {get;set;}       
    public SimpleOpConfigurationSetting__c config {get;set;}
     
    public SimpleOpModelConfigPageController()
    {
        configName = ApexPages.currentPage().getParameters().get('config_name');
        configTypeName = ApexPages.currentPage().getParameters().get('config_type_name');
        configDesc = FCCI.FCI_InfluenceConfigurationPluginAPI.GetInfluenceConfigDescription(configName);   
        newConfigDesc = configDesc;
        if (configName!=null) config = SimpleOpConfigurationSetting__c.getInstance(configName);     
    }
     
    // Saves configuration's custom setting record and sets a new description if modified
    public void Save()
    {           
        if (config!=null) upsert config; 
        if (configDesc != newConfigDesc) FCCI.FCI_InfluenceConfigurationPluginAPI.SetInfluenceConfigDescription(configName, newConfigDesc);      
    }        
     
    // Returns a PageReference of the URL defined in the page's returl URL parameter
    public PageReference Cancel()
    {
        return FCCI.FCI_InfluenceConfigurationPluginAPI.GetReturnURL();
    }       
 
}
  • Was this article helpful?