Adobe Launch

Creating Adobe Launch Extension : Shared Modules

On this article we will cover the sharedModules functionality.
This part is the most hidden functionality of the Launch Extension, not because it wants to stay hidden but because it is mostly not getting anything directly from the Launch product team. This functionality is only interesting if the users (developers to be exact) are sharing functions from their extensions.

What is a shared module?

The shared module functionality is a way for developers or for Extensions owner to share part of their functionalities to other extensions (or developers).
If you have developed something that you think can be useful to other developers, or you want to expose part of your Extension to other Extensions, in order to allow customization, this is the way to go.

I find this possibility very powerful but it is having a big weakness; the high dependency on documentation.

You can check the documentation of launch about it :
https://developer.adobelaunch.com/extensions/reference/shared-modules/

You will see that this article is not having a full use of this module, because we would need another Extension to use the one we are developing in our own. However, we will use shared modules from Adobe Analytics to realize it.

When you retrieve the extension shared module, you need to understand what is possible to do with it. This is an extra step on the documentation that needs to be provided by the original Extension developer. This is one of the reason it stay hidden.
I am positive on the fact that Adobe will provide some shared functionalities but overall, I feel that this powerful feature will be under-used, just because of all of the documentation that is required to have that in place. I hope I am wrong.

If you want to have a look at the shared modules of Adobe, there is a beginning of a documentation here :

https://github.com/Adobe-Marketing-Cloud/reactor-developer-docs/tree/9afdefa4364bb556b883f8d61df158734b29d6f2/extensions/shared_modules

Setting SharedModules

On the example below I will provide a sharedModule and use one in the same javascript file.
So you can see how you can access other shared modules.

I will also invoke a free turbine variables, they are listed here, or in my blog on this article. This one is the promise functionality. It ensures the compatibility with promise for old browsers.

Interesting thing to know, you don’t have to create a view for your shared modules. It is purely a JavaScript file that is in your extension.
I would recommend for you to have a documentation within your extension in order to expose your shared modules functionalities.

On my code below, I will use the Adobe Analytics module to inform that the tracker has been set and I will also pass a promise as shared module.

'use strict';
var getTracker, myPromise, sharedMod;/* because of strict mode, we have to declare the variable */
getTracker = turbine.getSharedModule('adobe-analytics', 'get-tracker') /* get the shared module from Adobe Analytics */
if (typeof getTracker != 'undefined') { /* if shared module doesn't exist, it return undefined */
    getTracker().then(function (tracker) { /** here the module is a promise (see docu) */
        turbine.logger.info('tracker has been set');
        turbine.logger.info(tracker);
    })
}
turbine.logger.info('Out of the sharedExtension');/** in order to inform that our shared module script has ran */
myPromise = require('@adobe/reactor-promise'); /* creating my shared Module function by calling the promise wrapper */
sharedMod = new myPromise(function (resolve, reject) {
    resolve('mySharedModule')
});
module.exports = { 'ags862': sharedMod };/* exporting the module, exposing it */

I hope that this article helped you to better understand what shared modules are and how to use them.

On this series, you may want to look at these articles :

ArticleContent
Introdcution to Adobe Launch & Extension Creation This posts covers the basic of what you need to know in order to start with this series of articles.
Architecture and dependencies within modules This posts covers the architectures and how the different modules are linked between each others
Global Extension Configuration This article explains how to set up your configuration HTML file. It is the core configuration module of your extension.
Event type module This article will show you how to build an event module. Every module will have a configuration part (HTML) and wrapper(JS).
Condition module
This article will show you how to build a condition module.
Action module This post will be related to the action module and how to build it. We will also see how you can actually import some cool feature of the launch library.
Data Element moduleThis article will be developing the possibilities of the Data Element module
Shared moduleThis article will focus on the shared functionality that you can write and share with other extension developpers to used. We will also used a feature shared from Adobe Analytics to show you how to use it.
Other featuresThe other features that are related to Launch Extension. I will cover additional (and important) information there.
Testing your extensionHow do I debug my Extension ?
Releasing and updating your ExtensionHow do I publish my Extension into Launch ? And after, how do you update it ?

Leave a Reply

Your email address will not be published. Required fields are marked *