Custom Javascript on every page

As you can find out here, you can have custom javascript to load on every page.

Because almost every site is unique, or the theme of your CMS is a bit different, you might need to do small adjustments, without a developer to make changes to the site.

Here is a good approach with a custom SDK method to add the script when page is ready:

object.tasks.addReadyListener(function() {
   // write your code here
   ...
});

Example to push the cartValue value in a variable.

(note that CSS selectors in the code below are just an example, and you will need to change those)

object.tasks.addReadyListener(function() {
   window._vteq.push(["setVar", "cartValue", jQuery('#cart.cartValue').text()]);
});

Example for checkAndSubscribe method to subscribe user on a page, validating first the subscription checkbox.

object.tasks.addReadyListener(function() {
    jQuery('#wpmc-next').on('click', function(){
	object.Helpers.checkAndSubscribe('#billing_email', '#mc_newsletter', true);
	});
}, 'runjs');

Related Articles