You can manage user email registration and their subscription status using the Pushwoosh Web SDK by leveraging tags.
1. Registering an Email without Immediate Subscription:
By default, api.registerEmail()
subscribes the user. To register an email but have the user initially considered 'unsubscribed' (or pending confirmation), you can register the email and then immediately set the Unsubscribed Emails
tag to true
.
Pushwoosh.push(function(api) {
var userEmail = 'user@example.com';
api.registerEmail(userEmail)
.then(function() {
console.log('Email ' + userEmail + ' registered.');
// Set 'Unsubscribed Emails' tag to true to mark them as not wanting emails initially
// or to reflect their current preference from your system.
return api.setTags({ 'Unsubscribed Emails': true });
})
.then(function() {
console.log('Unsubscribed Emails tag set to true for ' + userEmail);
})
.catch(function(error) {
console.error('Error during email registration or setting tag:', error);
});
});
This approach registers the email address with Pushwoosh, but the Unsubscribed Emails: true
tag indicates they should not receive general email campaigns until this tag is changed.
2. Unsubscribing a User from Emails via SDK:
To unsubscribe a user from email communications (or to reflect an unsubscribe action performed in your application), set the Unsubscribed Emails
tag to true
:
Pushwoosh.push(function(api) {
api.setTags({ 'Unsubscribed Emails': true })
.then(function() {
console.log('User marked as unsubscribed from emails.');
})
.catch(function(error) {
console.error('Error setting Unsubscribed Emails tag:', error);
});
});
3. Subscribing (or Re-subscribing) a User to Emails via SDK:
To subscribe a user to emails, or to re-subscribe them if they were previously marked as unsubscribed using this tag method, set the Unsubscribed Emails
tag to false
:
Pushwoosh.push(function(api) {
api.setTags({ 'Unsubscribed Emails': false })
.then(function() {
console.log('User marked as subscribed to emails.');
})
.catch(function(error) {
console.error('Error setting Unsubscribed Emails tag:', error);
});
});
Key Points:
* The Unsubscribed Emails
tag is a default boolean tag provided by Pushwoosh. When set to true
, users associated with this tag can be excluded from email campaigns.
* This tag is also automatically set to true
if a user clicks a standard Pushwoosh unsubscribe link in an email they receive.
* By managing this tag through the SDK, you can programmatically control a user's email subscription status based on your application's internal logic or user preferences expressed within your platform.
Comments
0 comments
Please sign in to leave a comment.