Custom Prebuilt Goals

Introduction

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.

Below is the process of how to do it.

Create a JS Goal

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:

Sample JS 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 JS Codes

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;
   }
};

Add Code in Global Project/Experience JS

Then include code on your website pages, by adding to the "Global Project JS" area on your "Project Settings" (you can also use the Global Experience JS section accessible from the Visual Editor):

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