Skip to content

Commit

Permalink
Merge pull request #27 from Kunstmaan/feature/default-segments
Browse files Browse the repository at this point in the history
Feature/default segments
  • Loading branch information
Roderik van der Veer committed Jun 22, 2014
2 parents 77437f3 + e03ee27 commit 1b8f1ff
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Controller/GoogleAnalyticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public function configAction(Request $request)
$params['disableGoals'] = $config->getDisableGoals();
$params['configId'] = $config->getId();


$params['profileSegments'] = $configHelper->getProfileSegments();

return $this->render(
'KunstmaanDashboardBundle:GoogleAnalytics:setupcontainer.html.twig',
$params
Expand Down
34 changes: 34 additions & 0 deletions Helper/Google/Analytics/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,40 @@ public function getActiveProfile() {
}
}

/* =============================== PROFILE SEGMENTS =============================== */
/**
* get all segments for the saved profile
*
* @return array
*/
public function getProfileSegments()
{
$profileSegments = $this
->serviceHelper
->getService()
->management_segments
->listManagementSegments()
->items;

$builtin = array();
$own = array();
foreach ($profileSegments as $segment) {
if ($segment->type == 'BUILT_IN') {
$builtin[] = array(
'name' => $segment->name,
'query' => $segment->segmentId
);
} else {
$own[] = array(
'name' => $segment->name,
'query' => $segment->segmentId
);
}
}

return array('builtin' => $builtin, 'own' => $own);
}

/* =============================== CONFIG =============================== */

/**
Expand Down
8 changes: 5 additions & 3 deletions Resources/public/js/setup/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,16 @@ $(function () {
return false;
});

function addSegmentInput() {
function addSegmentInput(name, query) {
if (!name) { name = ''; }
if (!query) { query = ''; }
// create an id
var id = $.now();

// create elements
var segmentDiv = $('<div>', {'id' : 'segmentDiv'+id});
var segmentInput = $('<input>', { 'type': 'text', 'id' : 'segment'+id, 'class' : 'segment-query', 'placeholder' : 'query'});
var segmentName = $('<input>', { 'type': 'text', 'id' : 'segment_name'+id, 'class' : 'segment-name', 'placeholder' : 'name'});
var segmentInput = $('<input>', { 'type': 'text', 'id' : 'segment'+id, 'class' : 'segment-query', 'placeholder' : 'query', 'value' : query});
var segmentName = $('<input>', { 'type': 'text', 'id' : 'segment_name'+id, 'class' : 'segment-name', 'placeholder' : 'name', 'value' : name});
var segmentButton = $('<input>', {'type': 'button', 'data-segment-id' : 'segmentDiv'+id, 'class' : 'segment-button__delete btn', 'value' : 'cancel'})

// add event trigger for the delete button
Expand Down
18 changes: 16 additions & 2 deletions Resources/public/scss/_dashboard-setup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
padding-left:40px;
padding-bottom:5px;

ul {
& > ul {
margin-left:0;

&:after {
Expand All @@ -90,7 +90,7 @@
clear:both;
}
}
li {
& > ul > li {
border: 1px solid #CCCCCC;
border-radius:3px;

Expand All @@ -107,6 +107,11 @@
}
}

.dropdown-menu {
height:200px;
overflow:auto;
}

.segment-list-button__edit,
.segment-list-button__confirm,
.segment-button__delete,
Expand Down Expand Up @@ -134,6 +139,15 @@
width:50%;
}

.segment-query__selection {
color:#30af25;
font-weight: bold;
}

#segment-button__add {
margin-bottom:20px;
}

.display-view,
.edit-view {
clear:both;
Expand Down
4 changes: 3 additions & 1 deletion Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ dashboard:
back: Go to dashboard
segment:
add: Add segment
info: 'For documentation on how to create segment queries, click'
info: 'To create segments, you can use segment IDs (and also combine them), or write your own queries. Google provides predefined segment IDs (listed below), and you can create your own with the Google Segment Builder tool in Google Analytics. For documentation on how to create your own segment queries, click'
here: here
own: Own segments
builtin: Built-in segments
segments: Segment setup
accounts: Account setup
reset:
Expand Down
27 changes: 26 additions & 1 deletion Resources/views/GoogleAnalytics/setup.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,33 @@
</li>
{% endfor %}
</ul>

<div id="segments-new"></div>
<button class="btn btn-small" type="button" id="segment-button__add"><i class="icon-plus"></i> add segment</button>

<button type="button" class="btn btn-small" id="segment-button__add">
<i class="icon-plus"></i> add segment
</button>

<div>
{% if profileSegments.own | length > 0 %}
<h4>{{ 'dashboard.ga.setup.segment.own' | trans }}</h4>
<ul>
{% for segment in profileSegments.own %}
<li>
{{segment.name}} (<span class="segment-query__selection">{{segment.query}}</span>)
</li>
{% endfor %}
</ul>
{% endif %}
<h4>{{ 'dashboard.ga.setup.segment.builtin' | trans }}</h4>
<ul>
{% for segment in profileSegments.builtin %}
<li>
{{segment.name}} (<span class="segment-query__selection">{{segment.query}}</span>)
</li>
{% endfor %}
</ul>
</div>
</div>

<div class="setup-group" id="control-group">
Expand Down

0 comments on commit 1b8f1ff

Please sign in to comment.