Custom Code Event Type

In Adobe Experience Platform Launch, the Custom Code event type from the Core extension is one of my favorite features. It provides a great deal of flexibility and power when you need it the most. Let’s say you’d like a rule to run when a user triple clicks on our webpage. You look through all the extensions available in Launch and notice — oh nos! — none of them provide a triple-click event type!

No problem. You could certainly write some code within your website that detects a triple-click and then triggers what’s affectionately known as a “direct call rule” using _satellite.track(). That works, but then you have Launch-related code intermingled with your website code. You could trigger a custom event from your website code and then use the Custom Event event type from the Core Extension, but you still might be adding code within your website that’s only servicing Launch. Those options are fine, but is there a better way? In many cases, yes!

While creating a rule, begin to add an event. On the edit screen, select the Core extension, and then the Custom Code event type. You should see something like this:

Custom Code Event Type

As it says, the code we provide in the editor will be run as soon as the Launch library is loaded on our webpage. All we have to do is call trigger() when we want the rule to fire. Let’s open up the editor and type some code:

Custom Code Editor

When the Launch library loads, we add an event listener to window that watches for a native click event. On a click event, there’s a detail property that is “a count of consecutive clicks that happened in a short amount of time, incremented by one.” When we see a click that is the third consecutive click in a short amount of time, we want our rule to run, so we call trigger().

Now let’s test it out. Save the rule, add it to a library, build the library, and run it on our webpage. Turn on debugging by running _satellite.setDebug(true); and then click the page three times fast.

Test Page

It worked! The possibilities are endless. Think your logic would be useful to others? You’re well on your way to building an extension.