call to replace anchor tags contains '/admin' in href

Startup Scripts

Startup scripts contain logic to add behaviour to storefronts. Startup scripts make it possible to add behaviours that are standard across different themes. Following are some of the few examples:

  • Add some conditions before a product is added to cart
  • Execute javascript tag on the switch to a specific page.
  • Execute some logic before the page is rendered. 
  • Redirect to another page on specific conditions.

Third party apps use startup controllers to capture events and perform tasks on those events. 

StoreHippo uses Single Page Architecture so startup scripts are executed only once. Once loaded, when a user switches pages, then scripts are not executed. If you want to write code for the specific page then you need to handle that through page events.

Go to Site > Startup Controllers section in StoreHippo Admin Panel to manage startup scripts. 

To add a new startup script, click on Add New button in the top right corner.


Enter the name of the startup script.


Provide your startup script in this field. The startup script must in the given format:


   // Code here


StoreHippo triggers various events in different actions on your store. You can use these events and bind a handler to these events.


(eventName, callback)

Use this global function to bind to a particular event. The callback function is invoked when the event is triggered. The event object is passed to the callback function as the only argument.


ms.bind('ms.page_change_start", function(event) {

    // code here


(eventName, data)

It is used to trigger an event. data is the object containing the data that need to pass to the event handlers.


There are standard events that are triggered in default theme automatically:



Event Object

The event object contains following properties:

pageObject containing the information about the current page.
widgetObject containing the information about the widget from which the event originated.
elementObject that triggered the event.
dataData passed at the time of triggering of the event.

Standard Events 

ms.page_change_startTriggered when page change is started. call event.stopPropagation to prevent it to happen.
ms.page_not_foundTriggered when a page is not found.
ms.messageTriggered automatically whenever API response contains messages. It can be triggered manually to display messages to customers.
Triggered when the transaction for the order failed. Data contains cart and transaction objects. 
ms.cart.order_successTriggered when the order is successfully created. Data contains the order object. 


  1. To prevent the state change on particular URL ("/page/test")
    ms.bind("ms.page_change_start", function (event) {
         if ( && &&"/page/test") > -1) {

  2. To add a script on a particular page
    ms.bind("ms.page_change_start", function (event) {
         if ( && &&"/checkout") > -1) {
          // append script in head here
             var s = document.createElement("script");
             s.type = "text/javascript";
             s.src = "";

  3. Custom code when a user goes to the Product Page
    ms.bind("ms.page_change_start", function (event) {
        if ( && &&"/product") > -1) {
            var productInterval = setInterval(function () {
                //check if the product object is resolved or not and available for use
                if ( &&["ms.product"]) {
                    var product =["ms.product"].product;
                    if (product && {
                        //run your custom code with the product object
            }, 1000)

  4. How to restrict pages if user is not login.
    ms.bind('ms.page_change_start', function(event) {
        //condition if user is not loggedin.
          if(!ms.user || !ms.user.isLoggedIn){
             //specify on which location you want to redirect


StoreHipp provides the REST API. You can call the StoreHippo API in frontend theme using ms.api.


Example: To list products{command : "list", entity : "ms.products"}, function(err, response){

        // handle error
    } else {
        console.log("Response ", response);


Besides events, you can also use frontend API hooks to intercept the request and response of API hooks.


Example: Restrict user to enter at least 5 items of any product

ms.api.addPrehook({entity: 'ms.carts', command: 'addItem'}, function(req, res, next) {
   if(ms.cart.item.quantity < 5) {
    // show a message to your user
    ms.trigger('ms.message', {msg: 'min_quantity_required', data: {quantity:
    ms.cart.item.quantity}, level: 'error'});


  Example: Calculate the total weight of the cart items

ms.api.addPosthook({entity: 'ms.carts', command: 'addItem'}, function(req, res, next) {
     if( && {
 = 0;
    += item.weight;

Example: triggring izooto data with Custom code for  when a product is added to cart

ms.api.addPosthook({entity: "ms.carts", command: "addItem"}, function (req, res, next) {
    var addedItem  =;

    window._izq.push(["event","Buy Now",{
        "Product Name",


Example: Custom code when a user is logged out

ms.api.addPosthook({entity: "ms.users", command: "logout"}, function (req, res, next) {

    //put your custom code here or call your API

Example: GTM Add item when product is added to cart

app.addPosthook({entity: "ms.carts", command: "addItem"}, function (req, res, next) {
    var product =;
        'event': 'addToCart',
        'ecommerce': {
            'add': {
                'products': [
                        'id': product._id,
                        'price': product.price,
                        'brand': product.brand,
                        'category': product.categories,
                        'variant': product.variant_id,
                        'quantity': product.quantity

NOTE: The next() call need to be there to pass control to the next code in line.