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

Support consent management tools #78

Closed
dahaupt opened this issue Jul 23, 2020 · 10 comments
Closed

Support consent management tools #78

dahaupt opened this issue Jul 23, 2020 · 10 comments
Assignees

Comments

@dahaupt
Copy link

dahaupt commented Jul 23, 2020

Cookie consent tools often have the requirement to add specific data-attributes (e.g. data-src and data-name) in order to load scripts only when consent is given.

Currently it seems necessary to override MapController->initializeAction and ScriptViewHelper->render to correctly include the scripts with necessary data-attributes (using PageRenderer->addFooterData).

Another current challenge is to include the scripts in the correct order. Would be awesome to ease this afford and allow easy integration into third-party consent management tools.

@mhirdes
Copy link
Owner

mhirdes commented Oct 2, 2020

Hi, you can use the TypoScript Setting plugin.tx_gomapsext.preview.enabled = 1. So the Api is not included directly. Then override the partial Resources/Private/Partials/Preview.html. Otherwise how would a good solution for you look like? You can also write on slack.

@mhirdes mhirdes assigned mhirdes and dahaupt and unassigned mhirdes Oct 2, 2020
@dahaupt
Copy link
Author

dahaupt commented Oct 4, 2020

Hey @mhirdes, thanks for your feedback!

I am aware of the preview functionality, but IMO the extension (or extensions in general) should not each include an individual opt-in mechanism as this should be primarily the task of a cookie consent tool. If each extension handles this on its own, configuration for those consent tools is more complex than it should be.


In my world, a cookie consent tool:

  • stores the necessary cookie to decide if a service (in this case Google Maps) is accepted
  • evaluates the state of a service and triggers the loading of scripts or necessary methods
  • shows an opt-in-banner in case consent was not given (including option to accept once or permanently)

Basically each functionality described above is more or less already integrated into the extension. In general, I would recommend to remove the functionality and refer to the use of a cookie consent tool. However, this simple preview might be sufficient for many smaller projects without many cookies and services.


In order to make the integration for cookie consent tools easier, I would propose to:

  • Add a new TypoScript constant: plugin.tx_gomapsext.settings.enableOptInMode:
    • This mode changes all scripts to <script data-src="{src}" data-name="{serviceName}" type="text/plain"></script> so they are not loaded anymore at all.
    • This constant could be set automatically by cookie consent extensions, which "officially" support this extension.
    • Using this mode, the initialization of the map must be triggered manually (e.g. by cookie consent tool).
  • Add a method to initialize a map (e.g. by providing the id of the element "#gme-1"). This method could alternatively also fetch all necessary scripts instead of adding data attributes. This method should be as simple as possible and will be called by the consent tool.

Looking forward to your feedback! (Slack: dahaupt)

@mhirdes
Copy link
Owner

mhirdes commented May 10, 2021

Hi @dahaupt,

sry for the late response. I checked again the current preview mode. To overwrite the partial and take a look at the jquery.gomapsext.preview.js it's a good example how to initialize the map. Of course costumization is needed.

But I wrote you an slack today. May we can write there to find a good solution.

@deadmanIsARabbit
Copy link

May I ask if you two have found a solution in your Slack discussion?

@dahaupt
Copy link
Author

dahaupt commented Jul 9, 2021

@deadmanIsARabbit Unfortunately, I have not responded back to @mhirdes, yet. Will try to find the time to look into this topic again!

@bardimardy
Copy link

bardimardy commented Oct 27, 2021

Hey @mhirdes and @dahaupt, I got the same question as @deadmanIsARabbit, ran into the same issue some days ago and it would be great to see a solution coming. Until this will happen I have to find a workaround for this issue.

Currently this appears in combination with the cookieman extension.

@bardimardy
Copy link

bardimardy commented Nov 4, 2021

If somebody got the same issue, I want to quickly describe a workaround for you to get GoMapsExt working in preview mode running together with a cookie consent tool. In my case it was Cookieman.

  • You need to overwrite the ScriptViewHelper, because you need to change the following things for the script tag generation. (Done it via registration of an XClass)

    • src attribute should be changed to data-src
    • type="text/javascript" to type="text/plain"
    • Add data-name attribute with the value "googleMapCE"

    Dahaupt's solution looks like this:

    $tempJavaScriptFile = GeneralUtility::writeJavaScriptContentToTemporaryFile($this->renderChildren());
       GeneralUtility::makeInstance(PageRenderer::class)
        ->addFooterData('<script data-src="' . $tempJavaScriptFile . '" type="text/plain" data-name="googleMapCE"></script>');
    
  • Enable the include_google_api_manually setting, because it will get injected later through showMap() function inside jquery.gomapsext.preview.js
    (showMap() will be called when you click the preview link)

  • Inject the following JS snipped when consent, it will load the GoMapsExt scripts and you're ready to go!

<script>
const $element = $('.tx-go-maps-ext');
if ($element) {
    $.when($.getScript('/typo3conf/ext/go_maps_ext/Resources/Public/Scripts/markerclusterer_compiled.js'),
           $.getScript('/typo3conf/ext/go_maps_ext/Resources/Public/Scripts/jquery.gomapsext.js'),
        $.Deferred(function (deferred) {
            $(deferred.resolve);
        })).done(function () {
        $('script[data-name="googleMapCE"]').each(function () {
            $.getScript($(this).data('src'));
        });
    });
}
</script>

Now your preview link will show the maps after clicked.

@ProWebs
Copy link

ProWebs commented Jan 23, 2023

  • ScriptViewHelper

Can you descripe it more detailed, were can i find the "ScriptViewHelper" on filesystem and how to override it? Copy code on a special place in this file? Or is there another way, to keep cookieman ready for future updates without override you workaround.

@mhirdes
Copy link
Owner

mhirdes commented Feb 17, 2023

You don't need to overwrite the script ViewHelper. The tempJavaScriptFile dosen't load any external function.

You can set in the extension manager config, that you load the JS by your own, if the preview function as it self works not for you.

@mhirdes
Copy link
Owner

mhirdes commented Feb 17, 2023

If any other help is needed for this topic, please contact me on slack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants