PHP code example of edisonlabs / adobe_analytics

1. Go to this page and download the library: Download edisonlabs/adobe_analytics library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

edisonlabs / adobe_analytics example snippets


$config['adobe_analytics'] = [
     'mode' => 'dev/prod',
 ];


/**
 * @file
 */

/**
* Implements hook_adobe_analytics_variables().
*/
function mymodule_adobe_analytics_variables() {
  // Initialize a variables array to be returned by this hook.
  $variables = [];
  $config_var = \Drupal::config('adobe_anlaytics.settings')
                ->get('track_search_engine', 0);
  if ($config_var) {
    $variables['referring_search_engine'] = 'none';

    // Create a list of possible search engines that my site cares about.
    $search_engines = ['google.com', 'yahoo.com', 'bing.com', 'ask.com'];

    // Get the referring URL.
    $referer = $_SERVER['HTTP_REFERER'];

    // Check the URL to see if the request is coming from a search engine
    // and if it is, change the value of my "referring_search_engine" variable.
    foreach ($search_strings as $engine) {
      if (stripos($referer, $engine) !== FALSE) {
        $variables['referring_search_engine'] = $engine;
        break;
      }
    }
  }

  // Lets assume we need a variable called "date" and that for some reason it
  // *must* come before all the other variables. Note that if you have a
  // variable that must come at the end you can use "footer" as well.
  $header = ['date' => date('Ymd')];

  return ['variables' => $variables, 'header' => $header];
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mymodule_form_adobe_anlaytics_admin_settings_alter(&$form, &$form_state) {
  $form['general']['adobe_anlaytics_track_search_engine'] = [
    '#type' => 'checkbox',
    '#title' => t('Track the referring search engine for every request'),
    '#default_value' => \Drupal::config(adobe_anlaytics . settings)
                        ->get('track_search_engine', 0),
  ];
}