Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Measurement manager
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosen authored Nov 16, 2021
1 parent 1d535e1 commit 37e5e1f
Show file tree
Hide file tree
Showing 16 changed files with 305 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

strategy:
matrix:
PHP: ['7.3', '7.4']
PHP: ['7.4', '8.0']

steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "GPL-2.0-or-later",
"minimum-stability": "dev",
"require": {
"drupal/core": "^8.8|^9.0",
"drupal/core": "^8.9|^9.2",
"drupal/token": "^1.7"
},
"require-dev": {
Expand Down
6 changes: 5 additions & 1 deletion config/install/ivw_integration.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ frabo_default: 'in'
frabo_overridable: false
frabo_mobile_default: 'mo'
frabo_mobile_overridable: false
mcvd: false
debug: false
pixel_type: 'cp'
distribution_channel: 'web'
legacy_mode: false
bfe: true
25 changes: 21 additions & 4 deletions config/schema/ivw_integration.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ ivw_integration.settings:
label: 'IVW mobile site name as used in st parameter'
service_domain_name:
type: string
label: 'Domain name for anonymous INFOnline measurement. It should look similar to data-{hash}.example.com'
label: 'Domain name for anonymous Measurement Manager.'
mobile_service_domain_name:
type: string
label: 'Mobile domain name for anonymous INFOnline measurement. It should look similar to data-{hash}.example.com'
label: 'Mobile domain name for anonymous Measurement Manager.'
code_template:
type: string
label: 'IVW code template'
Expand Down Expand Up @@ -127,6 +127,23 @@ ivw_integration.settings:
frabo_mobile_overridable:
type: boolean
label: 'Frabo control for mobile is overridable'
mcvd:
debug:
type: boolean
label: 'Activate Multistage Client & Visit Detection (MCVD)'
label: 'Activate debugging'
pixel_type:
type: string
label: 'The pixel type'
distribution_channel:
type: string
label: 'The distribution type'
legacy_mode:
type: boolean
label: 'Display legacy code additionally to measurement manager'
bfe:
type: boolean
label: 'Participate in agof daily digital facts'
disabled_languages:
type: sequence
label: 'Disabled languages'
sequence:
type: string
6 changes: 5 additions & 1 deletion graphql/ivw.base.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ type Ivw {
st: String
cp: String
sv: String
sc: String
co: String
dn: String
dg: String
pt: String
dc: String
bfe: String
mobile_cp: String
mobile_st: String
mobile_sv: String
mobile_dn: String
mobile_width: String
legacy_mode: String
}
50 changes: 35 additions & 15 deletions ivw_integration.module
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ function ivw_integration_theme() {
'cp' => NULL,
'sv' => NULL,
'co' => NULL,
'sc' => NULL,
'dn' => NULL,
'dc' => NULL,
'dg' => NULL,
'pt' => NULL,
'bfe' => NULL,
'mobile_st' => NULL,
'mobile_cp' => NULL,
'mobile_sv' => NULL,
Expand Down Expand Up @@ -87,42 +90,59 @@ function ivw_integration_page_attachments(array &$page) {
return;
}

// Base minification script on the core javascript setting.
$minified = \Drupal::config('system.performance')->get('js.preprocess');
if (!$trackerService->isLanguageEnabled()) {
return;
}

$page['#cache']['tags'] = Cache::mergeTags($page['#cache']['tags'] ?? [], $trackerService->getCacheTags());

$page['#cache']['tags'] = Cache::mergeTags(isset($page['#cache']['tags']) ? $page['#cache']['tags'] : [], $trackerService->getCacheTags());
if ($tracker['legacy_mode']) {
$page['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#attributes' => [
'src' => 'https://script.ioam.de/iam.js' . (\Drupal::config('system.performance')->get('js.preprocess') ? '?m=1' : ''),
],
],
'ivw_library',
];
$page['#attached']['library'][] = 'ivw_integration/ivw_call';
}

$page['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#tag' => 'link',
'#attributes' => [
'src' => 'https://script.ioam.de/iam.js' . ($minified ? '?m=1' : ''),
'rel' => 'preload',
'href' => '//' . $tracker['dn'] . '/iomm/latest/manager/base/es6/bundle.js',
'as' => 'script',
'id' => 'IOMmBundle',
],
],
'ivw_library',
'web_manager_base_preload',
];

