Activities


List of examples:

Logging an activity for a contact




// Gets the current user
UserInfo user = MembershipContext.AuthenticatedUser;

// Gets the current customer
CustomerInfo customer = ECommerceContext.CurrentCustomer;

if ((user != null) && (customer != null))
{
    // Creates a new activity of the "Customer registration" type
    // Gets the context of the activity from AnalyticsContext.ActivityEnvironmentVariables (the current contact, URL, etc.)
    ActivityCustomerRegistration newActivity = new ActivityCustomerRegistration(customer, user, AnalyticsContext.ActivityEnvironmentVariables);

    // Logs the previously created Customer registration activity
    newActivity.Log();

    // Tip: You can find classes representing other types of activities in the CMS.WebAnalytics namespace (the class names have the 'Activity' prefix)
}


> Back to list of examples

Updating logged activities




// Gets the first contact whose last name is 'Smith'
ContactInfo contact = ContactInfoProvider.GetContacts()
                                    .WhereEquals("ContactLastName", "Smith")
                                    .FirstObject;

if (contact != null)
{
    // Gets all activities logged for the contact
    var updateActivities = ActivityInfoProvider.GetActivities().WhereEquals("ActivityActiveContactID", contact.ContactID);

    // Loops through individual activities
    foreach (ActivityInfo activity in updateActivities)
    {
        // Updates the activity title
        activity.ActivityTitle = activity.ActivityTitle.ToUpper();

        // Saves the modified activity to the database
        ActivityInfoProvider.SetActivityInfo(activity);
    }
}


> Back to list of examples

Deleting logged activities




// Gets the first contact whose last name is 'Smith'
ContactInfo contact = ContactInfoProvider.GetContacts()
                                    .WhereEquals("ContactLastName", "Smith")
                                    .FirstObject;

if (contact != null)
{
    // Gets all activities logged for the contact
    var activities = ActivityInfoProvider.GetActivities().WhereEquals("ActivityActiveContactID", contact.ContactID);

    // Loops through individual activities
    foreach (ActivityInfo activity in activities)
    {
        // Deletes the activity
        ActivityInfoProvider.DeleteActivityInfo(activity);
    }
}


> Back to list of examples