Providing Global Functions in an Extension | Community
Skip to main content
Level 2
January 2, 2018
Solved

Providing Global Functions in an Extension

  • January 2, 2018
  • 3 replies
  • 4095 views

I know Extensions have shared modules where they can be shared with other extension code.  Can the same structure be used in a piece of custom javascript code deployed as an Action?

We have been developing a set of utilities (similar to what we did in DTM) that we are calling "Useful Things Adobe Should Have Cooked Into Launch" (granted, it needs a less unwieldy name!).  We can load in in custom JS and make the functions available at the window level, but if we could cook it all into an Extension it would be easier to deploy across all of our properties.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Stewart_Schilling

Have you looked at the new event type "Custom Code" that is available in the Core extension?   Seems like just the thing for your needs.

It says "The code you provide in the editor will be run as soon as the library is loaded. Inside your code, call trigger() whenever you would like the rule to fire."

3 replies

Level 2
January 2, 2018

Quick update.  I wrote an extension that has an action that will create a window-level object that has the various utility functions.  Seems to work OK (VERY limited testing) - I was able to execute commands from the console.

The only downside is you have to run the action in, say, a page load rule to make them available.  Is there a place to put code in an extension that runs regardless of whether or not an action is called?

Adobe Employee
June 11, 2021
You can just add the action code to a rules condition. This is always being executed.
Level 2
February 1, 2018

You can use a data element as well and just return a function or object as another option

// data element code

function myFunction(params){

...

}

return myFunction;

var myFunction=_satellite.getVar("dataeleement)("myvalue");

Stewart_Schilling
Community Advisor
Stewart_SchillingCommunity AdvisorAccepted solution
Community Advisor
February 27, 2018

Have you looked at the new event type "Custom Code" that is available in the Core extension?   Seems like just the thing for your needs.

It says "The code you provide in the editor will be run as soon as the library is loaded. Inside your code, call trigger() whenever you would like the rule to fire."