JavaScript for Commerce
Sovrn provides JavaScript as an option for installing Commerce. Here you'll find a few things to consider, how to install, and how to check if your installation is successful.
Should I use JavaScript or another method of Commerce installation?
Content and Blog sites usually benefit the most from using the Commerce JavaScript option. It's a simple and effective way for you to affiliate all existing links to products and merchants on your website.
If you are using social media, or another platform where you do not have access to the source code, this option will not work for you. Instead, you'll need to use Create Links, described here: Create Links in Commerce.
If you're using a mobile app or have a need to programmatically build links or report on your Commerce data, the Commerce API may work better for you. Please see visit the Developer Center to learn more.
How do I install the JavaScript?
The JavaScript code contains an API key that is specific to each site you've submitted in your account. You'll be able to find your site specific installation script and instructions Settings page when you click on the < > icon.
Alternatively, you can follow the steps here:
Obtain your Sovrn Commerce API key. If you do not have your API key, you can ask the owner of your Sovrn Commerce account. The API key can be found on the Settings tab by clicking on the "Key" icon next to the site where you're installing Commerce.
Insert your API key into the script below, and copy this script to your clipboard (this is the Commerce JavaScript)
<script type="text/javascript">
var vglnk = {key: 'YOUR API KEY GOES HERE'};
(function(d, t) {
var s = d.createElement(t);
s.type = 'text/javascript';
s.async = true;
s.src = '//cdn.viglink.com/api/vglnk.js';
var r = d.getElementsByTagName(t)[0];
r.parentNode.insertBefore(s, r);
}(document, 'script'));
</script>
Paste the Commerce Code on your pages. This code should be inserted at the very end of your pages, just before the </body> tag.
If you are using technologies such as AMP, Google Tag Manager, phpBB, tumblr, TypePad, vBulletin, Wordpress, and xenForo. You can find specific installation instructions for these integrations in this article: Other Installations for Commerce.
How does the JavaScript work?
Installing the JavaScript will automatically scan your page and change your existing links to products or merchants into affiliate links. However, you will only see clicks and revenue from links to merchants that you are approved for within Sovrn Commerce, so you may check to see if your existing links are to merchants found in your Approved Merchants tab.
The script loads asynchronously to your page, so it will not decrease the speed of your page load.
How can I check that the JavaScript is successfully installed?
To check that the script was installed successfully you can use the following methods:
Inspect your webpage. Inspect and navigate to the "Network" tab. Search for sovrn and reload your webpage. As long as you see sovrncm.js called to your page, the script is installed correctly. You can also use the domains response to see which domains our script is finding on the page. You may see a CORS or other errors if your site has not yet been approved by our Network Quality team. See the getting started and approval process in this article: Getting Started with Sovrn Commerce.
Check an individual link. Hover over a hyperlink on a page in which you installed the script, and check that link address (appearing in the black bar in the bottom left of your browser) states https://redirect.viglink.com... instead of the product URL. This indicates that Sovrn Commerce is dressing this URL in our redirect. Right click on any hyperlink on the page and click on Copy Link Address, then paste this link into the address bar. It should again read https://redirect.viglink.com...