|
4 | 4 | * Implements hook_permission(). |
5 | 5 | */ |
6 | 6 | function cornell_mixpanel_permission() { |
7 | | - return [ |
8 | | - 'administer cornell_mixpanel' => [ |
9 | | - 'title' => t('Administer Cornell Mixpanel'), |
10 | | - 'description' => t('Set Mixpanel token and change other internal settings for Mixpanel integration.'), |
11 | | - ], |
12 | | - ]; |
| 7 | + return [ |
| 8 | + 'administer cornell_mixpanel' => [ |
| 9 | + 'title' => t('Administer Cornell Mixpanel'), |
| 10 | + 'description' => t('Set Mixpanel token and change other internal settings for Mixpanel integration.'), |
| 11 | + ], |
| 12 | + ]; |
13 | 13 | } |
14 | 14 |
|
15 | 15 | /** |
16 | 16 | * Implements hook_help(). |
17 | 17 | */ |
18 | 18 | function cornell_mixpanel_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) { |
19 | | - switch ($route_name) { |
20 | | - case 'help.page.cornell_mixpanel': |
21 | | - return '<p>' . t('Provides integration with the Mixpanel real-time analytics service. <strong>For more information, see the <a href="!docs_url" target="_blank">full documentation</a> online.</strong>', [ |
22 | | - '!docs_url' => 'https://drupal.org/node/2096053', |
23 | | - ]) . '</p>'; |
24 | | - } |
| 19 | + switch ($route_name) { |
| 20 | + case 'help.page.cornell_mixpanel': |
| 21 | + return '<p>' . t('Provides integration with the Mixpanel real-time analytics service. <strong>For more information, see the <a href="!docs_url" target="_blank">full documentation</a> online.</strong>', [ |
| 22 | + '!docs_url' => 'https://drupal.org/node/2096053', |
| 23 | + ]) . '</p>'; |
| 24 | + } |
25 | 25 | } |
26 | | -function cornell_mixpanel_preprocess_page(&$variables) |
27 | | -{ |
28 | | - $config = \Drupal::config('cornell_mixpanel.settings'); |
29 | | - |
30 | | - $user = \Drupal::currentUser(); |
31 | | - if ($config->get('cornell_mixpanel_track_only_anonymous') && $user->isAuthenticated()) { |
32 | | - return; |
33 | | - } |
34 | | - |
35 | | - $route_name = \Drupal::routeMatch()->getRouteName(); |
36 | | - if ($config->get('cornell_mixpanel_ignore_admin_routes') && strpos($route_name, 'admin') !== false) { |
37 | | - return; |
38 | | - } |
39 | | - |
40 | | - $mixpanel_config = []; |
41 | | - $proxy_config = $config->get('cornell_mixpanel_prod_proxy_domain'); |
42 | | - if($proxy_config && $proxy_config != "") { |
43 | | - $proxy_config = rtrim(trim($proxy_config), '/'); |
44 | | - } |
45 | | - else { |
46 | | - $proxy_config = "https://api-js.mixpanel.com"; |
47 | | - } |
48 | | - $mixpanel_config['proxy_server'] = $proxy_config; |
| 26 | +function cornell_mixpanel_preprocess_page(&$variables) { |
| 27 | + $config = \Drupal::config('cornell_mixpanel.settings'); |
49 | 28 |
|
50 | | - if (isset($_ENV['PANTHEON_ENVIRONMENT']) && $_ENV['PANTHEON_ENVIRONMENT'] === 'live') { |
51 | | - $mixpanel_config['token'] = trim($config->get('cornell_mixpanel_token')); |
52 | | - } |
53 | | - else { |
54 | | - $mixpanel_config['token'] = trim($config->get('cornell_mixpanel_test_token')); |
| 29 | + $domains_to_track = $config->get('cornell_mixpanel_domains_to_track'); |
| 30 | + if ($domains_to_track) { |
| 31 | + $domains_to_track = array_map('trim', explode(',', $domains_to_track)); |
| 32 | + $current_domain = \Drupal::request()->getHost(); |
| 33 | + if (!in_array($current_domain, $domains_to_track)) { |
| 34 | + return; |
55 | 35 | } |
| 36 | + } |
| 37 | + |
| 38 | + $user = \Drupal::currentUser(); |
| 39 | + if ($config->get('cornell_mixpanel_track_only_anonymous') && $user->isAuthenticated()) { |
| 40 | + return; |
| 41 | + } |
| 42 | + |
| 43 | + $route_name = \Drupal::routeMatch()->getRouteName(); |
| 44 | + if ($config->get('cornell_mixpanel_ignore_admin_routes') && strpos($route_name, 'admin') !== FALSE) { |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + $mixpanel_config = []; |
| 49 | + $proxy_config = $config->get('cornell_mixpanel_prod_proxy_domain'); |
| 50 | + if ($proxy_config && $proxy_config != "") { |
| 51 | + $proxy_config = rtrim(trim($proxy_config), '/'); |
| 52 | + } |
| 53 | + else { |
| 54 | + $proxy_config = "https://api-js.mixpanel.com"; |
| 55 | + } |
| 56 | + $mixpanel_config['proxy_server'] = $proxy_config; |
| 57 | + if (isset($_ENV['PANTHEON_ENVIRONMENT']) && $_ENV['PANTHEON_ENVIRONMENT'] === 'live') { |
| 58 | + $mixpanel_config['token'] = trim($config->get('cornell_mixpanel_token')); |
| 59 | + } |
| 60 | + else { |
| 61 | + $mixpanel_config['token'] = trim($config->get('cornell_mixpanel_test_token')); |
| 62 | + } |
| 63 | + |
| 64 | + $mixpanel_config['cross_subdomain_cookie'] = (bool) $config->get('cornell_mixpanel_cross_subdomain_cookie'); |
| 65 | + $mixpanel_config['debug_mode'] = (bool) $config->get('cornell_mixpanel_debug_mode'); |
| 66 | + $mixpanel_config['ignore_dnt'] = (bool) $config->get('cornell_mixpanel_ignore_dnt'); |
56 | 67 |
|
57 | | - $mixpanel_config['cross_subdomain_cookie'] = (bool) $config->get('cornell_mixpanel_cross_subdomain_cookie'); |
58 | | - $mixpanel_config['debug_mode'] = (bool) $config->get('cornell_mixpanel_debug_mode'); |
59 | | - $mixpanel_config['ignore_dnt'] = (bool) $config->get('cornell_mixpanel_ignore_dnt'); |
60 | | - |
61 | | - $variables['#attached']['library'][] = 'cornell_mixpanel/cornell_mixpanel'; |
62 | | - $variables['#attached']['drupalSettings']['cornell_mixpanel'] = json_encode($mixpanel_config); |
| 68 | + $variables['#attached']['library'][] = 'cornell_mixpanel/cornell_mixpanel'; |
| 69 | + $variables['#attached']['drupalSettings']['cornell_mixpanel'] = json_encode($mixpanel_config); |
63 | 70 | } |
0 commit comments