Skip to main content

Custom Javascript

A library of custom javascript snippet that we have gathered during the years

Updated this week

With the Custom Script feature for Campaigns, the possibilities are endless when it comes to styling, additional tracking, and actions for your campaigns.

Javascript Snippet Examples

Restart Campaign

By default, Triggerbee remembers what step the visitor saw last. Usually, this is not an issue, as most campaigns are hidden after signing up or performing the desired action. But in some cases, such as embedded forms and guides, you want the visitor to be able to do the guide again or re-enter a signup.

To achieve this, you must delete the campaign ID from the cookie that remembers what campaigns have already been interacted with. Here's an example of how to do that.

  • Put this code on the submit or final CTA button in your campaign or on the afterFormSubmit JS-event.

  • change {siteID} to your siteID, which you'll find in your Account Settings.

  • change {stateID} to the current step ID, which is in the URL of your campaign when you're on the last step in the campaign, eg. https://app.triggerbee.com/campaigns/12345/widgets/136370/editor?state=197808

var tbStateCookie = mtr.get_cookie("triggerbee_widgets_state_{siteID}"); 
var parsedCookie = JSON.parse(tbStateCookie);
parsedCookie.widgets = parsedCookie.widgets.filter(state => state.id != {stateID});
mtr.set_cookie("triggerbee_widgets_state_{siteID}",JSON.stringify(parsedCookie));

Did this answer your question?