SubscriptionTracking

public struct SubscriptionTracking : Encodable

The SubscriptionTracking class is used to modify the subscription tracking setting on an email.

  • Text to be appended to the email, with the subscription tracking link. You may control where the link is by using the tag <% %>. For example:

    Click here to unsubscribe: <% %>
    

    Declaration

    Swift

    public let text: String?
  • HTML to be appended to the email, with the subscription tracking link. You may control where the link is by using the tag <% %>. For example:

    <p><% Click here %> to unsubscribe.</p>
    

    Declaration

    Swift

    public let html: String?
  • A tag that will be replaced with the unsubscribe URL. For example: [unsubscribe_url]. If this parameter is used, it will override both the text and html parameters. The URL of the link will be placed at the substitution tag’s location, with no additional formatting.

    Declaration

    Swift

    public let substitutionTag: String?
  • A Bool indicating if the setting is enabled or not.

    Declaration

    Swift

    public let enable: Bool
  • Initializes the setting with no templates or substitution tags, effectively disabling the setting. Use this initializer if the subscription tracking setting is enabled on your SendGrid account by default and you want to disable it for this specific email.

    If you want to enable the setting and/or modify the configuration of the setting for this email, use either the init(plainText:html:) or the init(substitutionTag:) initializer instead.

    Declaration

    Swift

    public init()
  • Initializes the setting with a plain text and HTML template to put at the bottom of the email.

    Both templates must use the <% %> tag to indicate where to place the actual unsubscribe link. For instance, this would be a valid template for the plain text template:

    Click here to unsubscribe: <% %>.
    

    …and this would be a valid template for the HTML portion:

    <p><% Click here %> to unsubscribe.</p>
    

    If you want to place the unsubscribe link somewhere other than the bottom of the email, use the init(substitutionTag:) initializer instead.

    If the subscription tracking setting is enabled by default on your SendGrid account and you want to disable it for this email, use the init() initializer instead.

    Declaration

    Swift

    public init(plainText: String, html: String)

    Parameters

    plainText

    Text to be appended to the email, with the subscription tracking link. You may control where the link is by using the tag <% %>.

    html

    HTML to be appended to the email, with the subscription tracking link. You may control where the link is by using the tag <% %>.

  • Initializes the setting with a substitution tag to place the unsubscribe URL at. Note: the tag you specify will be replaced with the unsubscribe URL only, not the templates defined in the setting.

    So for example, if you specified %unsubscribe% as your substitution tag, then in your plain text portion of your email, you would want to have something like this:

    Click here to unsubscribe: %unsubscribe%
    

    …and then in your HTML body you would want something like this:

    <p><a href="%unsubscribe%">Click here</a> to unsubscribe.</p>
    

    Declaration

    Swift

    public init(substitutionTag: String)

    Parameters

    substitutionTag

    A tag to indicate where to place the unsubscribe URL.

  • Validates that the plain text and HTML text contain the proper tag.

    Declaration

    Swift

    public func validate() throws