Skip to content

Commit

Permalink
New Feature Google Analytics Support
Browse files Browse the repository at this point in the history
Dev Global and Survey-specific Google Analytics API Keys
Dev Allows multiple styles of Google Analytics, starting with {none, default, survey-group tracking}
Dev New Keywords {GOOGLE_ANALYTICS_API_KEY} and {GOOGLE_ANALYTICS_JAVASCRIPT}

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev@11979 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
TMSWhite committed Jan 10, 2012
1 parent fc70dd5 commit 0b26b62
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 11 deletions.
2 changes: 2 additions & 0 deletions admin/database.php
Expand Up @@ -1143,6 +1143,8 @@ function get_max_question_order($gid)
'usecaptcha'=>$_POST['usecaptcha'],
'emailresponseto'=>trim($_POST['emailresponseto']),
'emailnotificationto'=>trim($_POST['emailnotificationto']),
'googleAnalyticsAPIKey'=>trim($_POST['googleAnalyticsAPIKey']),
'googleAnalyticsStyle'=>trim($_POST['googleAnalyticsStyle']),
'tokenlength'=>$_POST['tokenlength']
);

Expand Down
25 changes: 25 additions & 0 deletions admin/editsurveysettings.php
Expand Up @@ -836,6 +836,31 @@
$editsurvey .= ">".$clang->gT("No")."</option>\n"
. "</select></li>\n";

//GOOGLE ANALYTICS PROCESSING
//GOOGLE ANALYTICS API KEY
$editsurvey .= "<li><label for='googleAnalyticsAPIKey'>".$clang->gT("Google Analytics API Key for this Survey?")."</label>\n"
. "<input type='text' value=\"{$esrow['googleAnalyticsAPIKey']}\" name='googleAnalyticsAPIKey' id='googleAnalyticsAPIKey' size='20'/>\n"
. "</li>\n";

//GOOGLE ANALYTICS STYLE
$editsurvey .= "<li><label for='googleAnalyticsStyle'>".$clang->gT("Google Analytics Style for this Survey?")."</label>\n"
. "<select id='googleAnalyticsStyle' name='googleAnalyticsStyle'>\n"
. "<option value='0'";
if (!$esrow['googleAnalyticsStyle'] || $esrow['googleAnalyticsStyle'] == "0") {
$editsurvey .= " selected='selected'";
}
$editsurvey .= ">".$clang->gT("Do not use Google Analytics")."</option>\n"
. "<option value='1'";
if ($esrow['googleAnalyticsStyle'] == "1") {
$editsurvey .= " selected='selected'";
}
$editsurvey .= ">".$clang->gT("Default Google Analytics")."</option>\n"
. "<option value='2'";
if ($esrow['googleAnalyticsStyle'] == "2") {
$editsurvey .= " selected='selected'";
}
$editsurvey .= ">".$clang->gT("SurveyName-[SID]/GroupName")."</option>\n"
. "</select></li>\n";

// End Notification and Data management TAB
$editsurvey .= "</ul></div>\n";
Expand Down
4 changes: 3 additions & 1 deletion admin/globalsettings.php
Expand Up @@ -94,6 +94,7 @@ function globalsettingssave()
setGlobalSetting('sessionlifetime',$sessionlifetimetemp);
setGlobalSetting('ipInfoDbAPIKey',$_POST['ipInfoDbAPIKey']);
setGlobalSetting('googleMapsAPIKey',$_POST['googleMapsAPIKey']);
setGlobalSetting('googleAnalyticsAPIKey',$_POST['googleAnalyticsAPIKey']);
setGlobalSetting('force_ssl',$_POST['force_ssl']);
setGlobalSetting('surveyPreview_require_Auth',strip_tags($_POST['surveyPreview_require_Auth']));
$savetime=trim(strip_tags((float) $_POST['timeadjust']).' hours'); //makes sure it is a number, at least 0
Expand Down Expand Up @@ -261,7 +262,8 @@ function globalsettingsdisplay()
. "<input type='text' size='35' id='ipInfoDbAPIKey' name='ipInfoDbAPIKey' value=\"".htmlspecialchars(getGlobalSetting('ipInfoDbAPIKey'))."\" /></li>"
. "<li><label for='googleMapsAPIKey'>".$clang->gT("Google Maps API key:")."</label>\n"
. "<input type='text' size='35' id='googleMapsAPIKey' name='googleMapsAPIKey' value=\"".htmlspecialchars(getGlobalSetting('googleMapsAPIKey'))."\" /></li>"

. "<li><label for='googleAnalyticsAPIKey'>".$clang->gT("Google Analytics API key:")."</label>\n"
. "<input type='text' size='35' id='googleAnalyticsAPIKey' name='googleAnalyticsAPIKey' value=\"".htmlspecialchars(getGlobalSetting('googleAnalyticsAPIKey'))."\" /></li>"
;


Expand Down
5 changes: 3 additions & 2 deletions admin/install/create-mssql.sql
Expand Up @@ -315,7 +315,8 @@ CREATE TABLE [prefix_surveys] (
[navigationdelay] tinyint default '0',
[nokeyboard] char(1) default 'N',
[alloweditaftercompletion] char(1) default 'N',

[googleAnalyticsStyle] char(1) DEFAULT NULL,
[googleAnalyticsAPIKey] VARCHAR(25) DEFAULT NULL,
PRIMARY KEY ([sid])
)
;
Expand Down Expand Up @@ -551,7 +552,7 @@ create index [parent_qid_idx] on [prefix_questions] ([parent_qid]);
--
-- Version Info
--
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '154');
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '155');
INSERT INTO [prefix_settings_global] VALUES ('SessionName', '$sessionname');


Expand Down
6 changes: 3 additions & 3 deletions admin/install/create-mssqlnative.sql
Expand Up @@ -324,7 +324,8 @@ CREATE TABLE [prefix_surveys] (
[navigationdelay] tinyint default '0',
[nokeyboard] char(1) default 'N',
[alloweditaftercompletion] char(1) default 'N',

[googleAnalyticsStyle] char(1) DEFAULT NULL,
[googleAnalyticsAPIKey] VARCHAR(25) DEFAULT NULL,
PRIMARY KEY ([sid])
)
;
Expand Down Expand Up @@ -567,8 +568,7 @@ create index [parent_qid_idx] on [prefix_questions] ([parent_qid]);
--
-- Version Info
--
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '154');
INSERT INTO [prefix_settings_global] VALUES ('SessionName', '$sessionname');
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '155');
INSERT INTO [prefix_settings_global] VALUES ('SessionName', '$sessionname');


Expand Down
4 changes: 3 additions & 1 deletion admin/install/create-mysql.sql
Expand Up @@ -303,6 +303,8 @@ CREATE TABLE `prefix_surveys` (
`navigationdelay` tinyint(2) default '0',
`nokeyboard` char(1) default 'N',
`alloweditaftercompletion` char(1) default 'N',
`googleAnalyticsStyle` char(1) DEFAULT NULL,
`googleAnalyticsAPIKey` VARCHAR(25) DEFAULT NULL,
PRIMARY KEY(`sid`)
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Expand Down Expand Up @@ -538,7 +540,7 @@ create index `parent_qid_idx` on `prefix_questions` (`parent_qid`);
--
-- Version Info
--
INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '154');
INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '155');
INSERT INTO `prefix_settings_global` VALUES ('SessionName', '$sessionname');


Expand Down
4 changes: 3 additions & 1 deletion admin/install/create-postgres.sql
Expand Up @@ -313,6 +313,8 @@ CREATE TABLE prefix_surveys (
navigationdelay smallint DEFAULT '0',
nokeyboard character(1) DEFAULT 'N'::bpchar,
alloweditaftercompletion character(1) DEFAULT 'N'::bpchar,
googleAnalyticsStyle character(1) DEFAULT NULL,
googleAnalyticsAPIKey character varying(25) DEFAULT NULL,
CONSTRAINT prefix_surveys_pkey PRIMARY KEY (sid)
);

Expand Down Expand Up @@ -549,7 +551,7 @@ create index parent_qid_idx on prefix_questions (parent_qid);
--
-- Version Info
--
INSERT INTO prefix_settings_global VALUES ('DBVersion', '154');
INSERT INTO prefix_settings_global VALUES ('DBVersion', '155');
INSERT INTO prefix_settings_global VALUES ('SessionName', '$sessionname');


