Skip to content

Commit

Permalink
Quickly add analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 committed Jun 15, 2017
1 parent 02eeb08 commit 88c9f79
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 2 deletions.
33 changes: 33 additions & 0 deletions app/components/campaign/-analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Ember from 'ember';

const { Component, inject: { service } } = Ember;

export default Component.extend({
classNames: ['card', 'mb-3'],
campaignAnalytics: service(),

campaignId: null,
form: null,
loading: false,

report: null,

init() {
this._super(...arguments);
this.send('loadAnalytics');
},

actions: {
loadAnalytics() {
this.set('loading', true);
this.get('campaignAnalytics').retrieve(this.get('campaignId'), this.get('form.identifier'))
.then((report) => {
this.set('report', report);
console.info(report);
})
.finally(() => this.set('loading', false))
;
},
},

});
16 changes: 16 additions & 0 deletions app/services/campaign-analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Ember from 'ember';
import promisify from 'admin/utils/wrap-ajax';

const { Service, inject: { service }, $ } = Ember;

export default Service.extend({
errorProcessor: service(),

retrieve(campaignId, formId) {
return promisify($.ajax(`/analytics/campaign/${campaignId}/${formId}`, {
method: 'GET',
}))
.then((response) => response.response.data)
.catch((json) => this.get('errorProcessor').notify(json.errors || []))
},
});
2 changes: 1 addition & 1 deletion app/services/field-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export default Service.extend({
],

retrieve() {
const fields = this.get('fields');
const fields = this.get('fields').slice();
fields.pushObject({ key: 'country', label: 'Country', fieldType: 'select', options: this.get('countryOptions') });
return RSVP.resolve(fields);
},
Expand Down
64 changes: 64 additions & 0 deletions app/templates/components/campaign/-analytics.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<div class="card-header">
{{form.name}}
</div>

<div class="card-block">
{{#if loading}}
<small class="text-muted">Loading data, please wait...</small>
{{#-bs/progress}}
{{-bs/progress/bar value=100 animated=true}}
{{/-bs/progress}}
{{else}}
<div class="card-deck">
<div class="card mb-3">
<div class="card-block">
<p class="mb-0"><span class="display-4">{{ report.actions.render.count }}</span><br>Inserted</p>
</div>
</div>
<div class="card mb-3">
<div class="card-block">
<p class="mb-0"><span class="display-4">{{ report.actions.view.count }}</span><br>Viewed</p>
</div>
</div>
<div class="card mb-3">
<div class="card-block">
<p class="mb-0"><span class="display-4">{{ report.actions.focus.count }}</span><br>Focused</p>
</div>
</div>
<div class="card mb-3">
<div class="card-block">
<p class="mb-0"><span class="display-4">{{ report.actions.submit.count }}</span><br>Submitted</p>
</div>
</div>
{{!-- <div class="card mb-3">
<div class="card-block">
<p class="mb-0"><span class="display-4">{{ report.conversion }}</span> C/R</p>
</div>
</div> --}}
</div>
{{#if report.submissions.length}}
<div class="table-responsive">
<table class="table table-bordered table-sm mb-0">
<thead>
<tr>
<th>Date</th>
{{#each report.labels as |label|}}
<th>{{ label }}</th>
{{/each}}
</tr>
</thead>
<tbody>
{{#each report.submissions as |submission|}}
<tr>
<td>{{ submission.date }}</td>
{{#each report.labels as |label|}}
<td>{{ get submission.values label }}</td>
{{/each}}
</tr>
{{/each}}
</tbody>
</table>
</div>
{{/if}}
{{/if}}
</div>
10 changes: 10 additions & 0 deletions app/templates/components/campaign/email-signup/manage.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
Embed
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#email-signup-analytics" data-toggle="pill" role="tab">
Analytics
</a>
</li>
</ul>
</div>

Expand All @@ -50,6 +55,11 @@
type="campaign-email-signup"
}}
</div>
<div class="tab-pane" id="email-signup-analytics" role="tabpanel">
{{#each campaign.forms as |form|}}
{{campaign/-analytics form=form campaignId=campaign.id}}
{{/each}}
</div>
</div>

<div class="card-footer">
Expand Down
10 changes: 10 additions & 0 deletions app/templates/components/campaign/gated-content/manage.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
Embed
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#gated-content-analytics" data-toggle="pill" role="tab">
Analytics
</a>
</li>
</ul>
</div>

Expand All @@ -50,6 +55,11 @@
type="campaign-gated-content"
}}
</div>
<div class="tab-pane" id="gated-content-analytics" role="tabpanel">
{{#each campaign.forms as |form|}}
{{campaign/-analytics form=form campaignId=campaign.id}}
{{/each}}
</div>
</div>

<div class="card-footer">
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"bootstrap": "v4.0.0-alpha.6",
"Ionicons": "ionicons#^2.0.1",
"bootswatch": "https://github.com/thomaspark/bootswatch.git#v4"
"bootswatch": "https://github.com/thomaspark/bootswatch.git#v4",
"highcharts": "^5.0.12"
}
}
2 changes: 2 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module.exports = function(defaults) {
app.import(path.join(app.bowerDirectory, 'bootstrap/dist/js/bootstrap.min.js'));
app.import(path.join(app.bowerDirectory, 'bootstrap/dist/css/bootstrap.min.css.map'), { destDir : 'assets' });

app.import(path.join(app.bowerDirectory, 'highcharts/highcharts.js'));

var icons = new Funnel(path.join(app.bowerDirectory, 'Ionicons/fonts'), {
srcDir: '/',
include: ['**/*.svg', '**/*.eot', '**/*.ttf', '**/*.woff'],
Expand Down

0 comments on commit 88c9f79

Please sign in to comment.