by Dave | activecampaign
In this video, we’re going to talk about how to total the order value of the last five orders, as well as the average value of those last five orders.
Now to do so we’re going to need to create some custom fields, we’re going to call them current order order, total order average, and then order 123 up to five. And actually, you can have as many or as few as you want. The way this works, it’ll work, no matter how many orders you have, we’re going to have an automation, that triggers a web hook to your web server, and that web hook is going to do calculations, then update the contact, and the script was listed right there.
So let’s go ahead and dive right in.
To start inside your Active Campaign account, you’re going to want to create some custom fields. So under list, manage fields, and new custom field, we’re going to call one current order order, total order average, and then order one through five. Again, you can have as many years few of these as you want, doesn’t matter if they’re capitalized or not, no big deal. And then just to show you what the code looks like, and what it does, it’s right here.
Here, these two things are these three things that top you’re going to want to modifies, you’re going to want to have your API key from Active Campaign here, and your API URL right in there. And then how many orders you want to consider. So those are the only things you need to change.
What happens below is the script will catch the person’s ID and email address from Active Campaign, it will parse through the results. And then it’s going to create a result of orders, it’s going to do the math down here, it’s basically going to sum up all the orders and give you an order total, it’s going to give you an order average. And it’s smart enough to realize if you don’t have for instance, five values. If you only have two values, it will only do an average on those two values. And then it basically puts that pushes that information back to Active Campaign inside Active Campaign, we’re going to have a automation that starts when a field changes.
So for instance, when current order changes, then a web hook is sent to this script on your site. And that will update the contact. So let’s do some examples here. So here’s an example of a contact, these are the current fields, there’s nothing in here right now. So let’s say the first order. And my assumption is, you’re going to have a way to have this current or value updated. So in other words, your shopping cart might send information and push it into that custom field. Once it does that the automation takes over. So here we go.
So refresh this and show you what the numbers are.
So there it is, current orders 100 totals 100 average orders, and order one is honored. Now I’m going to put in 50, so the order total should go up to 150, they should go to 75, this should go to 50. And this should go to 100. So let’s do that.
There it is. So the order totals up 250, 75, 1500.
Now let’s make this go up to 300. So I’m going to do 150, the average is going to bump up to 100, and these borders shift down. So let’s do 150. Okay, we’ll just keep doing a few more examples. Let’s do 400. No idea what the order total is going to be. Well, actually, 400 plus 300 should be 700. I don’t know what the average will be though.
So now that we got five fields the next time I put something in their order five is going to get pushed off. Like I said, you can have as many or as few as you want. You just need to make sure there’s a number of fields and then you’ve matched that up inside this script on your account.
So let’s do 44 inside Active Campaign. That’s how we can calculate order values.