# CampaignUrlMetric Model

DB Table Name {wp_db_prefix}_fc_campaign_url_metrics
Schema Check Schema
Source File fluent-crm/app/Models/CampaignUrlMetric.php
Name Space FluentCrm\App\Models
Class FluentCrm\App\Models\CampaignUrlMetric

# Attributes

Attribute Data Type Comment
id Integer
url_id Integer
campaign_id Integer
subscriber_id Integer
type String
ip_address String
country String
city String
counter Integer
created_at Date Time
updated_at Date Time

# Usage

Please check Model Basic for Common methods.

# Accessing Attributes


$campaignUrlMatric = FluentCrm\App\Models\CampaignUrlMetric::find(1);

$subsctiber->id; // returns id
$campaignUrlMatric->type; // returns type
.......
1
2
3
4
5
6

# Fillable Attributes


'url_id',
'campaign_id',
'subscriber_id',
'type', unsubscribe / click
'ip_address',
'country',
'city'
1
2
3
4
5
6
7
8

# Relations

This model has the following relationships that you can use

# campaign

Access the associated campaign of a model

  • return FluentCrm\App\Models\Campaign Model Collection

# Example:

// Accessing Campaign
$campaignUrlMatric = $campaignUrlMatric->campaign;

// For Filtering by campaign relationship

// Get CampaignUrlMetrics which has type: funnel_email_campaign
$campaignUrlMatrics = FluentCrm\App\Models\CampaignUrlMetric::whereHas('campaign', function($query) {
    $query->where('type', 'funnel_email_campaign');
})->get();

// Get CampaignUrlMetrics which does not have type: funnel_email_campaign
$campaignUrlMatrics = FluentCrm\App\Models\CampaignUrlMetric::whereDoesntHave('campaign', function($query) {
    $query->where('type', 'funnel_email_campaign');
})->get();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# subscriber

Access the associated subscriber of a model

  • return FluentCrm\App\Models\Subscriber Model Collection

# Example:

// Accessing Subscriber
$campaignUrlMatric = $campaignUrlMatric->subscriber;

// For Filtering by subscriber relationship

// Get CampaignUrlMetrics which has first_name: Demo
$campaignUrlMatrics = FluentCrm\App\Models\CampaignUrlMetric::whereHas('subscriber', function($query) {
    $query->where('first_name', 'Demo');
})->get();

// Get CampaignUrlMetrics which does not have first_name: Demo
$campaignUrlMatrics = FluentCrm\App\Models\CampaignUrlMetric::whereDoesntHave('subscriber', function($query) {
    $query->where('first_name', 'Demo');
})->get();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# Methods

Along with Global Model methods, this model has few helper methods.

# maybeInsert($data)

Store or update campaign url matrix data

  • Parameters
    • $data array campaign url matrix data
  • Returns \FluentCrm\App\Models\CampaignUrlMetric

# Usage

$campaignUrlMatric = CampaignUrlMatric::maybeInsert($data);
1

# getLinksReport($campaignId)

Get Links report by campaign id

  • Parameters
    • $campaignId int
  • Returns array

# Usage

$linksReport = $campaignUrlMatric->getLinksReport(1);
1

# getCampaignAnalytics($campaignId)

Get campaign analytics from this model by campaign ID

  • Parameters
    • $campaignId int
  • Returns array

# Usage

$analytics = $campaignUrlMatric->getCampaignAnalytics(1);
1

# getSubjectStats($campaign)

Get subject stats from this model by campaign

  • Parameters
    • $campaign \FluentCrm\App\Models\Campaign
  • Returns array

# Usage

$stats = $campaignUrlMatric->getSubjectStats($campaign);
1