{"_id":"56f469393d86a90e009b2fae","version":{"_id":"568af725176a6c0d00a29ec7","project":"568af724176a6c0d00a29ec4","__v":11,"createdAt":"2016-01-04T22:50:13.289Z","releaseDate":"2016-01-04T22:50:13.289Z","categories":["568af725176a6c0d00a29ec8","56d9d397337fd11300d6a3e3","56d9d4287222d50b0070160b","56f424307ea0091700f63ac5","56f45babcb0dce29005a8e85","5739e5836c5ba134007a197d","57717aee3dd24019004c9122","5771b5d8c755ca0e00617d7d","579639964913990e001a5911","57e57e7df3d7fc0e009c5119","587569b6f4483a0f00d2e6b8"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"parentDoc":null,"user":"568af6d197d8960d0012ab7d","project":"568af724176a6c0d00a29ec4","category":{"_id":"56f45babcb0dce29005a8e85","__v":0,"version":"568af725176a6c0d00a29ec7","project":"568af724176a6c0d00a29ec4","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-03-24T21:27:07.645Z","from_sync":false,"order":7,"slug":"advanced-use-configuration","title":"Advanced Use & Configuration"},"__v":3,"updates":["59ffebc9adc119001ae43615"],"next":{"pages":[],"description":""},"createdAt":"2016-03-24T22:24:57.118Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"The VigLink 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 VigLink JavaScript explicitly.\n\nWherever the VigLink JavaScript library is installed, this simple JavaScript API is available for use.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"vglnk.open( URL[, target] )\"\n}\n[/block]\nRedirect to URL in the target window or frame, monetizing the URL before redirection.\n\nThis method behaves very much like the native window.open(), but with VigLink Convert monetization built in. One behavioral difference to note is that, with vglnk.open(), target defaults to _self, not _blank.\n\nCalls to vglnk.open() are counted as “clicks” in your VigLink analytics.\n\nWhen VigLink is disabled by configuration, vglnk.open() redirects without monetization.\n\n##**Parameters**\n**URL**\nrequired; string; format: URL\n\n**target**\nAny valid target can be used: a window or frame name, or a special target like _blank, _top, etc.\n\noptional; string; default: _self\n\n##**Example**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// send the user to example.com, monetized, in the current window\\nvglnk.open( \\\"http://example.com\\\" );\\n\\n// do the same, but in a new window\\nvglnk.open( \\\"http://example.com\\\", \\\"_blank\\\" );\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"vglnk.link( link )\"\n}\n[/block]\nEnsure that VigLink will attempt to monetize link when it is clicked.\n\nVigLink 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 VigLink about a specific link.\n\nWhen VigLink is disabled by configuration, vglnk.link() does nothing.\n\n##**Parameters**\nlink\nrequired; HTMLAnchorElement or HTMLAreaElement\n\n##**Example**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var iframe = createDynamicIframe(); // defined somewhere else\\n\\nmonetizeIframe( iframe );\\n\\nfunction monetizeIframe( iframe ) {\\n  var i, ii, iframe_links = iframe.contentDocument.links;\\n\\n  // ensure the VigLink JavaScript knows about each of the iframe's links\\n  for( i = 0, ii = links.length; i < ii; i++ ) {\\n    vglnk.link( links[i] );\\n  }\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"javascript-api","type":"basic","title":"Javascript API"}
The VigLink 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 VigLink JavaScript explicitly. Wherever the VigLink JavaScript library is installed, this simple JavaScript API is available for use. [block:api-header] { "type": "basic", "title": "vglnk.open( URL[, target] )" } [/block] 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 VigLink 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 VigLink analytics. When VigLink 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** [block:code] { "codes": [ { "code": "// send the user to example.com, monetized, in the current window\nvglnk.open( \"http://example.com\" );\n\n// do the same, but in a new window\nvglnk.open( \"http://example.com\", \"_blank\" );", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "vglnk.link( link )" } [/block] Ensure that VigLink will attempt to monetize link when it is clicked. VigLink 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 VigLink about a specific link. When VigLink is disabled by configuration, vglnk.link() does nothing. ##**Parameters** link required; HTMLAnchorElement or HTMLAreaElement ##**Example** [block:code] { "codes": [ { "code": "var iframe = createDynamicIframe(); // defined somewhere else\n\nmonetizeIframe( iframe );\n\nfunction monetizeIframe( iframe ) {\n var i, ii, iframe_links = iframe.contentDocument.links;\n\n // ensure the VigLink JavaScript knows about each of the iframe's links\n for( i = 0, ii = links.length; i < ii; i++ ) {\n vglnk.link( links[i] );\n }\n}", "language": "javascript" } ] } [/block]