Skip to main content
All CollectionsMini Lessons
Trigger Campaigns By Button Click
Trigger Campaigns By Button Click
Savannah Williamson avatar
Written by Savannah Williamson
Updated over 6 months ago

If you're wanting to trigger a popup campaign on a button click from your site you can accomplish this exact use case by setting up an anchor link on the button on your site (ex: <a href=โ€œ#show_signup"></a>)

โ€
โ€‹


๐Ÿ’ป Prepare the Anchor Link on Your Site

Add an anchor link to your button. Example: <a href="#show_signup"></a>. This link will serve as the conditions for your campaign to show.

โ€

๐Ÿš€ Set Up the Campaign in Amped

Visitor Segment: Select 'All Visitors' as you want this to show anytime the link is clicked (you could use others but Amped will consider all the targeting rules vs โ€œAll Visitorsโ€ is more wide open)

Trigger Configuration: Use โ€œTime on page of 0 secondsโ€

Page Targeting: Choose โ€œCurrently Viewing a page URLโ€ that contains "#show_signup" or whatever you set in your anchor link.

Frequency Setting: Set this to 'Once per page view' to activate the campaign each time the link is clicked.

Safe Display Setting: Choose 'Autonomous' under 'Safe Display' so that the campaign shows regardless of if the visitor has seen other Amped campaigns recently.

โ€

๐Ÿ‘‹ Add Code for #Hashtag Removal

You will want to make sure the X's on all steps, as well as the last step CTA to return to site all include a piece of custom code to remove the hashtag from the url so that your campaign doesn't continually fire.

โ€

  1. Navigate to the X's/last step CTA > Button Actions > Add Action

  2. Select "Custom Code"

  3. Rename to "Remove #" and paste script into body, then save!

โ€

๐Ÿ’ป Here is the script to use in your campaign

// Remove the Hash fragment from the URL
function removeHashFragment() {
if (window.location.hash) {
// Remove any hash fragment while keeping the pathname and search parameters
history.replaceState(null, null, window.location.pathname + window.location.search);
}
}

// Call the function to remove the hash fragment if present
removeHashFragment();



resolve(); // resolve(); tells your ad to continue. Otherwise the ad will load indefinitely, break, and it will timeout.

Copy this process on each X (on all steps) as well as the last step CTA to ensure whenever the campaign is closed, the hashtag is removed.

โ€

๐ŸŽ‰ Publish the Campaign

Reminder you will need to publish your campaign for this to work! Once it's live, you will be able to open the campaign on the button click from your site!

Did this answer your question?