Custom Prebuilt Goals

It is possible within Convert to create a custom goal and make it available to you and your collaborators at any time for adding it to your experiments.

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

Here is the process of how to do it:

First, create a JS Goal. Name it “Scroll to Bottom” and save it.

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

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");

     }
};

 Let's integrate the JS 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;

   }
};


Then include code on your website pages, by adding to the "Global Project JS" area on your "Project Settings":

Then your “Scroll to Bottom” goal will be available for all your experiments.

Important

keywords: javascript goal custom

Have more questions? Submit a request

Comments