Add view and click counts to campaign API response and UI

This commit is contained in:
Kailash Nadh 2018-12-18 23:46:29 +05:30
parent a4135be9c7
commit f54170d509
3 changed files with 8 additions and 3 deletions

View File

@ -225,8 +225,8 @@ class Campaigns extends React.PureComponent {
<Row><Col className="label" span={10}>Rate</Col><Col span={12}>{ Math.round(rate, 2) } / min</Col></Row> <Row><Col className="label" span={10}>Rate</Col><Col span={12}>{ Math.round(rate, 2) } / min</Col></Row>
} }
<Row><Col className="label" span={10}>Views</Col><Col span={12}>0</Col></Row> <Row><Col className="label" span={10}>Views</Col><Col span={12}>{ record.views }</Col></Row>
<Row><Col className="label" span={10}>Clicks</Col><Col span={12}>0</Col></Row> <Row><Col className="label" span={10}>Clicks</Col><Col span={12}>{ record.clicks }</Col></Row>
<br /> <br />
<Row><Col className="label" span={10}>Created</Col><Col span={12}>{ dayjs(record.created_at).format(cs.DateFormat) }</Col></Row> <Row><Col className="label" span={10}>Created</Col><Col span={12}>{ dayjs(record.created_at).format(cs.DateFormat) }</Col></Row>

View File

@ -136,6 +136,8 @@ type Campaign struct {
MessengerID string `db:"messenger" json:"messenger"` MessengerID string `db:"messenger" json:"messenger"`
Lists types.JSONText `json:"lists"` Lists types.JSONText `json:"lists"`
View int `db:"views" json:"views"`
Clicks int `db:"clicks" json:"clicks"`
// TemplateBody is joined in from templates by the next-campaigns query. // TemplateBody is joined in from templates by the next-campaigns query.
TemplateBody string `db:"template_body" json:"-"` TemplateBody string `db:"template_body" json:"-"`
Tpl *template.Template `json:"-"` Tpl *template.Template `json:"-"`

View File

@ -255,7 +255,7 @@ INSERT INTO campaign_lists (campaign_id, list_id, list_name)
-- name: get-campaigns -- name: get-campaigns
-- Here, 'lists' is returned as an aggregated JSON array from campaign_lists because -- Here, 'lists' is returned as an aggregated JSON array from campaign_lists because
-- the list reference may have been deleted. -- the list reference may have been deleted.
SELECT campaigns.*, ( SELECT campaigns.*, COUNT(campaign_views.campaign_id) AS views, COUNT(link_clicks.campaign_id) AS clicks, (
SELECT COALESCE(ARRAY_TO_JSON(ARRAY_AGG(l)), '[]') FROM ( SELECT COALESCE(ARRAY_TO_JSON(ARRAY_AGG(l)), '[]') FROM (
SELECT COALESCE(campaign_lists.list_id, 0) AS id, SELECT COALESCE(campaign_lists.list_id, 0) AS id,
campaign_lists.list_name AS name campaign_lists.list_name AS name
@ -263,7 +263,10 @@ SELECT campaigns.*, (
) l ) l
) AS lists ) AS lists
FROM campaigns FROM campaigns
LEFT JOIN campaign_views ON (campaign_views.campaign_id = campaigns.id)
LEFT JOIN link_clicks ON (link_clicks.campaign_id = campaigns.id)
WHERE ($1 = 0 OR id = $1) AND status=(CASE WHEN $2 != '' THEN $2::campaign_status ELSE status END) WHERE ($1 = 0 OR id = $1) AND status=(CASE WHEN $2 != '' THEN $2::campaign_status ELSE status END)
GROUP BY campaigns.id
ORDER BY created_at DESC OFFSET $3 LIMIT $4; ORDER BY created_at DESC OFFSET $3 LIMIT $4;
-- name: get-campaign-for-preview -- name: get-campaign-for-preview