If you'd like a visitor to manually trigger one of your Privy Convert campaigns by clicking a specific call-to-action (CTA), you can use an onClick JavaScript function.
Note: Custom JavaScript is outside the scope of Privy Support. The team cannot help you implement this on your site or troubleshoot issues related to its use.
Prepare the campaign
To properly trigger the campaign without conflicts:
- Navigate to Convert.
- Select the campaign you'd like to trigger.
- Navigate to the Create step of the campaign builder.
- Make sure the Tab Design setting is set to No tab.
- Navigate to the Target step of the campaign builder.
- Select the When To Show section and ensure all the Automatically Show settings are disabled.
- Save the changes and Publish the campaign.
Create and apply the function
To create the onClick JavaScript function that triggers the campaign:
- Take note of the URL displayed when viewing the campaign page and copy the number listed after /campaigns. This is the campaign's ID.
- Add the function listed below to your site's HTML to create the button. Make sure to replace "XYZ" with your campaign number, update the button text, and to style the button so that it matches your site's branding.
<button onClick="Privy('show', XYZ);">Attend Our Event</button>
See it in use
Once you add the button to your content, a visitor's click will trigger the campaign: