Skip to content

Instantly share code, notes, and snippets.

@ikorgik
Created June 7, 2013 14:10
Show Gist options
  • Save ikorgik/5729527 to your computer and use it in GitHub Desktop.
Save ikorgik/5729527 to your computer and use it in GitHub Desktop.
Code example
<?php
/**
* @file
* Web analytics.
*/
/**
* Implements hook_help().
*/
function web_analyt_help($section) {
switch ($section) {
case 'admin/help#web_analyt':
return t('The inserts web analytics tracking code.');
}
}
/**
* Implements hook_menu().
*/
function web_analyt_menu() {
$items['admin/config/web_analyt'] = array(
'description' => 'Support for web analytics.',
'title' => 'Web analytics',
'page callback' => 'drupal_get_form',
'page arguments' => array('web_analyt_admin_settings'),
'access arguments' => array('administer clicktale'),
);
return $items;
}
/**
* Implements hook_permission(). Registers the permission "administer
* clicktale".
*/
function web_analyt_permission() {
return array(
'administer clicktale' => array(
'title' => t('administer clicktale'),
),
);
}
/**
* Implements hook_init(). Inserts the value of the variable
* "web_analyt_header" into the page header.
*/
function web_analyt_init() {
global $user;
if ($user->uid == 0 && $value = variable_get('web_analyt_header', 0)) {
$element = array(
'#tag' => 'script',
'#prefix' => '<!-- ClickTale Top part -->',
'#suffix' => '<!-- ClickTale end of Top part -->',
'#value'=> $value,
'#attributes' => array('type' => 'text/javascript'),
);
drupal_add_html_head($element, 'web_analyt_header');
}
}
/**
* Implements hook_page_build(). Inserts the value of the variable
"web_analyt_footer" into the page footer.
*
* @param $main (optional)
* Whether the current page is the front page of the site.
* @return A script element
*/
function web_analyt_page_build(&$page) {
global $user;
if ($user->uid == 0 && $value = variable_get('web_analyt_footer', 0)) {
$page['footer']['web_analyt']= array(
'#type' => 'markup',
'#markup' => $value,
);
}
}
/**
* Clictale configuration form.
*/
function web_analyt_admin_settings($form, &$form_state) {
$form['web_analyt'] = array(
'#type' => 'item',
'#value' => '<p>' . t("Enter your ClickTale tracking code in the fields below.") . '</p>',
);
$form['web_analyt_header'] = array(
'#type' => 'textarea',
'#title' => t('Header'),
'#default_value' => variable_get('web_analyt_header', ''),
'#description' => t('Tracking code to insert after the &lt;body&gt; tag'),
'#required' => TRUE,
);
$form['web_analyt_footer'] = array(
'#type' => 'textarea',
'#title' => t('Footer'),
'#rows' => '12',
'#default_value' => variable_get('web_analyt_footer', ''),
'#description' => t('Tracking code to insert before the &lt;/body&gt; tag'),
'#required' => TRUE,
);
return system_settings_form($form);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment