Archive > Interaction Studio > Dynamic Preference Center Available Functions

Core Functions

AddToMySubscriptions(deName)
Creates a DOM object in the My Subscriptions section and adds an event listener to the toggle switch. If the current deName passed into the function matches the first_position_de it will add a DOM object in the my-first-position div. The data extension name is passed in as deName and we use that to look up the title, description, image url, etc. in the PreferenceCenterData.DataExtensions object.
AddToFeaturedSubscriptions(deName)
Creates a DOM object in the Featured Subscriptions section and adds an event listener to the toggle switch. The data extension name is passed in as deName and we use that to look up the title, description, image url, etc. in the PreferenceCenterData.DataExtensions object.
AddToAllSubscriptions(deName)
Creates a DOM object in the All Subscriptions section and adds an event listener to the toggle switch. If the current deName passed into the function matches the first_position_de it will add a DOM object in the all-first-position div.
initializeSubscriptions()
This is the core function that populates the page on load. We use the sortByTitle() function to alphabatize the array of objects, de_title_pairs. Once sorted we loop through the array and call the AddToMySubscriptions(), AddToFeaturedSubscriptions(), and AddToAllSubscriptions() functions passing the DE name / publication list ID
toggleSubscription(deName)
Checks the user’s subscription status in the PreferenceCenterData.DataExtensions object then will call either subscribeToPublication() or unsubscribeFromPublication() function, depending on what’s appropriate. Then we update the user’s subscription status in the PreferenceCenterData.DataExtensions object. We also call toggleSubscriptionDisplay() and pass the deName, the user’s subscription status, and a human friendly label value. If you are subscribing to a publication that has a parent DE, we also use this function to call subscribeToPublication() on the parent data extension
toggleSubscriptionDisplay(deName, status, display)
Calls toggleMySubscriptionDisplay(), toggleFeaturedSubscriptionDisplay(), toggleAllSubscriptionDisplay() and passes deName, status, and display arguments for each.
toggleMySubscriptionDisplay(deName, status, display)
We use deName to determine which subscription we are editing. Then we check to see if the it
toggleFeaturedSubscriptionDisplay(deName, status, display)
Updates the “Subscribed/Unsubscribed” label under all three sections by calling toggleMySubscriptionDisplay(), toggleFeaturedSubscriptionDisplay(), and toggleAllSubscriptionDisplay()
toggleMySubscriptionDisplay(deName, status, display)
Checks if toggle switch exists under My Subscriptions and updates label based on the display argument passed.
toggleFeaturedSubscriptionDisplay(deName, status, display)
Checks if toggle switch exists under Featured Subscriptions and updates label based on the display argument passed.
toggleAllSubscriptionDisplay(deName, status, display)
Checks if toggle switch exists under All Subscriptions and updates label based on the display argument passed.
UpdateSubscriptionDisplay(deName, status, display,inputObj,labelObj)
This is responsible for updating the state of the checkbox which is what the display of the toggle switch is based on.
subscribeToPublication(deName)
Uses the data extension name passed in to create the URL for a new XMLHttpRequest which will subscribe the visitor to the data extension passed.
unsubscribeFromPublication(deName)
Uses the data extension name passed in to create the URL for a new XMLHttpRequest which will unsubscribe the visitor to the data extension passed.

Utility Functions

sortByTitle(array)
We have to use a bubble sort to alphabatize all the data extensions and publication lists because Internet Explorer doesn’t allow us to make use of the [.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) function.
equalHeight()
Loops through the heights of all subscription modules and sets the height based on the largest one so that toggle switches and photos line up nicely.
openUnsubscribeModal()
Opens the modal window prompting the user to confirm they would like to unsubscibe from all publications
closeModal()
Opens the modal. Kidding, it closes it.
unsubscribeAllNewsletters()
This also calls the closeModal() function. For this function we automatically loop through PreferenceCenterData.JourneyPublicationLists and PreferenceCenterData.DataExtensions
filterNewsletters()
Decides what newsletters to show/hide based on a dropdown selection. The dropdown categories are populated via the Available_Categories data extension.

SMS Sign-Up Functions

formInvalid()
Hides the form confirmation box, shows the form error box.
formValid()
Hides the form error box, shows the form confirmation box.
blurPhone()
When field for phone number looses focus, we validate that the phone number is at least 10 digits long and add a 1 to the begining (because the SMS opt-in needs a country code). We throw an error or success messages depending on if the number checks out.
handleSmsForm()
We double check the sanitized phone number is 11 digits and use that to build the URL for a pixel that we drop on the page that will run some AMP script to… TODO: Link to documentation on text to opt in

Table of Contents

Your email address will not be published. Required fields are marked *