$page['#attached']['html_head'][] = [
[
'#tag' => 'link',
'#attributes' => [
'rel' => 'prefetch',
'rel' => 'preload',
'href' => '//' . $tracker['dn'] . '/iomm/latest/bootstrap/loader.js',
'as' => 'script',
'data-name' => 'ima',
'href' => 'https://' . $tracker['dn'] . '/sensor.modern.ncl.min.js',
],
],
'ima_prefetch',
'web_manager_bootstrap_preload',
];

$page['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#value' => '!function(e,n,c,r,t,l,o,a,d){r=e.IMAGlobalObject=r,e[r]=e[r]||function(){(e[r].q=e[r].q||[]).push(arguments)},l=n.querySelector("[data-name="+r+"]"),t=t&&!l?t+"/sensor.modern.ncl.min.js":l.href,e[r].src=t,o=n.createElement("script"),d=e.crypto&&e.crypto.subtle,a="noModule"in o&&!/Edge/.test(e.navigator.userAgent),o.src=a?d?t:t.replace(".ncl",".lcl"):t.replace(".modern.n",".legacy.l"),n.head.appendChild(o)}(window,document,0,"ima");',
'#attributes' => [
'src' => '//' . $tracker['dn'] . '/iomm/latest/bootstrap/loader.js',
'data-cmp-ab' => 2,
],
],
'ima_bootstrap',
'web_manager',
];

$page['#attached']['library'][] = 'ivw_integration/ivw_call';

}
2 changes: 1 addition & 1 deletion ivw_integration.services.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
ivw_integration.tracker:
class: Drupal\ivw_integration\IvwTracker
arguments: ['@config.factory', '@token', '@ivw_integration.lookup']
arguments: ['@config.factory', '@token', '@ivw_integration.lookup', '@language_manager']
ivw_integration.lookup:
class: Drupal\ivw_integration\IvwLookupService
arguments: ['@current_route_match', '@config.factory', '@entity_type.manager']
104 changes: 92 additions & 12 deletions src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Language\LanguageManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Utility\Token;

