Implementation Guide for Commerce JavaScript
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 Sovrn Commerce JavaScript implementation method. It's a simple and effective way for you to affiliate all existing links to products and merchants on your website. Feel free to explore our Content and Blog Onboarding Guide if you need any assistance on getting started.
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, we recommend you to utilize the Create Links implementation method, described here: Create Links in Commerce. You can also check out our Social Media Onboarding Guide for additional information.
If you have a mobile app/software or have a need to programmatically build links/report on your Commerce data, the Commerce API may work better for you. Please view our Mobile and Software Application Onboarding Guide or visit the Sovrn Developer Center to learn more.
How does the JavaScript work?
The JavaScript automatically scans your page and converts your existing products/merchants plainlinks into affiliate links. However, you will only see clicks, and any corresponding revenue, from links to merchants that you are approved for within Sovrn Commerce. We recommend checking first to see if the merchants you’d like to affiliate with are approved for your campaign(s). Approved merchants will be found under the Merchants tab in the Platform.
Note: The JavaScript loads asynchronously to your page, so it will not decrease the speed of your page load.
How do I install the JavaScript?
The Commerce JavaScript code requires an API key unique to each campaign you've submitted in your Sovrn Commerce account. You'll be able to find your campaign-specific installation script and instructions via the Settings page when you click on the “< >” icon next to your campaign.
Alternatively, you can follow the steps below:
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 via the Settings page by clicking on the "Key" icon next to the name of the campaign on which you're installing the Commerce JavaScript.
Insert your API key into the script below, and copy this script
<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 this script into the HTML of your site
This code should be inserted just before the </body>
tag.
Tip: The Commerce JavaScript can also be installed via AMP, Google Tag Manager, phpBB, tumblr, TypePad, vBulletin, Wordpress, Wix, and xenForo. You can find specific installation instructions for these integrations in this article: Other Installations for Commerce.
How can I check that the JavaScript is successfully installed?
There are a few different ways to check if you have installed the Sovrn Commerce JavaScript properly to ensure that the script will function. You can use the following methods:
“Check your installation” tool
A convenient way to check if you have installed the Commerce JavaScript correctly on your page would be to use the “Check your installation” tool.
Go to the Settings page in the Platform.
Click on the “< >” icon next to your campaign name.
There will be a “Check your installation” section beneath the campaign-specific installation JavaScript.
In the Site URL section, input the page URL where you have installed the Commerce JavaScript. The tool will inform you if the script was installed correctly, or else it will denote an error message. Here are some sample error messages you may see:
Error Message | Resolution |
---|---|
Code installed correctly. | Congrats, you’ve installed the JavaScript properly! |
Please code move to end of body. | The JavaScript was inserted in the improper location within the HTML. Please make sure the JavaScript code is inserted just before the |
Code was not found on page. | There was not a JavaScript code found on the inputted page URL, or you may be using the “Check your installation” tool on the wrong campaign. Please make sure you are inputting the proper page URL. |
Code found with incorrect key. Please use the code above with key: [insert key here]. | The JavaScript code was not inserted with the proper API key. Review to make sure the proper API key for the proper site is used, and/or double check for any typos or extra characters. |
Inspect your webpage
Another way to check if you have installed the Commerce JavaScript correctly on your page is to utilize the Inspect tool.
Open up the Inspect tool by right-clicking anywhere on your page and click on Inspect. This will bring up an Inspection view on the right side of your screen.
Navigate to the Network tab at the top.
In the Filter field, search up “vglnk” and reload your webpage. If you see the
vglnk.js
script called to your page, then the Commerce JavaScript is installed correctly.Additionally, in the Filter field, you can search up “domains” and reload your webpage. This will show which merchant domains the Commerce JavaScript is finding on the page.
Click on the
domains
response to see the list of merchant domains.
Note: If you visit the Console tab at the top, you may notice the following error message:
Refused to execute script from 'https://api.viglink.com/api/sync.js?key=[sample-api-key-here]' because its MIME type ('image/gif') is not executable.
This error message may be ignored, as it does not impact the functionality of the Sovrn Commerce JavaScript.
Check an individual link
You can also check the Commerce JavaScript installation on a given page by examining an individual hyperlink.
Hover your mouse over a hyperlink on your page.
Right click on that hyperlink and click on Copy Link Address.
Paste the link address into the address bar of your browser. It should read:
https://redirect.viglink.com...
This indicates that Sovrn Commerce JavaScript is dressing the hyperlink in our redirect, which confirms that the JavaScript is functioning properly.
I still need help.
Questions? We are here to support you, contact Sovrn Support.