Are there plans to add some kind of support for the DataLayer functionality of Google Tag Manager? If there was a way to specify this via GUI then we could pass the same data to Google Analytics as custom variables or custom dimensions/metrics. This type of functionality would let us use this module asa full replacement for the google_analytics module without losing functionality.

At the very least, it would be good if this module provided an API for specifying DataLayer data. Any module can do it manually, but if this module handled the processing/rendering into JS, it would keeps things centralized and clean.

Comments

Anonymous’s picture

Hi,

there is dataLayer module: https://www.drupal.org/project/datalayer

Regards,

rwohleb’s picture

It's very strange that they would implement an entire module for the DataLayer stuff, but leave implementation of GTM to the user. Based on the creation date of the datalayer module, and the lack of any mention for the google_tag module, it really seems like they failed to see if any GTM related module already existed. In any case, the maintainers of both modules need to have a chat to make sure everything is compatible, and cross-links would be good.

rwohleb’s picture

doublejosh’s picture

Hello @rwohleb. I created the Data Layer module :)

Was just coming here to make sure the cross linking happened. Added to my side. Seems like most folks using this GTM module would want to employ that eventually.

My interest in the dataLayer was actually as a meta data standard for anonymous user profiling via localStorage via my Groucho library. This is implemented in Drupal via the 2.0 branch of my Semi Anonymous module.

Kinda nice to decouple meta data rendering from snippet inclusion, but certainly could live together.

@solotandem Would appreciate a cross link if you so choose.

Thanks.

solotandem’s picture

It was my intention to add support for the data layer to this module; it simply was not a client requirement for first release. I will need to consider how the Data Layer module fits into this.

achton’s picture

I have attempted to go the way of GoogleTagManager + Data Layer modules to implement support for GTM and at the same time expose standard stuff about the site in the DataLayer variable.

I was originally going to submit a patch which simply adds info like user roles, entity type, attached terms, etc. to the DataLayer. However, I like the idea of letting an existing module provide this feature, and this seems to be more or less exactly what the Data Layer module provides. It even has an alter hook ready, so that other modules can add info to the DataLayer if they need to.

I have a few minor suggestions/changes I would like to see in Data Layer though, but most importantly (for me right now, since I have a deadline) is that I have trouble with the way Data Layer uses menu_get_item() to determine the entity type and how to load it. It may be that my use case (a complicated site that with lots of custom entity handling) is specific for this problem - in any case I will open an issue with Data Layer module for this bug and my other suggestions.

TL;DR: Barring a few bugs/suggestions, I think Data Layer module is a good companion for google_tag. I'm not sure any integration is even needed. Issues with the Data Layer module should go in the module's issue queue.

mvc’s picture

I agree that using the existing datalayer module makes more sense that recreating that functionality here. I have a suggestion for the advanced settings section of this module's configuration page, though. If datalayer is enabled, we could show a checkbox that uses its API to configure a GTM whitelist & blacklist, as per https://developers.google.com/tag-manager/devguide#security

Suggested default whitelist:

  • google
  • nonGooglePixels
  • nonGoogleScripts
  • nonGoogleIframes

Suggested default blacklist:

  • customScripts
  • customPixels

It could be added like this:

// Add extra datalayer information
if (module_exists('datalayer')) {
  datalayer_add(array(
    'gtm.whitelist' => array('google', 'nonGooglePixels', 'nonGoogleScripts', 'nonGoogleIframes'),
    'gtm.blacklist' => array('customScripts', 'customPixels'),
  ));
}

This is for the use case where a site manager has delegated GTM admin access to a third party, eg an SEO consulting firm. Without these security settings, that third party would be able to inject custom JS at will on any page.

If the datalayer module isn't available, a short note could be shown explaining that this functionality will become available if installed (like advanced_help does on the views UI page).

  • solotandem committed 41ee53b on 7.x-1.x
    Issue #2308667: Add settings for whitelist and blacklist classes.
    
    Add...
solotandem’s picture

Assigned: Unassigned » solotandem
Status: Active » Fixed

Patch does the following:

  • adds settings for the two sets of tag classes
  • checks for datalayer module and compares name of data layer
  • adds classes as inline JS or using datalayer api, if present and layer name is default

If datalayer module is updated to allow a different name for the layer, then can remove the restriction in this patch.

Please test latest release. Thanks.

  • solotandem committed 41ee53b on 8.x-1.x
    Issue #2308667: Add settings for whitelist and blacklist classes.
    
    Add...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

doublejosh’s picture

BTW: The Drupal 8 version of DataLayer is now in a dev status and being worked on :)