Skip to content

Commit

Permalink
Fixed Bug #11416: Google Analytics Global Configuration is not being …
Browse files Browse the repository at this point in the history
…used by survey

dev Added the possibility to use Global, self-defined or non at all google analytics in a survey. Reused The buttongroup of Token/Bounce Settings
dev Added some nice effect, hiding the disabled inputs
  • Loading branch information
Markus Flür committed Jul 21, 2016
1 parent 70358e0 commit a88e4d9
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 7 deletions.
15 changes: 14 additions & 1 deletion application/controllers/admin/database.php
Expand Up @@ -1234,7 +1234,20 @@ function index($sa = null)
$oSurvey->usecaptcha = Survey::transcribeCaptchaOptions();
$oSurvey->emailresponseto = App()->request->getPost('emailresponseto');
$oSurvey->emailnotificationto = App()->request->getPost('emailnotificationto');
$oSurvey->googleanalyticsapikey = App()->request->getPost('googleanalyticsapikey');
$oSurvey->googleanalyticsapikeysetting = App()->request->getPost('googleanalyticsapikeysetting');
if( $oSurvey->googleanalyticsapikeysetting == "Y")
{
$oSurvey->googleanalyticsapikey = App()->request->getPost('googleanalyticsapikey');
}
else if( $oSurvey->googleanalyticsapikeysetting == "G")
{
$oSurvey->googleanalyticsapikey = "9999useGlobal9999";
}
else if( $oSurvey->googleanalyticsapikeysetting == "N")
{
$oSurvey->googleanalyticsapikey = "";
}

$oSurvey->googleanalyticsstyle = App()->request->getPost('googleanalyticsstyle');
$oSurvey->tokenlength = (App()->request->getPost('tokenlength')<5 || App()->request->getPost('tokenlength')>36)?15:App()->request->getPost('tokenlength');
$oSurvey->adminemail = App()->request->getPost('adminemail');
Expand Down
5 changes: 4 additions & 1 deletion application/controllers/admin/surveyadmin.php
Expand Up @@ -1222,9 +1222,12 @@ private function _fetchSurveyInfo($action, $iSurveyID=null)
{
$oSurvey = Survey::model()->findByPk($iSurveyID);
}

if($oSurvey)
{
return $oSurvey->attributes;
$attribs = $oSurvey->attributes;
$attribs['googleanalyticsapikeysetting'] = $oSurvey->getGoogleanalyticsapikeysetting();
return $attribs;
}
}

Expand Down
12 changes: 8 additions & 4 deletions application/helpers/replacements_helper.php
Expand Up @@ -553,14 +553,18 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
{
$_assessment_current_total = '';
}

if (isset($thissurvey['googleanalyticsapikey']) && trim($thissurvey['googleanalyticsapikey']) != '')
if($thissurvey['googleanalyticsapikey'] === "9999useGlobal9999")
{
$_googleAnalyticsAPIKey = trim(getGlobalSetting('googleanalyticsapikey'));
}
else if (isset($thissurvey['googleanalyticsapikey']) && trim($thissurvey['googleanalyticsapikey']) != '')
{
$_googleAnalyticsAPIKey = trim($thissurvey['googleanalyticsapikey']);
}
else
else
{
$_googleAnalyticsAPIKey = trim(getGlobalSetting('googleanalyticsapikey'));
$_googleAnalyticsAPIKey = "";

}
$_googleAnalyticsStyle = (isset($thissurvey['googleanalyticsstyle']) ? $thissurvey['googleanalyticsstyle'] : '1');
$_googleAnalyticsJavaScript = '';
Expand Down
45 changes: 45 additions & 0 deletions application/models/Survey.php
Expand Up @@ -436,6 +436,51 @@ public function getHasTokens()
}
}

/**
* Returns the value for the SurveyEdit GoogleAnalytics API-Key UseGlobal Setting
*
*/
public function getGoogleanalyticsapikeysetting(){
if($this->googleanalyticsapikey === "9999useGlobal9999")
{
return "G";
}
else if($this->googleanalyticsapikey == "")
{
return "N";
}
else
{
return "Y";
}
}
public function setGoogleanalyticsapikeysetting($value){
if($value == "G")
{
$this->googleanalyticsapikey = "9999useGlobal9999";
}
else if($value == "N")
{
$this->googleanalyticsapikey = "";
}
}

