Hi there,
It sounds like a journey webhook is likely going to be the best solution here. If you set up a journey that is triggered by a click event for a particular campaign that this snippet is called in, (you can filter by the specific URL or URLs that are rendered by your snippet code), you can then call a journey webhook within that journey to send that click event data to whatever endpoint you like. Since the click event is what triggered the journey, a simple webhook with no custom code should pass the information about the click event to your endpoint. Feel free to reach out to our support team for further troubleshooting/setup by emailing support@iterable.com , or creating a ticket from within the Iterable UI by clicking the question mark in the top-right corner, and then selecting “submit a ticket” from the dropdown.
Best,
Heather
Hey @TenTops - wanted to follow up conceptually on @Heather Spoelstra’s answer here so that you have a better understanding of Iterable and Handlebars going forward - and my apologies if you already know all this and it’s redundant!
Handlebars is a templating language for JavaScript, meaning it’s meant for rendering HTML. Iterable adds some special sauce so that you can use the Handlebars syntax to also render text in SMS, push, in-app, etc but when you use Handlebars, you generally want to think of it as a tool meant for displaying content to the screen unless Iterable explicitly says you can use Handlebars syntax for something else.
In your case, when you use Handlebars in a template, it is able to read properties from the user and/or event objects associated with a user, but it’s not able or meant to pass data between the steps of an Iterable workflow since Handlebars is focused on rendering content within an individual workflow step’s template itself. So what you need to do is push data to someplace where you can store it for future reference.
That’s enough theory, now onto your question and code.
If I am reading your question and code correctly, it looks to me like you want to store the number of times a certain event has occurred for a given user, and render some HTML to them in an email based on the value of that number.
My recommendation to you would be to do what @Heather Spoelstra suggested and set up a workflow that is triggered by the two click events and then use filters to narrow down your conditions as you see fit within the workflow. In the end, you want to have the logic in place for one or more workflow nodes that will update the user profile directly with the value of counter that you’d like.
Luckily, Iterable has included their special sauce syntax to allow you to reference the user and triggering event object within an Update User Profile node, so you should be able to handle all of the logic you are currently trying to handle within the email template within this node instead, and this will allow you to reference it within future workflows’ steps.
Let me know if that makes sense or if you have any follow up questions! What you want to achieve is definitely do-able, you just need to flip some stuff around so that you are pushing and pulling data from the right places at the right times.