Giter VIP home page Giter VIP logo

inpsyde / google-tag-manager Goto Github PK

View Code? Open in Web Editor NEW
16.0 6.0 5.0 1001 KB

Adds the Google Tag Manager container snippet to your site and populates the Google Tag Manager Data Layer.

Home Page: https://inpsyde.com/en/web-analysis-wordpress-google-tag-manager/

License: GNU General Public License v2.0

JavaScript 0.76% PHP 91.87% Gherkin 3.05% SCSS 4.32%
wordpress wordpress-plugin google-tag-manager google

google-tag-manager's People

Contributors

biont avatar bueltge avatar chrico avatar retrorism avatar sabali33 avatar szepeviktor avatar yeremi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

google-tag-manager's Issues

Add filters for additional Datalayers

Is your feature request related to a problem? Please describe.
I always thought that the plugin already made it possible to add data from custom sources to the dataLayer, but - unless I'm mistaken - this is not the case. So an integration that needs different entries to be added to the dataLayer needs to render its own script tag with dataLayer.push(['customKey','CustomValue']), where ideally, this happens in the same place.

Describe the solution you'd like
Two additional filters in the dataLayerProvider::boot method:

  • one for an array to provide the dataCollectors (array of dataCollectorInterfaces)
  • one for an array of settingsSpecs (array of settingsSpec arrays)
    like so:
public function boot(GoogleTagManager $plugin)
    {
        $dataLayer = $plugin->get('DataLayer');

        $dataCollectors = apply_filters(
            'inpsyde.google-tag-manager.datalayer-data-collectors',
            [
                $plugin->get('DataLayer.User.UserDataCollector'),
                $plugin->get('DataLayer.Site.SiteInfoDataCollector')
            ]
        );

        foreach ($dataCollectors as $dataCollector) {
            $dataLayer->addData($dataCollector);
        }

        if (! is_admin()) {
            return;
        }

        $factory = $plugin->get('ChriCo.Fields.ElementFactory');

        $settings = apply_filters(
            'inpsyde.google-tag-manager.datalayer-data-collector-settings-specs',
            [
                $plugin->get('DataLayer')->settingsSpec(),
                $plugin->get('DataLayer.User.UserDataCollector')->settingsSpec(),
                $plugin->get('DataLayer.Site.SiteInfoDataCollector')->settingsSpec(),
            ]
        );

        $settingsPage = $plugin->get('Settings.Page');
        foreach ($settings as $spec) {
            $settingsPage->addElement(
                $factory->create($spec),
                $spec['filters'] ?? [],
                $spec['validators'] ?? []
            );
        }
    }

This way, a plugin that wants to add a compatible dataCollector can do so and optionally can add their own settings to the GTM settings panel.

Describe alternatives you've considered

  • adding a filter to the datalayer script output (currently, only the attributes can be filtered): this may actually still be useful, but makes for a very hacky experience which seems unnecessary since all the interfaces to do this 'properly' are already provided by the plugin.
  • refactoring the entire plugin to use inpsyde/modularity and so that it becomes possible to extend the dataLayerProvider (or whatever would be the best approach in that scenario 😏)

Additional context
Annoyingly, my usecase requires a bunch of things that are almost provided by the default settings, just in a different format and wrapped inside an object.

Add attributes to the script tag using a filter

Is your feature request related to a problem? Please describe.
Seeing how the combination GTM + UserCentrics seems to be quite common for cookie consent, I was wondering whether it would be reasonable to add a little integration to https://github.com/inpsyde/google-tag-manager to add a data-attribute to the script tag it renders. UserCentrics’ documentation asks for the following:

<script type="text/plain" data-usercentrics="Google Analytics">
(function(i,s,o,g,r,a,m){....} etc
</script>

Describe the solution you'd like
The documentation for the wp_print_inline_script_tag() suggests to use the $attributes in combination with the wp_{inline}_script_attributes filter but since there's no context being passed, I wouldn't know how we would prevent attributes added through a filter from being added to other script tags that apply those filters.
A custom filter like inpsyde-google-tag-manager.script-attributes would give developers full control over the attributes for the GTM script tag alone, with the added benefit that something like a nonce in the script tag (#7) also becomes a possibility.

Describe alternatives you've considered

  • Rolling out a custom plugin that handles all UserCentrics_ and GTM functionality is obviously not great. I think fixing it with an attributes filter is elegant and non-intrusive.

Additional context
UserCentrics docs: https://docs.usercentrics.com/#/direct-implementation-guide?id=step-2-adjust-existing-scripts

Unwanted '>' character in the ID rendering

)( window, document, 'script', '<?= esc_js($dataLayerName); ?>', '<?= esc_js($gtmId); ?>>' );

Hi @Chrico I missed this during my tests but after deploying this on a staging environment, one of our clients pointed out that we're rendering an additional '>' which has to be due to this line. I can obviously fix it in a PR once I'm out of this meeting but maybe you're quicker 😏

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.