/**
* Returns the value for the SurveyEdit GoogleAnalytics API-Key UseGlobal Setting
*
*/
public function getGoogleanalyticsapikey(){
if($this->googleanalyticsapikey === "9999useGlobal9999")
{
return getGlobalSetting(googleanalyticsapikey);
}
else
{
return $this->googleanalyticsapikey;
}
}



/**
* Creates a new survey - does some basic checks of the suppplied data
Expand Down
Expand Up @@ -157,14 +157,30 @@
</div>
</div>

<!-- GoogleAnalytics settings to be used -->
<div class="form-group">
<label class="col-sm-5 control-label" for="googleanalyticsapikeysetting">
<?php echo gT('Google Analytics settings:');?>
</label>
<div class="col-sm-7">
<?php $this->widget('yiiwheels.widgets.buttongroup.WhButtonGroup', array(
'name' => 'googleanalyticsapikeysetting',
'value'=> $esrow['googleanalyticsapikeysetting'],
'selectOptions'=>array(
"N"=>gT("None",'unescaped'),
"Y"=>gT("Use settings below",'unescaped'),
"G"=>gT("Use global settings",'unescaped')
)
));?>
</div>
</div>
<!-- Google Analytics -->
<div class="form-group">
<label class="col-sm-5 control-label" for='googleanalyticsapikey'><?php eT("Google Analytics API key:"); ?></label>
<div class="col-sm-7">
<?php echo CHtml::textField('googleanalyticsapikey',$esrow['googleanalyticsapikey'],array('size'=>20), array('class'=>"form-control")); ?>
</div>
</div>

<!-- Google Analytics style -->
<div class="form-group">
<label class="col-sm-5 control-label" for='googleanalyticsstyle'><?php eT("Google Analytics style:"); ?></label>
Expand All @@ -180,3 +196,7 @@
</div>
</div>
</div>
<?php
$oAdminTheme = AdminTheme::getInstance();
$oAdminTheme->registerScriptFile( 'ADMIN_SCRIPT_PATH', 'survey_edit_notificationpanel.js');
?>
41 changes: 41 additions & 0 deletions scripts/admin/survey_edit_notificationpanel.js
@@ -0,0 +1,41 @@
/**
* This javascript show or hide the googleanalytics parameters in function of the Notification settings to be used
* (None, use setting below, use global settings )
*/
function updateParameters()
{
if ($('#googleanalyticsapikeysetting input:radio:checked').val()=='Y'){
$("#googleanalyticsstyle").find('label').removeClass('disabled');
$("#googleanalyticsstyle").closest('div.form-group').slideDown(400);

$("#googleanalyticsapikey").removeAttr('disabled');
$("#googleanalyticsapikey").closest('div.form-group').slideDown(400);
if($("#googleanalyticsapikey").val() == "9999useGlobal9999"){
$("#googleanalyticsapikey").val("");
}
}
else if($('#googleanalyticsapikeysetting input:radio:checked').val()=='N')
{
$("#googleanalyticsstyle").val(0);
$("#googleanalyticsstyle").find('label').addClass('disabled');
$("#googleanalyticsstyle").closest('div.form-group').slideUp(400);

$("#googleanalyticsapikey").attr('disabled','disabled');
$("#googleanalyticsapikey").closest('div.form-group').slideUp(400);
}
else
{
$("#googleanalyticsstyle").find('label').removeClass('disabled');
$("#googleanalyticsstyle").closest('div.form-group').slideDown(400);

$("#googleanalyticsapikey").attr('disabled','disabled');
$("#googleanalyticsapikey").closest('div.form-group').slideUp(400);
}
}

$(document).ready(function(){
updateParameters();
$("input:radio[id^='googleanalyticsapikeysetting']").on('change',function(){
updateParameters();
});
});

1 comment on commit a88e4d9

@c-schmitz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be 'Fixed issue"

Please sign in to comment.