NewsMAN API Documentation
en ro

Remarketing Javascript API for developers

Loading the Newsman Remarketing code

Copy the Javascript code below on each page in the site, before the </body> tag.
Each list has a different remarketing code!

Codul de mai jos este unul general, cu valori de exemplu (cele evidențiate). Valorile listei tale le găsești în contul NewsMAN, la Setări > Remarketing.

cod general
<script type="text/javascript">
    var _nzm = _nzm || [];
    var _nzm_config = _nzm_config || [];
    (function(w, d, e, f, c, l, n) {
        ["identify", "track", "run"].map(function(m) {
            w[f][m] = function() {
                w[f].push([m].concat([].slice.call(arguments)));
            };
        });
        l = d.createElement(e);
        l.async = 1;
        l.src = (w[c].js_prefix || "https://t.newsmanapp.com") + "/jt/t.js";
        l.setAttribute("data-site-id", "SITE_ID-LIST_ID-FORM_ID-CONTROL_HASH");
        n = d.getElementsByTagName(e)[0];
        n.parentNode.insertBefore(l, n);
    })(window, document, "script", "_nzm", "_nzm_config");
</script>

Do you use one of the ecommerce platforms below? Install the corresponding plugin and the JavaScript code will be inserted automatically. In addition, ecommerce actions are already implemented and can be tracked and used in automations.

NewsMAN Remarketing ID-ul listei tale, împreună cu restul opțiunilor - dezactivare tracking, consent mode, conversii email, Javascript propriu - le găsești în interfața de administrare NewsMAN, la Setări > Remarketing.

Javascript API

The methods below are available on any page that loads the Remarketing code above.

Disabling tracking for a site

_nzm_config['no_tracking'] = 1;

Disabling tracking for a user/browser

_nzm.setTracking(0);

Sets a cookie of the form _nzm_tr_10200-1 with the value 0. It can be called from the logic of a "cookie banner".

Enabling tracking for a user/browser

_nzm.setTracking(1);

Deletes the cookie of the form _nzm_tr_10200-1. It can be called from the logic of a "cookie banner".

Identifying a user/customer

_nzm.identify( { email: 'ion@company.com', first_name: 'John', last_name: 'Doe' } );

or

_nzm.identify( { email: 'ion@company.com'} );

This usually happens after a user logs in to your application.

For special cases, you have to specify the email field whose value is used for autoidentify. The code goes into the Newsman administration interface, under "Settings" > "Remarketing". You can specify either the selector alone, or the selector and the page on which the selector should be looked up.

_nzm_config['autoidentify'].push({'url_containing': '/contul-meu', 'email_selector': '#ctl10_UserName'});
_nzm_config['autoidentify'].push({'url_containing': '/cosul-meu/comanda-rapida', 'email_selector': '#ctl10_tbEmail'});
_nzm_config['autoidentify'].push({'email_selector': '#ctl10_UserName'});
_nzm_config['autoidentify'].push({'email_selector': '#ctl10_tbEmail'});

Enabling tracking for non identified users

_nzm_config['enable_nonidentified'] = 1;

Enabling newsletter subscription on the register and checkout pages of a site, when a checkbox is ticked

_nzm_config['subscribe_checkbox'].push({'url_containing': '/contul-meu', 'checkbox_selector': '#opt-in-newsletter'});
_nzm_config['subscribe_checkbox'].push({'url_containing': '/cosul-meu/comanda-rapida', 'checkbox_selector': '#opt-in-newsletter-2'});

or

_nzm_config['subscribe_checkbox'].push({'checkbox_selector': '#opt-in-newsletter'});
_nzm_config['subscribe_checkbox'].push({'checkbox_selector': '#opt-in-newsletter-2'});

Checking whether a user/customer has been identified

_nzm.get_tracking_id();

Setting a custom variable for a Newsman subscriber

_nzm.run( 'user:setProp', { 'skill': 3000 } );

Tracking a custom event, with or without a callback

function my_callback(param) {
    console.log("This is a callback");
}
_nzm.track('good_luck', { luck_level: 10 }, 'my_callback');
_nzm.track('good_luck', { luck_level: 10 });

Opening / closing a subscription modal (if there is one)

_nzm.run('modal:show');
_nzm.run('modal:hide');

The modal can also be displayed embedded in a DOM node on demand: <div class="show-here-class">modal</div>

_nzm.run('modal:show', '.show-here-class');

