Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: Allow customisation of script type on accept (mainly for use with Partytown) #487

Closed
spacedawwwg opened this issue Mar 16, 2023 · 5 comments
Labels
enhancement New feature or request
Milestone

Comments

@spacedawwwg
Copy link

spacedawwwg commented Mar 16, 2023

curr_script.type = 'text/javascript';

It would be nice to be able to change the type to type="text/partytown" and trigger a ptupdate after consent is given

https://partytown.builder.io/partytown-scripts#dynamically-appending-scripts

Idea 💡

on a script you add data-type="text/partytown"

change line 1624 to:

// 99% of the time people will want the default
curr_script.type = curr_script.getAttribute('data-type') || 'text/javascript';

then a user can handle their own callback

//...
cc.run({
    // ...
    onAccept: function(cookie){
        window.dispatchEvent(new CustomEvent('ptupdate'));
    },
    // ...
});

What do you think?

@github-actions github-actions bot added the triage yet to be reviewed label Mar 16, 2023
@orestbida orestbida added enhancement New feature or request and removed triage yet to be reviewed labels Mar 16, 2023
@orestbida
Copy link
Owner

Hi @spacedawwwg,

this feature is already implemented in v3. However, since this is a very tiny code addition, we can also implement it in v2.

@spacedawwwg
Copy link
Author

Boom 💥

@orestbida orestbida added this to the v2.9.0 milestone Mar 16, 2023
@preetamslot
Copy link

preetamslot commented May 9, 2023

@orestbida
I tested this in 2.9.0 and 3. But it looks like only the first script is activated, other scripts get ignored. Am I doing something wrong?

If you look at the screenshot, first script is now active type="text/partytown-x". the second is still type="text/plain"

image

Thanks

@orestbida
Copy link
Owner

@spacedawwwg,

the first script in the screenshot has a src attribute, and the current implementation will wait for the onload/onerror event to fire before loading other script tags, to ensure that all script tags are loaded sequentially.

if(src){
// load script sequentially => the next script will not be loaded
// until the current's script onload event triggers
freshScript.onload = freshScript.onerror = () => {
loadScriptsHelper(scripts, ++index);
};
}

The onload/onerror event — however — is never fired due to the invalid javascript mime type: type="text/partytown-x". This also prevents all the other scripts from loading.

@orestbida
Copy link
Owner

@spacedawwwg please try this branch and let me know if that fixes it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants