I have a 3rd party script that runs on initial load and creates a div element on the page.
when I navigate away this element disappears. I cant figure out how to make this work.
-
I assume
data-turbo-permanent
isnt suitable in this case, because it’s not rendered by server but by 3rd party js. couldn’t make it work. -
tried with
addEventListener("turbo:before-render", (event) => {
event.detail.render = (currentElement, newElement) => {
const rowndNav = currentElement.querySelector('#rownd-privacy-hub')
newElement.appendChild(rowndNav)
}
})
but it does nothing.
what can I do?
it’s rails 7 with Turbo 8.
in my application.html I have
= javascript_include_tag "rph", "data-turbo-track": "reload", type: "module"
and my rpj.js file is
(function () {
var _rphConfig = (window._rphConfig = window._rphConfig || []);
let baseUrl = window.localStorage.getItem('rph_base_url_override') || 'https://hub.rownd.io';
_rphConfig.push(['setBaseUrl', baseUrl]);
var d = document,
g = d.createElement('script'),
m = d.createElement('script')
g.noModule = true;
g.async = true;
g.src = baseUrl + '/static/scripts/rph.js';
m.type = 'module';
m.async = true;
m.src = baseUrl + '/static/scripts/rph.mjs';
d.body.appendChild(g);
d.body.appendChild(m);
})();
_rphConfig.push(['setAppKey', document.body.dataset.appKey]);
_rphConfig.push(['setPostAuthenticationApi', {
method: 'post',
url: '/api/auth/rownd/authenticate'
}]);
_rphConfig.push(['setPostSignOutApi', {
method: 'POST',
url: '/api/auth/rownd/sign_out'
}]);
_rphConfig.push(['setPostUserDataUpdateApi', {
method: 'POST',
url: '/api/auth/rownd/update_data'
}])