/**
* Defines a form that configures ivw settings.
*/
class SettingsForm extends ConfigFormBase {

/**
* Language manager.
*
* @var \Drupal\Core\Language\LanguageManager
* Language manager.
*/
protected $languageManager;

/**
* The token object.
*
Expand All @@ -26,10 +36,13 @@ class SettingsForm extends ConfigFormBase {
* The factory for configuration objects.
* @param \Drupal\Core\Utility\Token $token
* The token object.
* @param \Drupal\Core\Language\LanguageManager $language_manager
* The Language manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, Token $token) {
public function __construct(ConfigFactoryInterface $config_factory, Token $token, LanguageManager $language_manager) {
parent::__construct($config_factory);
$this->token = $token;
$this->languageManager = $language_manager;
}

/**
Expand All @@ -38,7 +51,8 @@ public function __construct(ConfigFactoryInterface $config_factory, Token $token
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('token')
$container->get('token'),
$container->get('language_manager')
);
}

Expand Down Expand Up @@ -77,6 +91,13 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#group' => 'ivw_settings',
];

$form['language_settings'] = [
'#type' => 'details',
'#title' => $this->t('Language'),
'#open' => FALSE,
'#group' => 'ivw_settings',
];

$form['site_settings']['site'] = [
'#type' => 'textfield',
'#title' => $this->t('IVW Site name'),
Expand All @@ -94,16 +115,16 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['site_settings']['service_domain_name'] = [
'#type' => 'textfield',
'#title' => $this->t('Service domain name'),
'#required' => FALSE,
'#required' => TRUE,
'#default_value' => $ivw_integration_settings->get('service_domain_name'),
'#description' => $this->t('Service domain name for anonymous INFOnline measurement'),
'#description' => $this->t('Service domain name for Measurement Manager'),
];
$form['site_settings']['mobile_service_domain_name'] = [
'#type' => 'textfield',
'#title' => $this->t('Service domain name for mobile site'),
'#required' => FALSE,
'#title' => $this->t('Mobile service domain name'),
'#required' => TRUE,
'#default_value' => $ivw_integration_settings->get('mobile_service_domain_name'),
'#description' => $this->t('Service domain name for anonymous INFOnline measurement for mobile site'),
'#description' => $this->t('Mobile service domain name for Measurement Manager'),
];
$form['site_settings']['code_template'] = [
'#type' => 'textfield',
Expand Down Expand Up @@ -141,12 +162,51 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#default_value' => $ivw_integration_settings->get('mobile_width'),
'#description' => $this->t('On a responsive site, this value tells the javascript up to which screen width, the device should be treated as mobile.'),
];
$form['site_settings']['mcvd'] = [

$form['site_settings']['distribution_channel'] = [
'#type' => 'select',
'#options' => [
'web' => $this->t('web'),
'hyb' => $this->t('hyb'),
'app' => $this->t('app'),
'ctv' => $this->t('ctv'),
],
'#title' => $this->t('The distribution channel'),
'#default_value' => $ivw_integration_settings->get('distribution_channel') ?: 'web',
'#description' => $this->t('The pixel type.'),
];

$form['site_settings']['pixel_type'] = [
'#type' => 'select',
'#options' => [
'cp' => $this->t('cp'),
'sp' => $this->t('sp'),
'xp' => $this->t('xp'),
],
'#title' => $this->t('Pixel type'),
'#default_value' => $ivw_integration_settings->get('pixel_type') ?: 'cp',
'#description' => $this->t('The pixel type.'),
];

$form['site_settings']['debug'] = [
'#type' => 'checkbox',
'#title' => $this->t('Debugging'),
'#default_value' => $ivw_integration_settings->get('debug'),
'#description' => $this->t('Activate debugging.'),
];

$form['site_settings']['legacy_mode'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use legacy code.'),
'#default_value' => $ivw_integration_settings->get('legacy_mode'),
];

$form['site_settings']['bfe'] = [
'#type' => 'checkbox',
'#title' => $this->t('Activate Multistage Client & Visit Detection (MCVD)'),
'#default_value' => $ivw_integration_settings->get('mcvd'),
'#description' => $this->t('This activates the MCVD tracking capability. See <a href="https://www.infonline.de/downloads/web-mew-und-ctv/">INFOnline Fact Sheet \'Multistage Client & Visit Detection\' (MCVD)</a> for more information about this.'),
'#title' => $this->t('Agof daily digital facts.'),
'#default_value' => $ivw_integration_settings->get('bfe'),
];

$frabo_default = $ivw_integration_settings->get('frabo_default');
$form['default_values']['frabo_default'] = [
'#type' => 'select',
Expand Down Expand Up @@ -381,6 +441,21 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#default_value' => $ivw_integration_settings->get('content_overridable'),
];

// Language specific options.
$languages = $this->languageManager->getLanguages();
$language_options = [];
foreach ($languages as $language) {
$language_options[$language->getId()] = $language->getName();
}

$form['language_settings']['disabled_languages'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Language settings'),
'#description' => $this->t('IVW will be disabled for the selected languages.'),
'#options' => $language_options,
'#default_value' => !empty($ivw_integration_settings->get('disabled_languages')) ? $ivw_integration_settings->get('disabled_languages') : [],
];

return parent::buildForm($form, $form_state);
}

Expand Down Expand Up @@ -419,7 +494,12 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
->set('frabo_overridable', $values['frabo_overridable'])
->set('frabo_mobile_default', $values['frabo_mobile_default'])
->set('frabo_mobile_overridable', $values['frabo_mobile_overridable'])
->set('mcvd', $values['mcvd'])
->set('debug', $values['debug'])
->set('disabled_languages', $values['disabled_languages'])
->set('pixel_type', $values['pixel_type'])
->set('distribution_channel', $values['distribution_channel'])
->set('legacy_mode', $values['legacy_mode'])
->set('bfe', $values['bfe'])
->save();
}

Expand Down
Loading

0 comments on commit 37e5e1f

Please sign in to comment.