Scenarios

From $1

    This document contains scenario information that demonstrates the use of AMPscript and functions.

    Scenario 1: Concerts in Your Area

    The information below demonstrates how to use AMPscript in conjunction with data extensions to send an email message to subscribers about concerts occuring in their area. The contents of the email depend on the subscriber's stated genre performances. Download a file containing the sample code for this scenario here.

    Data Extensions and Relationships

    The marketer creates a data extension to contain information about upcoming concerts. Each concert has an associated genre, range of ticket prices, date, artist, venue, and city. Later, the marketer will create AMPscript to include this information in an email based on the subscriber's city and genre preferences.

    The marketer creates a webpage (such as a Web Collect or a Smart Capture form) where subscribers indicate their preferred music genres. The preferences are stored in the Customer_Genre_Preferences data extension.

    The Subscriber table contains the following data:

    Email Address Customer ID First Name Last Name City
    ettest201@example.com 201 Angel Ruiz Indianapolis
    ettest202@example.com 202 John Doe Chicago

    The Customer_Genre_Preferences data extension contains the following data:

    Customer ID Genre
    201 Rock
    201 Alt Country
    201 Indie
    202 Pop
    202 Folk
    202 Rock

    The Upcoming_Shows data extension contains the following data:

    Concert ID Genre Low Price High Price Show Date Artist Venue City
    101 Rock 35 45 10/27/2007 Band A Venue A Indianapolis
    106 Indie 15 37.5 10/6/2007 Band B Venue B New York
    107 Indie 25 40 11/15/2007 Band C Venue C Chicago
    108 Alt-Country 25 47.5 10/27/2007 Band D Venue D Indianapolis
    109 Indie 35 50 10/30/2007 Band E Venue E New York
    111 Alt-Country 15 30 10/19/2007 Band F Venue F Chicago
    112 Indie 35 57.5 11/2/2007 Band G Venue G Indianapolis
    113 Folk 25 35 11/6/2007 Band H Venue H Chicago
    114 Alt-Country 15 30 11/15/2007 Band I Venue I Indianapolis
    115 Indie 25 35 10/27/2007 Band J Venue J Indianapolis
    116 Alt-Country 15 30 10/30/2007 Band K Venue K New York
    117 Rock 15 37.5 10/21/2007 Band L Venue L Chicago
    118 Indie 15 30 10/19/2007 Band M Venue M Indianapolis
    119 Indie 25 40 11/2/2007 Band N Venue N New York
    120 Alt-Country 25 40 11/6/2007 Band O Venue O Indianapolis
    121 Indie 35 57/5 11/15/2007 Band P Venue P Chicago
    122 Indie 15 30 10/27/2007 Band Q Venue Q Chicago
    123 Rock 25 35 10/30/2007 Band R Venue R Indianapolis
    124 Indie 35 57.5 10/21/2007 Band S Venue S Chicago
    125 Alt-Country 25 47.5 10/19/2007 Band T Venue T Chicago
    126 Alt-Country 35 57.5 11/2/2007 Band U Venue U Indianapolis
    127 Indie 25 35 11/6/2007 Band V Venue V Chicago
    128 Indie 15 30 11/15/2007 Band W Venue W Chicago
    129 Rock 35 57.5 10/27/2007 Band X Venue X New York
    130 Rock 25 40 10/30/2007 Band Y Venue Y Chicago
    131 Indie 25 47.5 10/21/2007 Band Z Venue Z New York
    132 Pop 35 57.5 10/19/2007 Band 0 Venue 0 Chicago
    133 Folk 25 35 11/2/2007 Band 1 Venue 1 New York
    138 Indie 35 50 10/21/2007 Band 2 Venue 2 Chicago
    139 Indie 15 37.5 10/29/2007 Band 3 Venue 3 Indianapolis
    140 Alt-Country 25 40 11/2/2007 Band 4 Venue 4 Chicago
    141 Pop 25 35 11/6/2007 Band 5 Venue 5 Indianapolis
    142 Rock 25 40 11/15/2007 Band 6 Venue 6 New York
    143 Rock 25 40 10/27/2007 Band 7 Venue 7 Indianapolis
    144 Rock 15 30 10/30/2007 Band 8 Venue 8 Chicago
    145 Alt-Country 25 40 10/21/2007 Band 9 Venue 9 Chicago
    146 Rock 35 50 10/19/2007 Band 10 Venue 10 Chicago
    148 Rock 35 50 11/6/2007 Band 11 Venue 11 Indianapolis

    AMPscript

    The following AMPscript appears in the body of the email.

    <html>
    <body style="font-size: 12px;color: #000099; font-family: verdana;">
    
    %%[ /* This is an AMPscript Comment */ ]%%
    
    <p>Hi %%First Name%%,<br><br>
    We want to tell you about upcoming shows in your area based on your favorite music genres.  We think you are as stoked as we are to see great live music and wanted to pass the word on.  Enjoy!<br><br>
    </p>
    
    <h3>Upcoming Shows in %%City%%</h3>
    <br><br>
    
    %%[
    /* First we want to determine if the customer has any favorite genres stored. If not, we want to encourage them to create online */
    /* Otherwise, we will loop through every genre we find */
    
    var @rsgenre, @rowgenre, @rsshow, @rowshow, @countergenre, @countershow, @currentgenre
    
    SET @rsgenre = LOOKUPROWS("Customer_Genre_Preferences", "Customer ID", [Customer ID])
    ]%%
    
    %%[
    if ROWCOUNT(@rsgenre) == 0 then
    ]%%
    
    <h4>We see that you don't have any genres stored, please add them online to get the most relevant information sent to you next time!</h4>
    <a href="http://music.example.com">Add My Genres</a>
    
    %%[
    else
    
    /* Now we are going to loop through each customer's genre, and then use that and City to look up upcoming shows to display in a table */
    /* if we find a genre, but no corresponding shows, we are not going to display anything for that genre */
    ]%%
    
      %%[
      for @countergenre = 1 to ROWCOUNT(@rsgenre) do
    
      SET @currentgenre = FIELD(ROW(@rsgenre, @countergenre), "Genre Preference")
      SET @rsshow = LOOKUPROWS("Upcoming_Shows", "City", City, "Genre", @currentgenre)
    
        if ROWCOUNT(@rsshow) != 0 then ]%%
          <h4>%%=CONCAT("Upcoming ", @currentgenre, " Shows")=%%</h4><br>
            <table width="700px" style="border: 1 solid black; font-size: 10px;color: #000099; font-family: verdana;" cellpadding="2" cellspacing="0">
              <tr style="font-size: 10px;color: #999999; font-family: verdana; font-weight: bold;">
                <td>Date</td>
                <td>Artist</td>
                <td>Venue</td>
                <td>Tickets</td>
                <td>City</td>
              </tr>
            %%[
            for @countershow = 1 to ROWCOUNT(@rsshow) do
              SET @rowshow = ROW(@rsshow, @countershow)
    
              /* Here we are setting alternating style for the row */
    
              if MOD(@countershow, 2)== 0 and @countershow != 1 then
            ]%%
    
              <tr style="background-color: #dcdcdc;">
    
            %%[else]%%
    
              <tr>
    
            %%[endif]%%
    
                <td>%%=FORMAT(FIELD(@rowshow, "Show Date"), "ddd, MMM d")=%%</td>
                <td>%%=FIELD(@rowshow, "Artist")=%%</td>
                <td>%%=FIELD(@rowshow, "Venue")=%%</td>
                <td><a href="http://music.com?ConcertID=%%=FIELD(@rowshow, 'Concert ID')=%%">%%=CONCAT("From", FORMAT(FIELD(@rowshow, "Low Price"), "C2")," to ", FORMAT(FIELD(@rowshow, "High Price"), "C2"))=%%</a></td>
                <td>%%=FIELD(@rowshow, "City")=%%</td>
              <tr>
    
            %%[
            next @countershow
            ]%%
    
            </table>
            <br><br>
        %%[
        endif
        ]%%
    
      %%[
      next @countergenre
      ]%%
    %%[
    endif
    ]%%
    
    <custom name="opencounter" type="tracking"><table cellpadding="2" cellspacing="0" width="600" ID="Table5" Border=0><tr><td><font face="verdana" size="1" color="#444444">This email was sent to:  %%emailaddr%% <br><br><b>Email Sent By:</b> %%Member_Busname%%<br>%%Member_Addr%% %%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%<br><br></font></td></tr></table><a href="%%profile_center_url%%" alias="Update Profile">Update Profile</a>
    
    </body>
    </html>

    Output

    When the marketer sends the email, the application processes the code:

    For Angel Ruiz:

    Hi Angel,

    We want to tell you about upcoming shows in your area based on your favorite music genres. We think you are as stoked as we are to see great live music and wanted to pass the word on. Enjoy!

    Upcoming Shows in Indianapolis

    Upcoming Rock Shows
    Date Artist Venue Tickets City
    Sat, Oct 27 Band A Venue A From $35.00 to $45.00 Indianapolis
    Tue, Oct 30 Band R Venue R From $25.00 to $35.00 Indianapolis
    Sat, Oct 27 Band 7 Venue 7 From $25.00 to $40.00 Indianapolis
    Tue, Nov 6 Band 11 Venue 11 From $35.00 to $50.00 Indianapolis
    Upcoming Alt-Country Shows
    Date Artist Venue Tickets City
    Sat, Oct 27 Band D Venue D From $25 to $47.50 Indianapolis
    Thu, Nov 15 Band I Venue I From $15.00 to $30.00 Indianapolis
    Tue, Nov 6 Band O Venue O From $25.00 to $40.00 Indianapolis
    Fri, Nov 2 Band U Venue U From $35.00 to $57.50 Indianapolis
    Upcoming Indie Shows
    Date Artist Venue Tickets City
    Fri, Nov 2 Band G Venue G From $35.00 to $57.50 Indianapolis
    Sat, Oct 27 Band J Venue J From $25.00 to $35.00 Indianapolis
    Fri, Oct 19 Band M Venue M From $15.00 to $30.00 Indianapolis
    Mon, Oct 29 Band 3 Venue 3 From $15.00 to $37.50 Indianapolis

    For John Doe:

    Hi John,

    We want to tell you about upcoming shows in your area based on your favorite music genres. We think you are as stoked as we are to see great live music and wanted to pass the word on. Enjoy!

    Upcoming Shows in Chicago

    Upcoming Pop ShowsEdit section
    Date Artist Venue Tickets City
    Fri, Oct 19 Band 0 Venue 0 From $35.00 to $57.50 Chicago
    Upcoming Folk Shows
    Date Artist Venue Tickets City
    Tue, Nov 6 Band H Venue H From $25.00 to $35.00 Chicago
    Upcoming Rock Shows
    Date Artist Venue Tickets City
    Sat, Oct 27 Band L Venue L From $15.00 to $37.50 Chicago
    Tue, Oct 30 Band R Venue R From $25.00 to $35.00 Chicago
    Sat, Oct 27 Band 7 Venue 7 From $25.00 to $40.00 Chicago
    Tue, Nov 6 Band 11 Venue 11 From $35.00 to $50.00 Chicago

    Scenario 2: Suggested Car Listings

    In this example, a car broker wants to send a subscriber an email that includes a list of makes and models of cars that the subscriber might like based on the subscriber's stated preference as to type of car.

    The car broker creates an attribute for the subscriber to contain the subscriber's preference in car type. The broker populates the attribute with a survey.

    Data Extensions and Relationships

    The car broker also creates a data extension that contains multiple makes and models of cars for each of the short list of types that the subscribers could choose in the survey. The car broker creates a data relationship to associate the car_preference attribute on the subscriber to the type column in the data extension.

    CarListing1.PNG

    The subscriber table contains the following data:

    email_address first_name
    last_name
    region
    car_preference
    aruiz@example.com Angel Ruiz north sedan
    johndoe@example.com John Doe south convertible
    janedoe@example.com Jane Doe north SUV

    The cars data extension contains the following data:

    type
    make
    model
    Sedan Company A Sedan A
    Sedan Company B Sedan B
    Sedan Company C Sedan C
    Convertible Company D Convertible A
    Convertible Company E Convertible B
    SUV Company F SUV A
    SUV Company D SUV B
    SUV Company G SUV C
    SUV Company H SUV D

    AMPscript

    The car broker includes the following AMPscript block in the body of the email:

    <html>
    ...
    <table style= "border: 1px solid black">
    %%[   /* Starting AMPscript */
    
    /* Declaring variables */
    
    var @rs, @row, @cntr
    
    /* Looking up related cars by subscriber */
    /* Using lookup rows function to return a rowset of related cars to use */
    
    SET @rs = LookupRows("Cars", "Type", car_preference)
    
    /* Looping through each record in the recordset */
    
    for @cntr = 1 to RowCount(@rs) do
    
        /* If there is a value in the row, output to HTML */
    SET @row = Row(@rs, @cntr)
      /*Ending script block here */ ]%%
    
            %%=Field(@row, "Make")=%%  &nbsp; &nbsp; &nbsp; %%=Field(@row, "Model")=%%
    
    
        %%[  /* resuming script block here */
    next @cntr
      /*Ending script block */]%%
        </table>
    
    </html>

    Output

    When the car broker sends the email, the application processes the code:

    For Angel Ruiz

    Company A Sedan A
    Company B Sedan B
    Company C Sedan C

    For John Doe

    Company D Convertible A
    Company E Convertible B

    For Jane Doe

    Company F SUV A
    Company D SUV B
    Company G SUV C
    Company H SUV D

    This page was last updated by Ryan Williams on Tue, 13 Dec 2011 13:51:28 GMT.

    If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:

     


    Was This Page Helpful?
    Suggestions or Comments:
    Name (optional):
    Email Address (optional):
    Enter 16215 backwards:
       
    Tags: (Edit tags)
    • No tags
    FileSizeDateAttached by 
    CarListing1.PNG
    No description
    8.36 kB09:51, 13 Dec 2011AdminActions
    ConcertsInYourArea.zip
    No description
    7.49 kB09:51, 13 Dec 2011AdminActions
    RockShowOutput1 (1).png
    No description
    29.79 kB09:51, 13 Dec 2011AdminActions
    RockShowOutput2.PNG
    No description
    22.63 kB09:51, 13 Dec 2011AdminActions
    Comments (0)
    You must login to post a comment.

     
    Powered by MindTouch 2010
    Admin