getCampaignDetails method

Map<String, dynamic> getCampaignDetails()

Get Campaign Details from RemoteMessage.

Implementation

Map<String, dynamic> getCampaignDetails() {
  Map<String, dynamic> result = <String, dynamic>{
    'pi_pn_campaignName': "",
    'pi_pn_campaignSource': "",
    'pi_pn_campaignId': ""
  };

  if (data.isNotEmpty) {
    String targetUrl = data['targetUrl'] ?? "";
    String campaignName = data["campaignName"] ?? "";
    String campaignSource = data["campaignSource"] ?? "";
    String campaignId = data["campaign_id"] ?? "";
    if (targetUrl.isNotEmpty) {
      final uri = Uri.parse(targetUrl);
      final queryParams = uri.queryParameters;
      campaignName = queryParams["campaignName"] ?? campaignName;
      campaignSource = queryParams["campaignSource"] ?? campaignSource;
      campaignId = queryParams["campaignId"] ?? campaignId;
    }
    result["pi_pn_campaignName"] = campaignName;
    result["pi_pn_campaignSource"] = campaignSource;
    result["pi_pn_campaignId"] = campaignId;
  }

  return result;
}