Custom Prebuilt Goals

THIS ARTICLE WILL HELP YOU:


Introduction

It is possible within Convert to create a custom goal and make it available to you and your collaborators for use in your experiments.

In this article, we will create a goal that is triggered when somebody scrolls to the bottom of the page.

Below is the process of how to do it:

Create a JavaScript Goal

First, create a JavaScript Goal. Name it "Scroll to Bottom” and save it.

Re-edit the goal, and you will find the code to trigger it has been created within the goal. For example:

Sample JavaScript Code for an Action

Following is the code that issues an alert when the user scrolls down a web page.


var scrollgoal_triggered;
window.onscroll = function(ev) {
if ((window.innerHeight + window.scrollY) >= document.body).offsetHeight) {
alert("you're at the bottom of the page");
}
};

Integrate JavaScript Code

Let's integrate the JavaScript goal code into our scroll to bottom alert code.


var scrollgoal_triggered;
window.onscroll = function(ev) {
if ((window.innerHeight + window.scrollY) >= document.body).offsetHeight) && (scrollgoal_triggered = false) {
window._conv_q = window._conv_q || [];
_conv_q.push(["triggerConversion","100122012"]);
scrollgoal_triggered = true;
}
};

Add Code in Global Project/Global Experience JavaScript

Include code on your website pages by adding it to the "Global Project JavaScript" area in your "Project Configuration" (you can also use the Global Experience JavaScript section accessible from the Visual Editor):


Your "Scroll to Bottom" goal will then be available for all your experiments.

 

Make sure you include the tracking code on the page where you want to trigger a goal with JavaScript. Otherwise, the code won't run.

 

 

keywords: JavaScript goal custom