<div id="show-here-id">modal</div>

_nzm.run('modal:show', '#show-here-id');
_nzm.run('modal:show', '#show-here-id', 'insert');
_nzm.run('modal:show', '#show-here-id', 'append');
_nzm.run('modal:show', '#show-here-id', 'replace');
_nzm.run('modal:show', '#show-here-id', 'insert_before');
_nzm.run('modal:show', '#show-here-id', 'insert_after');

A specific modal can be displayed, by form_id:

_nzm.run('modal:show:1c2c635b96eeeb3e8ee4756vc6c889163f2', '#show-here-id', 'insert_before');

Events

_nzm.run('on:scroll.to50', function () { console.log('Scrolled to mid page') } );
_nzm.run('on:seconds-passed', function () { console.log('It passed 5 seconds after page loaded') }, 5);

The _nzm.run() method with a callback

_nzm.run( 'send', 'event', 'UX', 'click', 'add to cart', null, _nzm.createFunctionWithTimeout(function() {
    console.log('Produsul a fost pus in cos')
}));

Use this method when a redirect happens immediately after the tracking call (for example: add to cart with a redirect to the cart). If _nzm.run does not work, the callback still runs (it has a one second timeout).

Debugging

_nzm.debug();

The ecommerce module

The ecommerce module is very similar to Google's Enhanced Ecommerce. The fastest way to integrate Newsman Remarketing for ecommerce with your applications is therefore to clone your Google Enhanced Ecommerce integration, if you already have one: change the loading script and replace "ga(" with "_nzm.run(" in the code.

The following sections show how to implement and measure these activities:

Loading the ecommerce module

_nzm.run( 'require', 'ec' );

Specifying the local currency

_nzm.run( 'set', 'currencyCode', 'RON' );

Measuring a product page view

_nzm.run( 'require', 'ec');
_nzm.run( 'set', 'currencyCode', 'USD' );
_nzm.run( 'ec:addProduct', {
	'id': 'S-003',
	'name': 'Elkton Jacket',
	'category': 'Longsleeves/Men\'s Clothing/Other/Pants/T-shirts',
	'price': '249',
} );
_nzm.run( 'ec:setAction', 'detail' );
_nzm.run( 'send', 'pageview' );

Measuring product impressions on a category page

_nzm.run( 'require', 'ec' );
_nzm.run( 'set', 'currencyCode', 'EUR' );
_nzm.run( 'ec:addImpression', {
	'id': '266',
	'name': 'Spencer Cadet',
	'category': 'Climbing Equipment',
	'list': 'Product List',
	'position': '1'
} );
_nzm.run( 'ec:addImpression', {
	'id': '259',
	'name': 'E.C.O. Yoga Mat',
	'category': 'Climbing Equipment',
	'list': 'Product List',
	'position': '2'
} );
_nzm.run( 'send', 'pageview' );

Adding a product to the cart

_nzm.run( 'require', 'ec');
_nzm.run( 'set', 'currencyCode', 'RON' );
_nzm.run( 'ec:addProduct', {
	'id': '035pp',
	'name': 'Pantalonis Trouser',
	'price': '44.11',
	'brand': 'Pantalonis',
	'category': 'Trousers',
	'quantity': 1
} );
_nzm.run( 'ec:setAction', 'add' );
_nzm.run( 'send', 'event', 'UX', 'click', 'add to cart' );

Removing a product from the cart

_nzm.run( 'require', 'ec');
_nzm.run( 'set', 'currencyCode', 'RON' );
_nzm.run( 'ec:addProduct', {
	'id': '035pp',
	'quantity': '1',
} );
_nzm.run( 'ec:setAction', 'remove' );
_nzm.run( 'send', 'event', 'UX', 'click', 'remove from cart' );

Measuring purchases

_nzm.run( 'require', 'ec');
_nzm.run( 'set', 'currencyCode', 'RON' );
_nzm.run( 'ec:addProduct', {
	'id': 'T-03',
	'name': 'Spencer Cadet',
	'category': 'Climbing Equipment',
	'price': '84.00',
	'quantity': '1'
} );
_nzm.run( 'ec:setAction', 'purchase', {
	'id': '758',
	'affiliation': 'RetroMod',
	'revenue': '84.00',
	'tax': '0',
	'shipping': '4.00'
} );
_nzm.run('send', 'pageview');

The articles below are also worth reading: