1 00:00:00,680 --> 00:00:06,020 The last video we spoke about how we were going to take our instance of a survey and an e-mail template 2 00:00:06,020 --> 00:00:11,490 that we're about to create and merge the two together inside of a Meyler object at the very end I had 3 00:00:11,510 --> 00:00:17,540 said that somehow communicating this mailer off to the email provider is a rather complicated process 4 00:00:17,750 --> 00:00:21,590 particularly for the application that you and I are going to build. 5 00:00:21,620 --> 00:00:23,210 So let's dive into this. 6 00:00:23,210 --> 00:00:26,720 We're going to figure out why it's challenging and why this is all such a big deal. 7 00:00:27,260 --> 00:00:27,580 OK. 8 00:00:27,620 --> 00:00:29,600 So again we're going to look at a diagram here. 9 00:00:29,680 --> 00:00:35,660 That's going to help you understand exactly how this mailer gets sent off to the e-mail provider. 10 00:00:35,720 --> 00:00:37,640 We're going to look at two different diagrams. 11 00:00:37,640 --> 00:00:43,000 The first diagram is going to show you a bad way of communicating the mailer to the provider. 12 00:00:43,190 --> 00:00:46,930 And the second one is going to be the good way the way in which we are going to do it. 13 00:00:46,940 --> 00:00:48,730 So let's take a look. 14 00:00:49,500 --> 00:00:49,820 OK. 15 00:00:49,850 --> 00:00:51,440 So this is the bad approach here. 16 00:00:51,470 --> 00:00:56,070 This is what you and I do not want to do in this type of approach. 17 00:00:56,090 --> 00:01:03,440 I'm saying that for every single recipient inside of our survey list we could create a separate mailer 18 00:01:03,490 --> 00:01:04,570 object. 19 00:01:04,880 --> 00:01:10,160 We could then send that mailer object off to our e-mail provider and that e-mail provider would that 20 00:01:10,220 --> 00:01:13,550 send the e-mail off to the individual recipient. 21 00:01:13,550 --> 00:01:16,120 Now why might this be about approach right here. 22 00:01:16,490 --> 00:01:23,300 Well when you think about it if we say that for every single recipient we are going to create one mailer 23 00:01:23,360 --> 00:01:24,230 object. 24 00:01:24,380 --> 00:01:31,790 And then in one single HTP request we're going to send each and every Mailer or excuse me one separate 25 00:01:31,790 --> 00:01:33,320 request for every mailer. 26 00:01:33,320 --> 00:01:41,590 We would then have ten thousand or a thousand or 100000 separate requests required to handle one survey. 27 00:01:41,600 --> 00:01:49,850 In other words for every single recipient who is inside of one survey be it 1000 10000 or 100000. 28 00:01:49,890 --> 00:01:50,260 We will. 29 00:01:50,270 --> 00:01:55,310 We are saying that we're going to create a separate Mailer and communicate it to our e-mail provider 30 00:01:55,490 --> 00:01:58,570 in a separate HTP request. 31 00:01:58,610 --> 00:02:04,640 Now obviously off the bat we probably don't want to make a separate request over to this e-mail provider 32 00:02:04,670 --> 00:02:06,670 for every single recipient. 33 00:02:06,740 --> 00:02:14,180 It would be a lot better if we could somehow take all of these recipients create one mailer object and 34 00:02:14,180 --> 00:02:20,570 then just take that one single e-mail or that one single Mailer and communicate off to our e-mail provider. 35 00:02:20,570 --> 00:02:26,450 In other words I want to do a sort of batch operation and say for all the different recipients who are 36 00:02:26,450 --> 00:02:31,190 attached to a single survey just make one mailer and send it off. 37 00:02:31,190 --> 00:02:33,740 And so that's exactly what we're going to do. 38 00:02:33,800 --> 00:02:39,070 We're going to take all of the different recipients who are included inside of our survey. 39 00:02:39,140 --> 00:02:44,750 We're going to create one single mailer object and then we're going to pass that mailer off to our e-mail 40 00:02:44,750 --> 00:02:51,890 provider and one Cingular network request will then leave it to our e-mail provider to figure out exactly 41 00:02:51,890 --> 00:02:56,270 how to handle the e-mail to each individual recipient. 42 00:02:56,270 --> 00:02:56,910 OK. 43 00:02:57,200 --> 00:03:01,240 So this is the approach we're going to take right here for all these different recipients. 44 00:03:01,250 --> 00:03:06,120 Will make one mailer we'll send the one mailer off to the e-mail provider. 45 00:03:06,620 --> 00:03:13,720 Now how does this approach affect our application and it really does in a big way. 46 00:03:13,730 --> 00:03:19,400 So let's kind of break this down let's consider some of the cons of this approach right here and figure 47 00:03:19,400 --> 00:03:23,600 out exactly how we're going to address them inside of our application. 48 00:03:23,630 --> 00:03:29,000 First thing I want to do is look back at a diagram that we were just glancing at in the last video. 49 00:03:29,000 --> 00:03:36,140 Remember we had said that for a given mailer we have one survey instance and we have one e-mail templates 50 00:03:36,650 --> 00:03:43,400 and this e-mail template right here provides the kind of HVM L or kind of the body of the actual e-mail 51 00:03:43,400 --> 00:03:44,820 that a user receives. 52 00:03:45,080 --> 00:03:49,400 So essentially that e-mail template is creating this stuff right here. 53 00:03:49,400 --> 00:03:50,730 The message to the user. 54 00:03:50,810 --> 00:03:55,910 And it also is going to set up the two possible links that a user can click to provide feedback to our 55 00:03:55,910 --> 00:03:57,280 application. 56 00:03:57,320 --> 00:04:04,010 So if we are using the exact same templates the exact same Like instance of the template for all these 57 00:04:04,010 --> 00:04:06,490 people what's the downside to that. 58 00:04:06,690 --> 00:04:09,560 Let's think it through for a minute. 59 00:04:09,560 --> 00:04:16,890 So if everyone is getting the exact same e-mail like I mean every last character 100 percent identical 60 00:04:17,450 --> 00:04:20,230 even the links inside the e-mail are identical. 61 00:04:20,330 --> 00:04:21,780 And that's the important part here. 62 00:04:21,800 --> 00:04:26,000 So let's imagine that everyone is getting the exact same links and the e-mail. 63 00:04:26,090 --> 00:04:31,040 How are we going to somehow understand who clicked on a link. 64 00:04:31,040 --> 00:04:31,650 Whenever they do. 65 00:04:31,650 --> 00:04:37,010 Like if you get this e-mail and you click on No right now how am I going to know that you clicked on 66 00:04:37,010 --> 00:04:39,780 this e-mail as opposed to someone else. 67 00:04:39,820 --> 00:04:41,300 And why do we care about that at all. 68 00:04:41,300 --> 00:04:47,480 Well remember that was the entire purpose of recording that list of recipients inside of our survey 69 00:04:47,480 --> 00:04:53,390 schema we had said that we want to store the list of recipients so that for every different email we 70 00:04:53,390 --> 00:04:58,730 send out or every single recipient we have indicated by this e-mail property right here we want to make 71 00:04:58,730 --> 00:05:02,860 sure that we record whether or not they have responded to the e-mail previously. 72 00:05:03,240 --> 00:05:08,170 And that we were going to do that to make sure that we kind of put a curb on any sort of duplicate votes 73 00:05:08,170 --> 00:05:09,330 inside of our application. 74 00:05:09,340 --> 00:05:12,010 We don't want people to be able to vote multiple times. 75 00:05:12,130 --> 00:05:16,160 So we were going to start off everyone with a responded Of false. 76 00:05:16,270 --> 00:05:20,060 And then after you provide us feedback one time we flip this over to true. 77 00:05:20,080 --> 00:05:22,700 And then after that we no longer record your votes. 78 00:05:22,960 --> 00:05:28,540 So remember we went through this entire process of ensuring that we could somehow uniquely identify 79 00:05:28,540 --> 00:05:33,990 people in order to combat possible fraudulent votes or duplicate votes. 80 00:05:34,000 --> 00:05:39,610 And so when you look back at the actual e-mail right here it obviously becomes very pinnacle to make 81 00:05:39,610 --> 00:05:45,210 sure that you and I understand exactly who is clicking on this link. 82 00:05:45,250 --> 00:05:46,880 Now why is this such a challenge. 83 00:05:46,930 --> 00:05:53,980 Remember again you and I we do not or we are not going to have the ability to create a separate link 84 00:05:53,980 --> 00:06:00,310 right here for every individual user because everyone is going to be getting the same exact mailer so 85 00:06:00,370 --> 00:06:08,240 everyone sees the exact same link so just to kind of drill this point home because I want to make sure 86 00:06:08,240 --> 00:06:11,480 that it's really clear really you know very very clear. 87 00:06:11,480 --> 00:06:17,000 The last thing I want to say here is in a perfect world we would have been able to set up this route 88 00:06:17,000 --> 00:06:25,010 right here or this link right here as send you to somewhere like email dot com surveys slash feedback. 89 00:06:25,280 --> 00:06:30,420 And then maybe we indicate the idea of the survey with like you know 1 2 3 right here. 90 00:06:30,530 --> 00:06:33,800 So maybe this email corresponds to survey 1 2 3. 91 00:06:34,010 --> 00:06:38,840 And then maybe if the user clicked on the no button we would do something like Slash no to say save 92 00:06:38,840 --> 00:06:40,080 the user clicked on no. 93 00:06:40,280 --> 00:06:45,260 And then in the link right here Ideally we would have been able to put the user's e-mail address so 94 00:06:45,260 --> 00:06:50,770 something like email or user out example dot com. 95 00:06:50,810 --> 00:06:56,810 So inside of just the URL of this link right here or if someone clicked on this link we could say OK 96 00:06:56,810 --> 00:07:00,090 someone's trying to give us feedback for survey 1 2 3. 97 00:07:00,140 --> 00:07:01,390 They want to vote no. 98 00:07:01,430 --> 00:07:04,610 And here is the e-mail address of this particular user. 99 00:07:04,640 --> 00:07:08,570 So if we've been able to do something like this it would have solved all of our problems and we could 100 00:07:08,570 --> 00:07:14,870 say that we could customize every single link here when the user clicks it just by the path that the 101 00:07:14,870 --> 00:07:18,070 user linked on we can figure out exactly what to do. 102 00:07:18,280 --> 00:07:21,770 And so what I'm saying very clearly here I'm trying to make sure this is really clear. 103 00:07:21,770 --> 00:07:28,340 I'm telling you that everyone is going to get the exact same link so we cannot somehow communicate the 104 00:07:28,340 --> 00:07:30,340 email inside the link. 105 00:07:30,350 --> 00:07:31,790 This is the best we can do right here. 106 00:07:31,820 --> 00:07:38,630 At best we can say hey if you click on this link it'll take you to feedback for survey 1 2 3 and you 107 00:07:38,630 --> 00:07:40,360 are attempting to vote yes or no. 108 00:07:40,640 --> 00:07:47,630 We cannot put any identifying token into the email because everyone gets the exact same one from a single 109 00:07:47,690 --> 00:07:48,600 mailer. 110 00:07:49,130 --> 00:07:49,570 OK. 111 00:07:49,610 --> 00:07:52,550 So I feel like it probably drilled at home enough. 112 00:07:52,790 --> 00:07:57,830 Hopefully you understand it by now hopefully understand that we need some mechanism to uniquely identify 113 00:07:57,830 --> 00:07:59,880 users who click on these links. 114 00:07:59,960 --> 00:08:01,850 So obviously there's a solution to this. 115 00:08:01,850 --> 00:08:03,430 Let's talk about what we're going to do. 116 00:08:03,880 --> 00:08:09,740 So to solve this problem this is going to go into a little bit of the behind the scenes stuff with our 117 00:08:09,800 --> 00:08:12,950 e-mail provider and the e-mail provider that we're going to use. 118 00:08:12,980 --> 00:08:17,000 So I can tell you right now is a provider called cent.. 119 00:08:17,330 --> 00:08:19,870 So we'll sign up for this provider in just a minute. 120 00:08:19,880 --> 00:08:26,600 But if you want to you can open up a new browser tab and go to send grid dot com and check out a little 121 00:08:26,600 --> 00:08:28,960 bit there documentation. 122 00:08:29,060 --> 00:08:33,050 So we're going to talk a little bit about what send grids does behind the scenes. 123 00:08:33,050 --> 00:08:38,870 That's going to solve this problem that we have been able to identify our users uniquely. 124 00:08:38,870 --> 00:08:39,440 All right. 125 00:08:39,470 --> 00:08:40,860 So let's get to it. 126 00:08:41,480 --> 00:08:47,900 So whenever we send grid to send out an e-mail to one of our users send grid does something a little 127 00:08:47,900 --> 00:08:50,890 bit automatic behind the scenes for us. 128 00:08:50,960 --> 00:08:57,740 Here's what they do for each user that centigrade is going to send an e-mail to they look at the body 129 00:08:57,740 --> 00:09:03,180 of the e-mail and they look to see if any links exist in that e-mail. 130 00:09:03,530 --> 00:09:08,090 And in our case there will be links right where we have the yes link and then no link. 131 00:09:08,300 --> 00:09:12,610 We never send grid sees a link inside of our e-mail. 132 00:09:12,710 --> 00:09:20,600 They automatically replace the link with a customized link that sends the user to their own servers. 133 00:09:20,600 --> 00:09:26,240 So in other words regardless of what you are l you and I put inside these two links right here regardless 134 00:09:26,240 --> 00:09:31,880 of what you and I do when censored sends out this e-mail they are going to replace the destination links 135 00:09:31,880 --> 00:09:37,960 inside of here with links that send the user to their own personal send grid server. 136 00:09:38,300 --> 00:09:43,820 And they do this to build a collect metrics on what links people are clicking inside of all these different 137 00:09:43,820 --> 00:09:45,660 e-mails they're sending out. 138 00:09:45,680 --> 00:09:52,460 So whenever a user clicks on Aslund great here they will be sent off to send grid's server grade is 139 00:09:52,460 --> 00:09:58,370 going to record some analytic information about the user and then send good sense off the user to the 140 00:09:58,370 --> 00:10:03,380 actual destination of the link like the actual original destination. 141 00:10:03,380 --> 00:10:05,180 So how is that going to help us out here. 142 00:10:05,180 --> 00:10:07,670 Well here's what happens. 143 00:10:07,670 --> 00:10:13,060 So when we tell grid to send an e-mail out to people send it is going to scan the e-mail. 144 00:10:13,220 --> 00:10:17,510 It's going to replace every link with their own very individual special one. 145 00:10:17,720 --> 00:10:20,830 And then here is the very important part here. 146 00:10:20,990 --> 00:10:27,560 When when when grid replaces these links with their own special ones they customize the links for each 147 00:10:27,650 --> 00:10:31,850 individual person that the e-mail is going to be sent out to. 148 00:10:31,850 --> 00:10:38,060 So even though you and I are communicating this email over to send grade with a single mailer object 149 00:10:38,300 --> 00:10:44,390 which room which means that we only have like exactly one unique copy the e-mail sent grid goes back 150 00:10:44,390 --> 00:10:51,140 through the e-mail in that customizes each e-mail to be very particular to every specific recipient 151 00:10:51,230 --> 00:10:54,000 every specific person who actually gets the e-mail. 152 00:10:54,380 --> 00:11:01,100 So when Segretti replaces these links they put some token into the link that uniquely identifies the 153 00:11:01,100 --> 00:11:01,880 user. 154 00:11:01,880 --> 00:11:06,510 So send Gred in fact knows what user is clicking on a link. 155 00:11:06,550 --> 00:11:12,850 We don't send grid does because they go through this customization process just for the purpose of collecting 156 00:11:12,850 --> 00:11:14,600 some type of metrics. 157 00:11:14,620 --> 00:11:20,020 So what we really want to do is somehow get censored to tell us whenever someone clicks a link on an 158 00:11:20,020 --> 00:11:20,510 e-mail. 159 00:11:20,530 --> 00:11:22,730 And that's exactly what we're going to do. 160 00:11:22,750 --> 00:11:29,080 So after sending semi-rigid replaces all these links they send out the e-mail a user clicks on the link 161 00:11:29,440 --> 00:11:32,450 send grid sees that the user clicked on the link. 162 00:11:32,470 --> 00:11:35,260 They know exactly who clicked on it. 163 00:11:35,440 --> 00:11:38,800 The user gets sent off to the destination and the user is happy. 164 00:11:39,070 --> 00:11:45,820 But then more importantly Saenger then sends a little message to our server informing us that hey someone 165 00:11:45,820 --> 00:11:47,720 just clicked on one of your links. 166 00:11:47,800 --> 00:11:48,970 Here's the link it was. 167 00:11:49,120 --> 00:11:54,760 And here is some information about that particular user who clicked on the link specifically the e-mail 168 00:11:54,760 --> 00:11:57,100 address of the person who clicked on it. 169 00:11:57,220 --> 00:12:03,670 And so this whole process right here is what is going to save us from not knowing who clicks on the 170 00:12:03,670 --> 00:12:05,230 link. 171 00:12:05,770 --> 00:12:06,510 So one more time. 172 00:12:06,520 --> 00:12:07,560 I know it's a long section. 173 00:12:07,570 --> 00:12:12,660 I know that I'm repeating this stuff about why the links you know why we can't really use this effectively. 174 00:12:12,670 --> 00:12:17,140 But I again I really want to make sure that this stuff is very clear because we are definitely in a 175 00:12:17,140 --> 00:12:21,040 jump through a couple of hoops to make sure that all this stuff works correctly and I want to understand 176 00:12:21,310 --> 00:12:23,200 why we're taking this extra trouble. 177 00:12:23,200 --> 00:12:24,070 So from the top. 178 00:12:24,070 --> 00:12:32,230 One more time you and I are creating a single mailer object that mailer contains exactly identical content 179 00:12:32,290 --> 00:12:35,600 for every single user that we are sending the survey out to. 180 00:12:35,620 --> 00:12:40,200 So we have no ability to customize these links on a per user basis. 181 00:12:40,360 --> 00:12:44,710 So we do not know who is clicking on any individual link. 182 00:12:44,890 --> 00:12:50,800 Thankfully when we tell it to send out the e-mail send great is going to replace every link with one 183 00:12:50,800 --> 00:12:57,010 of their own and the link that says great replaces it with is a very special link that is customized 184 00:12:57,010 --> 00:13:03,700 for each individual particular recipient of the email after the user clicks on the link send grid then 185 00:13:03,700 --> 00:13:09,520 knows exactly who clicked on it because they customized the link for every individual person said Great 186 00:13:09,550 --> 00:13:16,410 Well then send a message to our server telling us about the link now this very last step of the process 187 00:13:16,410 --> 00:13:20,760 here where second grade eventually sends a message back to our server telling us that someone clicked 188 00:13:20,760 --> 00:13:27,690 on something just you know this process is referred to as a web hook a web poke is anything where some 189 00:13:27,750 --> 00:13:34,050 outside API is kind of facilitating some process and then gives our application some type of callback 190 00:13:34,050 --> 00:13:37,410 or some type of little notice that some events just occurred. 191 00:13:37,620 --> 00:13:39,860 So we refer to this as a web book. 192 00:13:40,040 --> 00:13:46,650 And so maybe now if we go back to our route definitions Baqir the route we had spoken about to record 193 00:13:46,650 --> 00:13:51,750 feedback from a user we had named it API slash survey slash web hooks. 194 00:13:51,750 --> 00:13:58,770 So this right here this route is going to be a route that only send grid accesses and send it at some 195 00:13:58,770 --> 00:14:03,210 intervals are going to be sending us a little notification saying hey someone just clicked on one of 196 00:14:03,210 --> 00:14:03,660 your links. 197 00:14:03,660 --> 00:14:05,090 Here's the information about it. 198 00:14:05,130 --> 00:14:07,960 So that's why we call this thing Web hook back here. 199 00:14:08,490 --> 00:14:09,340 OK. 200 00:14:09,750 --> 00:14:11,160 So that's the entire process. 201 00:14:11,170 --> 00:14:15,360 It is the I think that we've gone through it in great deal detail at this point. 202 00:14:15,360 --> 00:14:16,500 So let's take a quick break. 203 00:14:16,500 --> 00:14:18,180 We're going to come back in the next section. 204 00:14:18,210 --> 00:14:23,580 We're going to start to sign up with send grid and integrate center grid into our application in order 205 00:14:23,580 --> 00:14:25,210 to send out all these e-mails. 206 00:14:25,360 --> 00:14:28,020 So see in the next section.