Expand Down
6 changes: 6 additions & 0 deletions admin/update/upgrade-mssql.php
Expand Up @@ -592,6 +592,12 @@ function db_upgrade($oldversion) {
modify_database("","ALTER TABLE [prefix_groups] ADD [grelevance] text DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='154' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}
if ($oldversion < 155)
{
modify_database("","ALTER TABLE [prefix_surveys] ADD [googleAnalyticsStyle] char(1) DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("","ALTER TABLE [prefix_surveys] ADD [googleAnalyticsAPIKey] varchar(25) DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='155' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}
echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions admin/update/upgrade-mssqlnative.php
Expand Up @@ -591,6 +591,12 @@ function db_upgrade($oldversion) {
modify_database("","ALTER TABLE [prefix_groups] ADD [grelevance] text DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("","update [prefix_settings_global] set [stg_value]='154' where stg_name='DBVersion'"); echo $modifyoutput; flush();@ob_flush();
}
if ($oldversion < 155)
{
modify_database("","ALTER TABLE [prefix_surveys] ADD [googleAnalyticsStyle] char(1) DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("","ALTER TABLE [prefix_surveys] ADD [googleAnalyticsAPIKey] varchar(25) DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='155' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}

echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
return true;
Expand Down
7 changes: 6 additions & 1 deletion admin/update/upgrade-mysql.php
Expand Up @@ -702,7 +702,12 @@ function db_upgrade($oldversion) {
modify_database("","ALTER TABLE `prefix_groups` ADD `grelevance` text DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("","update `prefix_settings_global` set `stg_value`='154' where stg_name='DBVersion'"); echo $modifyoutput; flush();@ob_flush();
}

if ($oldversion < 155)
{
modify_database("","ALTER TABLE `prefix_surveys` ADD `googleAnalyticsStyle` char(1) DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("","ALTER TABLE `prefix_surveys` ADD `googleAnalyticsAPIKey` varchar(25) DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("", "UPDATE `prefix_settings_global` SET stg_value='155' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}
echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions admin/update/upgrade-postgres.php
Expand Up @@ -426,6 +426,12 @@ function db_upgrade($oldversion) {
modify_database("","ALTER TABLE prefix_groups ADD grelevance text DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("", "UPDATE prefix_settings_global SET stg_value='154' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}
if ($oldversion < 155)
{
modify_database("","ALTER TABLE prefix_surveys ADD googleAnalyticsStyle char(1) DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("","ALTER TABLE prefix_surveys ADD googleAnalyticsAPIKey character varying(25) DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
modify_database("", "UPDATE prefix_settings_global SET stg_value='155' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}

echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
return true;
Expand Down
9 changes: 9 additions & 0 deletions config-defaults.php
Expand Up @@ -532,6 +532,15 @@

$googleMapsAPIKey = '';

// Google Analytics API key: http://www.google.com/analytics/
$googleAnalyticsAPIKey = '';

// Style for using Google Analytics
// 0 = Don't use Analytics
// 1 = Default
// 2 = SurveyName-[SID]/GroupName
$googleAnalyticsStyle = '0';

/**
* This variable defines the total space available to the file upload question across all surveys. If set to 0 then no limit applies.
*
Expand Down
44 changes: 44 additions & 0 deletions replacements.php
Expand Up @@ -544,6 +544,48 @@ function templatereplace($line, $replacements=array(), $anonymized=false, $quest
$_assessment_current_total = '';
}

$_googleAnalyticsAPIKey = (isset($thissurvey['googleAnalyticsAPIKey']) ? $thissurvey['googleAnalyticsAPIKey'] : '');
$_googleAnalyticsStyle = (isset($thissurvey['googleAnalyticsStyle']) ? $thissurvey['googleAnalyticsStyle'] : '0');

switch ($_googleAnalyticsStyle)
{
case '0':
default:
$_googleAnalyticsJavaScript = '';
break;
case '1':
// Default Google Tracking
$_googleAnalyticsJavaScript = <<<EOD
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("$_googleAnalyticsAPIKey");
pageTracker._trackPageview();
} catch(err) {}
</script>
EOD;
break;
case '2':
// SurveyName-[SID]/GroupName
$_trackURL = htmlspecialchars($thissurvey['name'] . '-[' . $surveyid . ']/' . $_groupname);
$_googleAnalyticsJavaScript = <<<EOD
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("$_googleAnalyticsAPIKey");
pageTracker._trackPageview("$_trackURL");
} catch(err) {}
</script>
EOD;
break;
}

// Set the array of replacement variables here - don't include curly braces
$corecoreReplacements = array();
$coreReplacements['ANSWER'] = $answer; // global
Expand All @@ -557,6 +599,8 @@ function templatereplace($line, $replacements=array(), $anonymized=false, $quest
$coreReplacements['COMPLETED'] = $completed; // global
$coreReplacements['DATESTAMP'] = $_datestamp;
$coreReplacements['EXPIRY'] = $_dateoutput;
$coreReplacements['GOOGLE_ANALYTICS_API_KEY'] = $_googleAnalyticsAPIKey;
$coreReplacements['GOOGLE_ANALYTICS_JAVASCRIPT'] = $_googleAnalyticsJavaScript;
$coreReplacements['GROUPDESCRIPTION'] = $_groupdescription;
$coreReplacements['GROUPNAME'] = $_groupname;
$coreReplacements['LANG'] = $clang->getlangcode();
Expand Down
4 changes: 2 additions & 2 deletions version.php
@@ -1,7 +1,7 @@
<?php

$versionnumber = "1.92 RC1";
$dbversionnumber = 154;
$versionnumber = "1.92 RC2";
$dbversionnumber = 155;
$buildnumber = '';

?>

0 comments on commit 0b26b62

Please sign in to comment.