1 00:00:00,750 --> 00:00:05,050 We now have a second grade event that represents an actual click on one of our emails. 2 00:00:05,250 --> 00:00:10,260 So we're going to look at this event right here and figure out how we can tell which survey the user 3 00:00:10,260 --> 00:00:15,140 just voted on and then make sure we update not only the feedback property on that survey. 4 00:00:15,150 --> 00:00:20,850 Remember the yes or no property but also make sure that the particular user gets marked as having given 5 00:00:20,940 --> 00:00:22,340 us a response. 6 00:00:22,500 --> 00:00:24,140 So we've got a pretty good amount of work here. 7 00:00:24,150 --> 00:00:25,270 Let's get to it. 8 00:00:25,560 --> 00:00:29,940 Let's first start off by inspecting this event that we got back from second grade a little bit more 9 00:00:29,940 --> 00:00:31,120 closely. 10 00:00:31,170 --> 00:00:34,420 You'll notice that the event itself has a type of click. 11 00:00:34,440 --> 00:00:37,740 So yes it's definitely a click on the link. 12 00:00:37,770 --> 00:00:39,930 We can also see who clicked on the link. 13 00:00:39,970 --> 00:00:45,180 Here's the email property and then we also get the URL that the user was attempting to visit. 14 00:00:45,180 --> 00:00:48,270 Now there's just one piece of the puzzle missing here. 15 00:00:48,480 --> 00:00:54,390 You'll notice that nothing inside this event is currently telling us anything about the survey that 16 00:00:54,390 --> 00:00:56,180 the user is responding to. 17 00:00:56,250 --> 00:01:02,180 And it's also not telling us whether or not the user clicked on the yes or no link inside the e-mail. 18 00:01:02,220 --> 00:01:04,980 So I think that we still need to do a little bit of work here. 19 00:01:05,010 --> 00:01:08,570 First off let's kind of just make things really crystal clear right now. 20 00:01:08,730 --> 00:01:13,640 So we've got some number of events coming from our sin grid web poll data. 21 00:01:14,130 --> 00:01:17,010 We know the users e-mail but nothing else. 22 00:01:17,100 --> 00:01:22,200 So if we have a big old list of surveys inside of our database right now we don't know if the user just 23 00:01:22,200 --> 00:01:26,580 clicked on a survey or an e-mail corresponding to this survey or this one. 24 00:01:26,580 --> 00:01:32,620 And then even then we don't know whether or not the user gave us a yes vote or no vote. 25 00:01:32,640 --> 00:01:37,620 In addition you know you might be thinking Well Stephen that's fine maybe we can look at all the different 26 00:01:37,620 --> 00:01:43,330 surveys and find the survey where the user's email address is marked as the recipient. 27 00:01:43,590 --> 00:01:45,050 Well that would definitely work out. 28 00:01:45,050 --> 00:01:49,630 But what happens if a given user was included on two different surveys. 29 00:01:49,770 --> 00:01:54,590 So maybe this recipient and this recipient right here are the exact same person. 30 00:01:54,750 --> 00:01:59,790 So we can't really just rely upon the user's e-mail for figuring out what survey they are belonging 31 00:01:59,790 --> 00:02:00,620 to either. 32 00:02:00,840 --> 00:02:06,640 So we need to think of a better approach for identifying what survey a user is responding to. 33 00:02:06,900 --> 00:02:07,870 Here's my suggestion. 34 00:02:07,920 --> 00:02:10,340 Here's where I think we should do right now. 35 00:02:10,380 --> 00:02:16,650 Whenever we give a link to a user to click on inside of the e-mail they are going to the route of API 36 00:02:16,800 --> 00:02:22,060 slash surveys slash things and they're always going to the same route no matter what. 37 00:02:22,140 --> 00:02:27,260 What I'm thinking is that maybe we should change up the route that we place inside of those emails. 38 00:02:27,420 --> 00:02:32,850 Instead we'll give them a route or something like API slash survey ID. 39 00:02:32,880 --> 00:02:38,950 So the very particular ID of the survey that they are attempting to look at slash choice. 40 00:02:39,210 --> 00:02:46,940 So in reality we might end up with a route that looks something like API slash ABC 1 2 3. 41 00:02:46,950 --> 00:02:48,290 So that's the route. 42 00:02:48,350 --> 00:02:53,610 I mean the idea of the survey that the user is responding to and then choice would either be yes if 43 00:02:53,610 --> 00:02:58,580 the user clicked on yes or no if the user clicks on no. 44 00:02:59,090 --> 00:03:04,230 So if we make sure that our e-mail kind of encodes this information into the link that the user is clicking 45 00:03:04,230 --> 00:03:11,580 on then when we get the response back from our web host data we can pull out the survey ID to figure 46 00:03:11,580 --> 00:03:16,230 out which surveyed the user was looking at and also figure out whether or not the user clicked on the 47 00:03:16,230 --> 00:03:18,460 yes or no button. 48 00:03:18,570 --> 00:03:23,310 We can then still find the correct recipient and make sure we update them as having responded to that 49 00:03:23,310 --> 00:03:26,050 survey and we can also make sure that we update the surveys. 50 00:03:26,070 --> 00:03:29,150 Yes and no property to record the actual feedback. 51 00:03:29,460 --> 00:03:31,560 So I think this is going to be a pretty good approach here. 52 00:03:31,590 --> 00:03:36,840 Lets take this type of direction to make sure that we update this link right here to kind of encode 53 00:03:36,840 --> 00:03:40,170 this information will go and find our e-mail template. 54 00:03:40,200 --> 00:03:45,720 So the template that we use to kind of populate the body of the emails that we're sending out so all 55 00:03:45,720 --> 00:03:51,810 change back to my code editor a find my services directory inside of there is the email templates folder 56 00:03:51,990 --> 00:03:55,050 and inside of there is the survey template file. 57 00:03:55,500 --> 00:03:59,080 So here are the two links that we are currently generating. 58 00:03:59,100 --> 00:04:01,440 We send the user to either API. 59 00:04:01,580 --> 00:04:05,750 Only Right now I should say to API slash surveys slash. 60 00:04:05,750 --> 00:04:09,430 Thanks and that's the only thing we're really sending user to now. 61 00:04:09,480 --> 00:04:14,820 You will recall that this function this template right here is being passed the survey model. 62 00:04:14,970 --> 00:04:18,740 So we already have access to the ID of this very particular survey. 63 00:04:19,050 --> 00:04:25,390 So in both links right here we're going to delete the word it let's do surveys in here. 64 00:04:25,470 --> 00:04:26,820 Let's let's change this up a little bit. 65 00:04:26,820 --> 00:04:31,620 Let's say that we will still go to slash surveys. 66 00:04:31,800 --> 00:04:37,890 So do API surveys and then the idea of the survey so it could still keep that kind of nice name spacing 67 00:04:37,890 --> 00:04:43,350 here of slash surveys rather than just always going to API slash idea the survey. 68 00:04:43,350 --> 00:04:45,490 So we'll keep those surveys namespace. 69 00:04:45,720 --> 00:04:52,780 So we'll say API surveys slash and will put in the idea of this particular survey. 70 00:04:53,160 --> 00:05:00,370 So survey ID and we're going to do this for both length's survey data. 71 00:05:00,770 --> 00:05:04,910 And then rather than showing just you know thanks on here we'll make sure that we encode whether or 72 00:05:04,910 --> 00:05:07,520 not the user clicks on yes or no. 73 00:05:07,820 --> 00:05:10,060 So in the first link this is the Yes button. 74 00:05:10,130 --> 00:05:11,720 So I want that to be yes. 75 00:05:11,750 --> 00:05:15,380 And then on the second one this would be no down here. 76 00:05:15,380 --> 00:05:21,050 So now whenever we generate this email body and send it out to the actual user the link that they click 77 00:05:21,050 --> 00:05:22,910 on will reflect API. 78 00:05:23,040 --> 00:05:27,090 Slash surveys the idea the survey they are responding to. 79 00:05:27,200 --> 00:05:29,360 And then yes or no. 80 00:05:29,960 --> 00:05:35,840 Let's now test this out through the entire flow and just make sure that we are communicating this information 81 00:05:35,870 --> 00:05:37,440 all the way down the chain. 82 00:05:37,580 --> 00:05:42,350 And once we kind of verify that that information is present We'll then figure out exactly how we pull 83 00:05:42,410 --> 00:05:48,000 the survey ID and the yes or no vote out of the Centigrade event. 84 00:05:48,170 --> 00:05:50,300 Let's test this thing out. 85 00:05:50,600 --> 00:05:52,780 I'm going to go back over to my re-act application. 86 00:05:52,790 --> 00:05:54,960 We're going to create a new survey. 87 00:05:55,400 --> 00:06:05,720 So I'll give this one a title of about a survey ID test that works I'll copy that on down and I'm going 88 00:06:05,720 --> 00:06:11,330 to send it to my test e-mail again and click on next and then send out the survey. 89 00:06:11,800 --> 00:06:14,790 It's now a flip on over to my e-mail account. 90 00:06:14,790 --> 00:06:22,460 Here's that survey I.D. test so now in theory the yes or no buttons are going to kind of include the 91 00:06:22,550 --> 00:06:27,740 idea of the survey that we are responding to and whether or not we're clicking on yes or no for this 92 00:06:27,740 --> 00:06:30,050 first test I had to click on the Yes button. 93 00:06:30,230 --> 00:06:31,700 So I click on yes. 94 00:06:31,970 --> 00:06:35,490 Now we get a message here that says cannot get this particular route. 95 00:06:35,510 --> 00:06:36,400 That's totally fine. 96 00:06:36,410 --> 00:06:40,910 That's just our express server saying hey I don't know what route you're attempting to visit here. 97 00:06:41,000 --> 00:06:45,590 So we will want to make sure that we still show users some nice message of Hey thanks for voting on 98 00:06:45,590 --> 00:06:49,510 our survey or something like that but we'll get around to that in just a second. 99 00:06:49,520 --> 00:06:55,430 Much more importantly you'll notice that our new route now shows the idea of the survey and the fact 100 00:06:55,430 --> 00:06:56,680 that we clicked on the option. 101 00:06:56,720 --> 00:06:58,060 Yes. 102 00:06:58,130 --> 00:07:05,480 So let's now flip over to our terminal and check out the response that we get from the web hook route. 103 00:07:05,480 --> 00:07:08,220 And so when I flip back over I just I timed it perfectly. 104 00:07:08,270 --> 00:07:11,960 Here's the response we got or the web hook data that we got from said grid. 105 00:07:12,020 --> 00:07:15,470 So remember that it always takes about 30 seconds to get your data over here. 106 00:07:15,470 --> 00:07:19,730 So if you don't see the data right away just pause the video for a second until you see the stuff pop 107 00:07:19,730 --> 00:07:21,330 up. 108 00:07:21,350 --> 00:07:27,410 So now inside of this event object that we got passed we were being told the e-mail the person who just 109 00:07:27,410 --> 00:07:33,620 voted and then we also are being told the idea of the survey that they are responding to and the fact 110 00:07:33,620 --> 00:07:35,180 that they clicked on the Yes button. 111 00:07:35,420 --> 00:07:42,050 So it's really now up to you and me to somehow extract the survey I.D. from this thing and also extract 112 00:07:42,050 --> 00:07:44,090 the fact that they voted yes. 113 00:07:44,420 --> 00:07:45,680 So let's take a quick break. 114 00:07:45,680 --> 00:07:47,470 When we come back the next set S.. 115 00:07:47,480 --> 00:07:49,520 We're going to figure out how we're going to parse this. 116 00:07:49,520 --> 00:07:53,960 You are all right here and pull out just the parts of the world that we care about. 117 00:07:54,020 --> 00:07:54,880 So quick break. 118 00:07:54,920 --> 00:07:56,590 We'll continue in the next section.