You are here

datalayer.api.php in dataLayer 7

Same filename and directory in other branches
  1. 8 datalayer.api.php

Documentation for the Data Layer module.

This file contains no working PHP code; it exists to provide additional documentation for doxygen as well as to document hooks in the standard Drupal manner.

File

datalayer.api.php
View source
<?php

/**
 * @file
 * Documentation for the Data Layer module.
 *
 * This file contains no working PHP code; it exists to provide additional
 * documentation for doxygen as well as to document hooks in the standard
 * Drupal manner.
 */

/**
 * @defgroup datalayer_hooks Data Layer hooks
 *
 * @{
 * Hooks that can be implemented to externally extend the Data Layer module.
 */

/**
 * Provide candidate entity properties for output to the screen.
 */
function hook_datalayer_meta() {

  // EXAMPLE:
  // Add your own entity property to output.
  return array(
    'some_property',
  );
}

/**
 * Provide candidate entity properties for specific entity types.
 */
function hook_datalayer_ENTITY_TYPE_meta() {

  // EXAMPLE:
  // Add your own entity property to output.
  return [
    'some_property',
  ];
}

/**
 * Alter the Data Layer data before it is output to the screen.
 *
 * @param array $properties
 *   Data layer properties to output on entiity pages.
 */
function hook_datalayer_meta_alter(array $properties) {

  // EXAMPLE:
  // Remove author uid if anonymous or admin.
  if ($properties['uid'] == 0 || $properties['uid'] == 1) {
    unset($properties['uid']);
  }
}

/**
 * Alter entity specific Data Layer data before it is output to the screen.
 *
 * @param array $properties
 *   Data layer properties to output on entiity pages.
 */
function hook_datalayer_ENTITY_TYPE_meta_alter(array $properties) {

  // EXAMPLE:
  // Remove author uid if anonymous or admin.
  if ($properties['uid'] == 0 || $properties['uid'] == 1) {
    unset($properties['uid']);
  }
}

/**
 * Alter the Data Layer data before it is output to the screen.
 *
 * @param array $data_layer
 *   GTM data layer data for the current page.
 */
function hook_datalayer_alter(array &$data_layer) {

  // EXAMPLE:
  // Set the "site" variable to return in lowercase.
  $data_layer['site'] = strtolower($data_layer['site']);
}

/**
 * @}
 * End hook documentation.
 */

Functions

Namesort descending Description
hook_datalayer_alter Alter the Data Layer data before it is output to the screen.
hook_datalayer_ENTITY_TYPE_meta Provide candidate entity properties for specific entity types.
hook_datalayer_ENTITY_TYPE_meta_alter Alter entity specific Data Layer data before it is output to the screen.
hook_datalayer_meta Provide candidate entity properties for output to the screen.
hook_datalayer_meta_alter Alter the Data Layer data before it is output to the screen.