• Features
  • API Docs
  • Help Center
  • Log in
  • Sign Up
  • Features
  • API Docs
  • Help Center
  • Log in
  • Sign Up

How to create and update contact via JS

59 views January 11, 2022 0

You can easily update already existing contact’s data and add a new one using JavaScript.

To update the contact’s data in the Contact List or to create a new one, you need to properly identify your user and fire an event on your web page.

IMPORTANT Include those snippets on every page in your app, immediately before the closing </body> tag to initialize JS API and identify your user.

Connecting the library:

<script type="text/javascript" src="//js.smartsender.io/js/v1/JS_SCRIPT_ID.js>

</script>

Contact identificator:

<script type="text/javascript">

    var contact = new_smartSenderContact('{{identifier}}');

</script>

Step-by-step instructions:

  1. Install JS API 
  2. Create and generate a JS code snippet.
  3. Call JS API methods to manage your user data:
  • To add a new user to the Contact List see example: 
    <script type="text/javascript">
    
        contact.Add({    
    
            name: "John Doe",   
    
            email: "user@example.com",
    
            phoneNumber: "+15555555",
    
            userId: "myUserId",
    
            active: true,
    
            emailSubscribe: true,
    
            smsSubscribe: true,
    
            firstName: "John",
    
            lastName: "Doe",
    
            contactBirthday: "1990-01-01",
    
            contactLanguage: "en",
    
            contactGender: "female",
    
            contactTimezone: "Europe/Tallinn",
    
            contactScore: 100,
    
            avatarLink: "img.smartsender.io/g/06c38b4568.jpg",
    
            facebookLink: "https://www.facebook.com/smartsender.io",
    
            instagramLink: "instagram.com/smartsender",
    
            linkedInLink: "linkedin.com/company/smartsender"
    
            twitterLink: "twitter.com/smart_sender",
    
            tiktokLink: "tiktok.com/smartsender",
    
            sourceId: "Source_ID_from_SmartSender",
    
            customerSourceId: "Customer_Source_ID_From_Your_Platform",
    
            cac: {
    
                value:      2.05,
    
                currency:   "USD",
    
            },
    
            variables: [
    
                {name: "stringVariableName", value: "newVariableValue"},
    
                {name: "dateVariableName", value: "2020-10-20"}
    
            ],
    
        });
    
    </script>

     

    Parameters
    contact 'required' An array of contact information.
    name 'optional' The optional display name to use for the recipient
    email 'optional' Contact’s email address.
    phoneNumber 'optional' IMPORTANT: should be valid E.164 phone number format.
    userId 'optional' Contact’s unique user ID from your platform to enable management of the contact in the list based on it.
    active 'optional' You can set if the contact is enable  contact list or not. The default value is false (disable).
    true 'optional' Contact enabled. Contact can receive communication from enabled channels.
    false 'default' Contact disabled. No communications will be send to this contact.
    emailSubscribe 'optional' You can set if the contact is subscribed to receiving emails or not. The default value is false (unsubscribed).
    true 'optional' Subscribe contact to emails
    false 'default' Unsubscribe contact from emails
    smsSubscribe 'optional' You can set if the contact is subscribed to receiving SMS or not. The default value is false (unsubscribed).
    true 'optional' Subscribe contact to SMS
    false 'default' Unsubscribe contact from SMS
    firstName 'optional' Contact’s first name
    lastName 'optional' Contact’s last name
    contactBirthday 'optional' Contact’s birth date in ENUM_DATE (YYYY-MM-DD) format
    contactLanguage 'optional' Contact’s locale in ISO 639-1 format
    contactGender 'optional' Contact’s gender in ISO/IEC 5218 format
    0 Not known
    1 Male
    2 Female
    9 Not applicable
    contactTimezone 'optional' Contact’s timezone in ISO 8601 format
    contactScore 'optional' Contact Score
    avatarLink 'optional' Link to contact’s avatar image.
    facebookLink 'optional' Link to contact’s Facebook profile.
    instagramLink 'optional' Link to contact’s Instagram profile.
    linkedInLink 'optional' Link to contact’s LinkedIn profile.
    twitterLink 'optional' Link to contact’s Twitter profile.
    tiktokLink 'optional' Link to contact’s TikTok profile.
    variables 'optional' An array of contact variables and their values.
    name 'required' Variable name in lowerCamelCase format WARNING: Please use only latin lowerCamelCase format. No numbers or other symbols allowed.
    value 'required' Variable value in 'ENUM_STRING' or 'ENUM_DATE' (YYYY-MM-DD) format correspondingly
    sourceId 'optional' Contact’s unique source ID from SmartSender platform
    customerSourceId 'optional' Contact’s unique source ID from your system to synchronize two sides
    cac 'optional' value 'required' CAC value in 'ENUM_STRING' format correspondingly
    currency 'required' (EUR, USD) WARNING: Please use only latin uppercase format. No numbers or other symbols allowed.
  • To update contact data in the Contact List see example: 

     

    <script type="text/javascript">
        contact.update({    
    
            name: "John Doe",   
    
            email: "user@example.com",
    
            phoneNumber: "+15555555",
    
            userId: "myUserId",
    
            active: true,
    
            emailSubscribe: true,
    
            smsSubscribe: true,
    
            desktopWebPushSubscribe: true,
    
            mobileWebPushSubscribe: true,
    
            telegramSubscribe: true,
    
            firstName: "John",
    
            lastName: "Doe",
    
            contactBirthday: "1990-01-01",
    
            contactLanguage: "en",
    
            contactGender: "female",
    
            contactTimezone: "Europe/Tallinn",
    
            contactScore: 100,
    
            avatarLink: "img.smartsender.io/g/06c38b4568.jpg",
    
            facebookLink: "https://www.facebook.com/smartsender.io",
    
            instagramLink: "instagram.com/smartsender",
    
            linkedInLink: "linkedin.com/company/smartsender"
    
            twitterLink: "twitter.com/smart_sender",
    
            tiktokLink: "tiktok.com/smartsender",
    
            sourceId: "Source_ID_from_SmartSender",
    
            customerSourceId: "Customer_Source_ID_From_Your_Platform",
    
            cac: {
    
                value:      2.05,
    
                currency:   "USD",
    
            },
    
            variables: [
    
                {name: "stringVariableName", value: "newVariableValue"},
    
                {name: "dateVariableName", value: "2020-10-20"}
    
            ],
    
        });
    
    </script>

     

    Parameters
    contact
    'required'
    An array of contact information want to update.
    name
    'optional'
    The optional display name to use for the recipient
    email
    'optional'
    Contact’s email address.
    phoneNumber
    'optional'
    IMPORTANT should be valid E.164 phone number format.
    userId
    'optional'
    Contact’s unique user ID from your platform to enable management of the contact in the list based on it.
    active
    'optional'
    You can set if the contact is enable  contact list or not.
    The default value is false (disable).
    true
    'optional'
    Contact enabled. Contact can receive communication from enabled channels.
    false
    'default'
    Contact disabled. No communications will be send to this contact.
    emailSubscribe
    'optional'
    You can set if the contact is subscribed to receiving emails or not.
    The default value is false (unsubscribed).
    true
    'optional'
    Subscribe contact to emails
    false
    'default'
    Unsubscribe contact from emails
    smsSubscribe
    'optional'
    You can set if the contact is subscribed to receiving SMS or not.
    The default value is false (unsubscribed).
    true
    'optional'
    Subscribe contact to SMS
    false
    'default'
    Unsubscribe contact from SMS
    desktopWebPushSubscribe
    'optional'
    You can set if the contact is subscribed to receiving desktop web push notifications or not.
    The default value is false (unsubscribed).
    true
    'optional'
    Subscribe contact to desktop webpush notifications
    false
    'default'
    Unsubscribe contact from desktop webpush notifications
    mobileWebPushSubscribe
    'optional'
    You can set if the contact is subscribed to receiving mobile web push notifications or not.
    The default value is false (unsubscribed).
    true
    'optional'
    Subscribe contact to mobile webpush notifications
    false
    'default'
    Unsubscribe contact from mobile webpush notification
    telegramSubscribe
    'optional'
    You can set if the contact is subscribed to receiving Telegram messages or not.
    The default value is false (unsubscribed).
    true
    'optional'
    Subscribe contact to Telegram messages
    false
    'default'
    Unsubscribe contact from Telegram messages
    firstName
    'optional'
    Contact’s first name
    lastName
    'optional'
    Contact’s last name
    contactBirthday
    'optional'
    Contact’s birth date in ENUM_DATE (YYYY-MM-DD) format
    contactLanguage
    'optional'
    Contact’s locale in ISO 639-1 format
    contactGender
    'optional'
    Contact’s gender in ISO/IEC 5218 format
    0 Not known
    1 Male
    2 Female
    9 Not applicable
    contactTimezone
    'optional'
    Contact’s timezone in ISO 8601 format
    contactScore
    'optional'
    Contact Score
    avatarLink
    'optional'
    Link to contact’s avatar image.
    facebookLink
    'optional'
    Link to contact’s Facebook profile.
    instagramLink
    'optional'
    Link to contact’s Instagram profile.
    linkedInLink
    'optional'
    Link to contact’s LinkedIn profile.
    twitterLink
    'optional'
    Link to contact’s Twitter profile.
    tiktokLink
    'optional'
    Link to contact’s TikTok profile.
    variables
    'optional'
    An array of contact variables and their values.
    name
    'required'
    Variable name in lowerCamelCase format
    IMPORTANT Please use only latin lowerCamelCase format. No numbers or other symbols allowed.
    value
    'required'
    Variable value in 'ENUM_STRING' or 'ENUM_DATE' format correspondingly
    sourceId
    'optional'
    Contact’s unique source ID from SmartSender platform
    customerSourceId
    'optional'
    Contact’s unique source ID from your system to synchronize two sides. IMPORTANT If you use sourceId and customerSourceId at the same time, sourceId will have higher priority.
    cac
    'optional'
    value
    'required'
    CAC value in 'ENUM_STRING' format correspondingly
    currency
    'required'
    (EUR, USD)
    IMPORTANT Please use only latin uppercase format. No numbers or other symbols allowed.

     

Similar posting
  • Integration with Mailchimp
  • Zapier Integration
  • JS API methods
  • Add contact manually
  • Web Push Prompt Settings in JS
  • How to fire event via JS
Company
  • About us
  • Team
  • YouTube
  • Facebook
  • Google Business
Legal
  • Terms of Use
  • Privacy Policy
  • Anti-Spam Policy
  • Cookie Statement
Resources
  • Api Documentation
  • FAQ
  • Knowledge Base
  • SmartSender Blog
  • Marketplace

We use cookies to make SmartSender’s website a better place. Cookies help to provide a more personalized experience for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).

got it