Capture when a user resubscribes to a newsletter

Tracey Penberthy asked on March 15, 2017 11:32

Hi

How do I listen out for when a user resubscribes to a newsletter?

So they have previously subscribed and then unsubscribed to a newsletter and are displayed in the newsletter recipients table as Unsubscribed.

Then they subscribe again. This event isn't captured in: SubscriberNewsletterInfo.TYPEINFO.Events.Insert.Before

I have tried the following but it is not captured in any of these either:

SubscriberInfo.TYPEINFO.Events.Insert.Before += SubscriberInfo_Insert_Before;
SubscriberInfo.TYPEINFO.Events.Update.Before += SubscriberInfo_Update_Before;
SubscriberNewsletterInfo.TYPEINFO.Events.Update.Before += Newsletter_Update_Before;

Many Thanks

Recent Answers


Rui Wang answered on March 16, 2017 16:20

Here is a thought, based on how a subscriber is been add to a newsletter (https://docs.kentico.com/api9/on-line-marketing/email-marketing#Emailmarketing-Addingasubscribertoanemailcampaign) it's using a core service, which I think the SubscriberInfo doesn't get updated at all.

So maybe you can do something like delete the subscriber (https://docs.kentico.com/api9/on-line-marketing/email-marketing#Emailmarketing-Deletingasubscriber) during the NewsletterEvents.SubscriberUnsubscribes.Execute event, so when they resubscribe, the SubscriberInfo will be triggered.

This may be a problem if you have multiple subscription. Another possibility maybe tie it to the online marketing activity (https://docs.kentico.com/k10/custom-development/handling-global-events/reference-global-system-events#Reference-Globalsystemevents-ActivityEvents) but you'll need to test it to see if the resubscribe do log an as an activity or not.

0 votesVote for this answer Mark as a Correct answer

Pavel Jiřík answered on March 16, 2017 16:20 (last edited on March 16, 2017 16:27)

Hi Tracey,

I am not sure what is your current version of Kentico, but if it is v9 or v10, I would try to hook it to the following event:

UnsubscriptionInfo.TYPEINFO.Events.Update.Before

When someone unsubscribes from a newsletter, relevant record is created in the Newsletter_Unsubscription table and Kentico doesn't send them any emails. If someone subscribes to a newsletter again, the record is deleted from that table.

I hope it helps!

0 votesVote for this answer Mark as a Correct answer

Tracey Penberthy answered on March 17, 2017 17:24

Thank you Rui and Pavel for your responses they were really helpful

Here's what I did

In my NewsletterEvents.SubscriberUnsubscribes.Execute event I removed the subscriber from the newsletter's recipients and that meant that when they 'resubscribed' the SubscriberNewsletterInfo.TYPEINFO.Events.Insert.Before event got fired.

private void Subscriber_Unsubscribes(object sender, UnsubscriptionEventArgs e)
     {
        // check the newsletter id
        if (e.Newsletter.NewsletterID == 3)
        { 
            // delete newsletter subscription so that if they resubscribe that event gets fired
            // Get the subscriber 
            SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberByEmail(e.Email, SiteContext.CurrentSiteID);
            if (subscriber != null)
            {
                // Prepare an instance of the Kentico email feed subscription service
                ISubscriptionService subscriptionService = CMS.Core.Service<ISubscriptionService>.Entry();
                // Remove the subscriber from the newsletter's recipients
                subscriptionService.RemoveSubscription(subscriber.SubscriberID, e.Newsletter.NewsletterID, sendConfirmationEmail: false);
            }
        }
    }
0 votesVote for this answer Mark as a Correct answer

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