Organic JavaScript SDK (Code Snippet)
The Organic JavaScript SDK is a small code snippet that must be installed on your website in order to use Organic Ads or Organic Affiliate.
Installation
There are two methods for installing the code snippet:
Install automatically (WordPress only)
Install and configure the Organic WordPress plugin and you're done!
Install manually
If you aren't using WordPress, use the instructions below to manually install the code snippet:
-
Choose the appropriate code snippet below.
-
In the snippet, replace each instance of
YOUR_SITE_ID
with your Site ID from the Access Control settings page in the Organic dashboard.infoCan't access the Access Control Settings page? Ask your Organic site admin to grant it to you.
-
If you have a USP cookie, replace
YOUR_USP_COOKIE_NAME
with your actual USP cookie name. -
Insert the code snippet before your site's closing
</head>
or</body>
tag.
Choose a code snippet:
If you are not using Organic Ads, use the following code snippet:
<!-- Start Organic Snippet -->
<script>
window.organic = window.organic || {};
window.__organic_usp_cookie = 'YOUR_USP_COOKIE_NAME'; // update this to your USP cookie name
window.loadOrganicCSS =
window.loadOrganicCSS ||
function (id, src) {
if (document.getElementById(id)) return;
var link = document.createElement('link');
link.id = id;
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = src;
document.getElementsByTagName('head')[0].appendChild(link);
};
window.loadOrganicScript =
window.loadOrganicScript ||
function (id, src, moduleSrc) {
if (document.getElementById(id)) return;
var script = document.createElement('script');
script.id = id;
script.async = true;
var useModules = typeof script.noModule === 'boolean' && moduleSrc;
if (useModules) {
// If js-module provided and browser supports it
script.type = 'module';
script.src = moduleSrc;
} else {
// Using regular script
script.src = src;
}
document.getElementsByTagName('head')[0].appendChild(script);
};
window.loadOrganicCSS(
'organic-css',
'https://api.organiccdn.io/sdk/customcss/YOUR_SITE_ID',
);
window.loadOrganicScript(
'organic-sdk',
'https://organiccdn.io/assets/sdk/sdkv2?guid=YOUR_SITE_ID',
'https://organiccdn.io/assets/sdk/sdkv2?guid=YOUR_SITE_ID&usemodules=true',
);
</script>
<!-- End Organic Snippet -->
If you are using Organic Ads, use the following code snippet:
<!-- Start Organic Snippet -->
<script>
window.organic = window.organic || {};
window.__organic_usp_cookie = 'YOUR_USP_COOKIE_NAME'; // update this to your USP cookie name
window.loadOrganicCSS =
window.loadOrganicCSS ||
function (id, src) {
if (document.getElementById(id)) return;
var link = document.createElement('link');
link.id = id;
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = src;
document.getElementsByTagName('head')[0].appendChild(link);
};
window.loadOrganicScript =
window.loadOrganicScript ||
function (id, src, moduleSrc) {
if (document.getElementById(id)) return;
var script = document.createElement('script');
script.id = id;
script.async = true;
var useModules = typeof script.noModule === 'boolean' && moduleSrc;
if (useModules) {
// If js-module provided and browser supports it
script.type = 'module';
script.src = moduleSrc;
} else {
// Using regular script
script.src = src;
}
document.getElementsByTagName('head')[0].appendChild(script);
};
window.loadOrganicCSS(
'organic-css',
'https://api.organiccdn.io/sdk/customcss/YOUR_SITE_ID',
);
window.loadOrganicScript(
'gpt',
'https://securepubads.g.doubleclick.net/tag/js/gpt.js',
);
window.loadOrganicScript(
'organic-prebid',
'https://organiccdn.io/assets/sdk/prebid-stable.js',
'https://organiccdn.io/assets/sdk/prebid-stable.m.js',
);
window.loadOrganicScript(
'organic-sdk',
'https://organiccdn.io/assets/sdk/sdkv2?guid=YOUR_SITE_ID',
'https://organiccdn.io/assets/sdk/sdkv2?guid=YOUR_SITE_ID&usemodules=true',
);
</script>
<!-- End Organic Snippet -->
See this page for additional Organic Ads configuration options.