Custom Activity not logging in Kentico 10

Matt Fox asked on April 24, 2017 16:49

I have a custom activity that I'm trying to log, but no activity shows up. The contact record is created (in a previous step) and is working fine.

public void LogVideoViewActivityForContact(string activityType, string videoName, ContactInfo contact)
{
    var service = Service.Entry<IActivityLogService>();

    var activityInitializer = new VideoViewActivityInitializer(videoName).WithContactId(contact.ContactID);

    if (activityInitializer != null)
    {
        service.Log(activityInitializer, CMSHttpContext.Current.Request);
    }     
}

I'm not getting any errors, but no activities associated with the contact either.

Recent Answers


Brenden Kehren answered on April 24, 2017 18:53

Based on the limited code, I'd say your activityInitializer object is null. Have you tried debugging it or placing an else to write an event log with maybe the video name and the contact info?

0 votesVote for this answer Mark as a Correct answer

Matt Fox answered on April 24, 2017 19:30

The activity is not null, and the input (videoName) is correct. The logging just seems to go into a black hole.

FWIW, I did double-check that Activity logging was enabled.

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on April 24, 2017 23:13

.Log(activityInitializer, CMSHttpContext.Current.Request);

Is this a custom method? I don't believe the default .log() for activity accepts any parameters. If it is, I would look into that method and see what it is doing.

0 votesVote for this answer Mark as a Correct answer

Matt Fox answered on April 24, 2017 23:15

This is Kentico 10, and they have updated the API. My code is basically a lift of the example: https://docs.kentico.com/api10/on-line-marketing/activities, with a custom activity.

0 votesVote for this answer Mark as a Correct answer

Matt Fox answered on April 25, 2017 18:04

Update:

If I create an Activity manually and don't use the Logger, it seems to work. Can anyone validate that this won't create other issues down the road? FYI, the activity is the correct one and is associated with the correct contact.

var activity = new ActivityInfo();
activity.ActivitySiteID = currentSite.SiteID;
activity.ActivityContactID = contact.ContactID;
activity.ActivityType = activityInitializer.ActivityType;

ActivityInfoProvider.SetActivityInfo(activity);
0 votesVote for this answer Mark as a Correct answer

Luke Ballantine2 answered on June 4, 2017 01:46

Hi Matt - I too am having these issues. Did you ever get to the bottom of it? Just not seeing the Custom Activity being logged through the service logger.

0 votesVote for this answer Mark as a Correct answer

Boris Pocatko answered on June 27, 2017 05:23

I'm not sure if this is a bug (try getting in touch with support@kentico.com) but this workaround works:

protected void Custom_Code_Click(object sender, EventArgs e)
{
    // Logs activity for current contact
    if (ContactManagementContext.GetCurrentContact() != null)
    {
        // Obtains the activity logging service
        var service = Service.Entry<IActivityLogService>();

        // Prepares an initializer for logging the activity
        var activityInitializer = new MyActivityInitializer("current contact");

        // Logs the activity
        service.Log(activityInitializer, CMSHttpContext.Current.Request);
    }



    // Logging the activity for a different contact

    ContactInfo contact = ContactInfoProvider.GetContacts().Where("ContactEmail = 'bp@example.com'").TopN(1);

    if (contact != null)
    {
        // set contact cookie to the logged contact
        HttpCookie currentContactCookie = CookieHelper.GetExistingCookie("CurrentContact");

        string tempCurrentContactCookieValue = currentContactCookie.Value;

        CookieHelper.SetValue(currentContactCookie.Name, contact.ContactGUID.ToString(), currentContactCookie.Expires);

        // Obtains the activity logging service
        var service = Service.Entry<IActivityLogService>();

        // Prepares an initializer for logging the activity
        var activityInitializer = new MyActivityInitializer("different conntact");

        // Logs the activity
        service.Log(activityInitializer, CMSHttpContext.Current.Request);

        // restore cookie value
        CookieHelper.SetValue(currentContactCookie.Name, tempCurrentContactCookieValue, currentContactCookie.Expires);
    }
}
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.