Is it possible to add an external js file based on domain name from integration ?
Lets say the domain is: example.com. When user installs my integration, I want to add a myintegration.com/examplecom.js to my magento store.
Is it possible to add an external js file based on domain name from integration ?
Lets say the domain is: example.com. When user installs my integration, I want to add a myintegration.com/examplecom.js to my magento store.
Use this in your default.xml:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<script src="http://myintegration.com/examplecom.js" src_type="url" />
</head>
</page>
I didn't try it but I think you can do this with require.
In the requirejs-config.js of your module you can do something like:
var domain = window.location.hostname,
jsPath = 'myintegration.com/' + domain.match(/(?:http?:\/\/)?(?:www\.)?(.*?)\//) + '.js';
var config = {
"paths": {
"myintegration": jsPath
}
};
(Indicative code, not tested)