Javascript API

The Sovrn Commerce JavaScript library automatically integrates into your site to monetize clicks on existing links, insert relevant product links when appropriate, and more. Even so, sometimes it makes sense to integrate with Commerce JavaScript explicitly.

Wherever the Commerce JavaScript library is installed, this simple JavaScript API is available for use.

vglnk.open( URL[, target] )

Redirect to URL in the target window or frame, monetizing the URL before redirection.

This method behaves very much like the native window.open(), but with Commerce Convert monetization built in. One behavioral difference to note is that, with vglnk.open(), target defaults to _self, not _blank.

Calls to vglnk.open() are counted as “clicks” in your Commerce analytics.

When Commerce is disabled by configuration, vglnk.open() redirects without monetization.

Parameters

URL
required; string; format: URL

target
Any valid target can be used: a window or frame name, or a special target like _blank, _top, etc.

optional; string; default: _self

Example

// send the user to example.com, monetized, in the current window
vglnk.open( "http://example.com" );

// do the same, but in a new window
vglnk.open( "http://example.com", "_blank" );

vglnk.link( link )

Ensure that Commerce will attempt to monetize link when it is clicked.

Commerce Convert automatically monetizes any link on the current page, regardless of when the link is added. In rare circumstances though, it may be necessary to manually notify Commerce about a specific link.

When Commerce is disabled by configuration, vglnk.link() does nothing.

Parameters

link
required; HTMLAnchorElement or HTMLAreaElement

Example

var iframe = createDynamicIframe(); // defined somewhere else

monetizeIframe( iframe );

function monetizeIframe( iframe ) {
  var i, ii, iframe_links = iframe.contentDocument.links;

  // ensure the VigLink JavaScript knows about each of the iframe's links
  for( i = 0, ii = links.length; i < ii; i++ ) {
    vglnk.link( links[i] );
  }
}

Did this page help you?