summaryrefslogtreecommitdiff
path: root/Postman/Postman-Mail/sendgrid/vendor/sendgrid/sendgrid/lib/mail/Ganalytics.php
blob: 2d5118839dc9b9b493f209cff0d1b3477c420f1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?php
/**
 * This helper builds the Ganalytics object for a /mail/send API call
 *
 * PHP Version - 5.6, 7.0, 7.1, 7.2
 *
 * @package   SendGrid\Mail
 * @author    Elmer Thomas <dx@sendgrid.com>
 * @copyright 2018-19 Twilio SendGrid
 * @license   https://opensource.org/licenses/MIT The MIT License
 * @version   GIT: <git_id>
 * @link      http://packagist.org/packages/sendgrid/sendgrid
 */

namespace SendGrid\Mail;

/**
 * This class is used to construct a Ganalytics object for the /mail/send API call
 *
 * @package SendGrid\Mail
 */
class Ganalytics implements \JsonSerializable
{
    /** @var $enable bool Indicates if this setting is enabled */
    private $enable;
    /** @var $utm_source string Name of the referrer source. (e.g. Google, SomeDomain.com, or Marketing Email) */
    private $utm_source;
    /** @var $utm_medium string Name of the marketing medium. (e.g. Email) */
    private $utm_medium;
    /** @var $utm_term string Used to identify any paid keywords */
    private $utm_term;
    /** @var $utm_content string Used to differentiate your campaign from advertisements */
    private $utm_content;
    /** @var $utm_campaign string The name of the campaign */
    private $utm_campaign;

    /**
     * Optional constructor
     *
     * @param bool|null $enable Indicates if this setting is enabled
     * @param string|null $utm_source Name of the referrer source. (e.g.
     *                                  Google, SomeDomain.com, or Marketing Email)
     * @param string|null $utm_medium Name of the marketing medium. (e.g. Email)
     * @param string|null $utm_term Used to identify any paid keywords
     * @param string|null $utm_content Used to differentiate your campaign from
     *                                  advertisements
     * @param string|null $utm_campaign The name of the campaign
     */
    public function __construct(
        $enable = null,
        $utm_source = null,
        $utm_medium = null,
        $utm_term = null,
        $utm_content = null,
        $utm_campaign = null
    )
    {
        if (isset($enable)) {
            $this->setEnable($enable);
        }
        if (isset($utm_source)) {
            $this->setCampaignSource($utm_source);
        }
        if (isset($utm_medium)) {
            $this->setCampaignMedium($utm_medium);
        }
        if (isset($utm_term)) {
            $this->setCampaignTerm($utm_term);
        }
        if (isset($utm_content)) {
            $this->setCampaignContent($utm_content);
        }
        if (isset($utm_campaign)) {
            $this->setCampaignName($utm_campaign);
        }
    }

    /**
     * Update the enable setting on a Ganalytics object
     *
     * @param bool $enable Indicates if this setting is enabled
     * 
     * @throws TypeException
     */ 
    public function setEnable($enable)
    {
        if (!is_bool($enable)) {
            throw new TypeException('$enable must be of type bool.');
        }
        $this->enable = $enable;
    }

    /**
     * Retrieve the enable setting on a Ganalytics object
     *
     * @return bool
     */
    public function getEnable()
    {
        return $this->enable;
    }

    /**
     * Add the campaign source to a Ganalytics object
     *
     * @param string $utm_source Name of the referrer source. (e.g.
     *                           Google, SomeDomain.com, or Marketing Email)
     * 
     * @throws TypeException
     */ 
    public function setCampaignSource($utm_source)
    {
        if (!is_string($utm_source)) {
            throw new TypeException('$utm_source must be of type string.');
        }
        $this->utm_source = $utm_source;
    }

    /**
     * Return the campaign source from a Ganalytics object
     *
     * @return string
     */
    public function getCampaignSource()
    {
        return $this->utm_source;
    }

    /**
     * Add the campaign medium to a Ganalytics object
     *
     * @param string $utm_medium Name of the marketing medium. (e.g. Email)
     * 
     * @throws TypeException
     */ 
    public function setCampaignMedium($utm_medium)
    {
        if (!is_string($utm_medium)) {
            throw new TypeException('$utm_medium must be of type string.');
        }
        $this->utm_medium = $utm_medium;
    }

    /**
     * Return the campaign medium from a Ganalytics object
     *
     * @return string
     */
    public function getCampaignMedium()
    {
        return $this->utm_medium;
    }

    /**
     * Add the campaign term to a Ganalytics object
     *
     * @param string $utm_term Used to identify any paid keywords
     * 
     * @throws TypeException
     */ 
    public function setCampaignTerm($utm_term)
    {
        if (!is_string($utm_term)) {
            throw new TypeException('$utm_term must be of type string');
        }
        $this->utm_term = $utm_term;
    }

    /**
     * Return the campaign term from a Ganalytics object
     *
     * @return string
     */
    public function getCampaignTerm()
    {
        return $this->utm_term;
    }

    /**
     * Add the campaign content to a Ganalytics object
     *
     * @param string $utm_content Used to differentiate your campaign from
     *                            advertisements
     * 
     * @throws TypeException
     */ 
    public function setCampaignContent($utm_content)
    {
        if (!is_string($utm_content)) {
            throw new TypeException('$utm_content must be of type string.');
        }
        $this->utm_content = $utm_content;
    }

    /**
     * Return the campaign content from a Ganalytics object
     *
     * @return string
     */
    public function getCampaignContent()
    {
        return $this->utm_content;
    }

    /**
     * Add the campaign name to a Ganalytics object
     *
     * @param string $utm_campaign The name of the campaign
     * 
     * @throws TypeException
     */ 
    public function setCampaignName($utm_campaign)
    {
        if (!is_string($utm_campaign)) {
            throw new TypeException('$utm_campaign must be of type string.');
        }
        $this->utm_campaign = $utm_campaign;
    }

    /**
     * Return the campaign name from a Ganalytics object
     *
     * @return string
     */
    public function getCampaignName()
    {
        return $this->utm_campaign;
    }

    /**
     * Return an array representing a Ganalytics object for the Twilio SendGrid API
     *
     * @return null|array
     */
    public function jsonSerialize()
    {
        return array_filter(
            [
                'enable' => $this->getEnable(),
                'utm_source' => $this->getCampaignSource(),
                'utm_medium' => $this->getCampaignMedium(),
                'utm_term' => $this->getCampaignTerm(),
                'utm_content' => $this->getCampaignContent(),
                'utm_campaign' => $this->getCampaignName()
            ],
            function ($value) {
                return $value !== null;
            }
        ) ?: null;
    }
}