इसके माध्यम से साझा किया गया


मोबाइल डिवाइस पर पुश नोटिफिकेशन प्राप्त करना

Customer Insights - Journeysमें पुश नोटिफ़िकेशन सेट अप करने के समग्र दृष्टिकोण के बारे में अधिक जानने के लिए, पुश नोटिफ़िकेशन सेटअप अवलोकन पर जाएँ

Customer Insights - Journeysमें पुश नोटिफिकेशन सक्षम करने के लिए, आपको निम्नलिखित चरण पूरे करने होंगे:

  1. पुश सूचना अनुप्रयोग कॉन्फ़िगरेशन
  2. पुश सूचनाओं के लिए उपयोगकर्ता मैपिंग
  3. पुश नोटिफिकेशन के लिए डिवाइस पंजीकरण
  4. उपकरणों पर पुश सूचनाएं प्राप्त करना
  5. पुश सूचनाओं के लिए सहभागिता रिपोर्टिंग

महत्त्वपूर्ण

प्राप्तकर्ताओं द्वारा सूचनाओं में खोले गए लिंक को ट्रैक करने के लिए, आपको ग्राहक ट्रैकिंग सहमति एकत्र करनी होगी. ग्राहक सहमति एकत्र करने की रणनीतियों के बारे में अधिक जानें Customer Insights - Journeys: सहमति प्रबंधन अवलोकन

यदि आपने ट्रैकिंग सहमति एकत्र नहीं की है, तो आपको नीचे कोड स्निपेट में वर्णित originalLink URL फ़ील्ड का उपयोग करना होगा। यदि आपने सहमति प्राप्त कर ली है, तो आप लिंक फ़ील्ड मान का उपयोग कर सकते हैं, जिसे ट्रैक किया जा सकता है।

PushLinkClicked स्वचालित रूप से उत्पन्न होता है. यूआरएल एक रीडायरेक्ट लिंक है जो लिंक फ़ील्ड से लिंक का उपयोग किए जाने पर इंटरैक्शन बनाता है।

पुश संदेश अधिसूचनाएं प्राप्त करें iOS

1. iOS में आने वाली सूचनाओं को पार्स करने के लिए नमूना कोड स्निपेट:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{

// Print full message
    NSString *urlString = [[userInfo valueForKey:@"data"] valueForKey:@"link"];
    NSString *originalUrlString = [[userInfo valueForKey:@"data"] valueForKey:@"originalLink"];
    NSString *trackingIdString = [[userInfo valueForKey:@"data"] valueForKey:@"trackingId"];
    
    if(![urlString isEqual:[NSNull null]])
    {
        if([urlString length] != 0)
        {
            [self createInteraction:[NSNumber numberWithInt:0] stringTracking:trackingIdString];
            
            NSURL *url = [NSURL URLWithString:urlString];
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10) {
                
// iOS 10 and above
                [[UIApplication sharedApplication] openURL:url options:[NSDictionary dictionary] completionHandler:nil];
            }
            else
            {
                [[UIApplication sharedApplication] openURL:url]; // iOS <10
            }
        }
    }
    else
    {
        [self createInteraction:[NSNumber numberWithInt:1] stringTracking:trackingIdString];
    }
}

iOS (स्विफ्ट संस्करण) में आने वाली सूचनाओं को पार्स करने के लिए नमूना कोड स्निपेट:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse,  withCompletionHandler completionHandler: @escaping () -> Void) { 

        let userInfo = response.notification.request.content.userInfo 
        let data = userInfo["data"] as? [String:Any] ?? [:]; 
        print("User info \(userInfo)") 
        let urlString = data["link"] as? String; 
        let trackingIdString = data["trackingId"] as? String; 

        if(urlString != nil && !urlString!.isEmpty) 
        { 

            self.createInteraction(typeInteraction:0, trackingId:trackingIdString ?? ""); 

            if let url = URL(string: urlString ?? ""), UIApplication.shared.canOpenURL(url) { 

                UIApplication.shared.open(url) 
            } 
        } 
        else 
        { 
            self.createInteraction(typeInteraction:1, trackingId:trackingIdString ?? ""); 
        } 
        // Always call the completion handler when done. 
        completionHandler() 
    } 

2. iOS (छवि के साथ अधिसूचना) में आने वाली रिच पुश सूचनाओं को पार्स करने के लिए नमूना स्विफ्ट कोड स्निपेट:

didReceive में AppDelegateविधि के अतिरिक्त, हमें प्रदर्शित होने से पहले अधिसूचना को रोकने, छवि को डाउनलोड करने और छवि डेटा के साथ अधिसूचना को समृद्ध करने के लिए NotificationExtension जोड़ने की आवश्यकता है। अधिक जानें: UNNotificationServiceExtension

class NotificationService: UNNotificationServiceExtension { 
    var contentHandler: ((UNNotificationContent) -> Void)? 
    var content: UNMutableNotificationContent? 
    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { 
        self.contentHandler = contentHandler 
        self.content        = (request.content.mutableCopy() as? UNMutableNotificationContent) 
        if let bca = self.content { 
            func save(_ identifier: String, 
                      data: Data, options: [AnyHashable: Any]?) -> UNNotificationAttachment? { 
                    let directory = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(ProcessInfo.processInfo.globallyUniqueString, isDirectory: true) 
                    do { 
                        try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true, attributes: nil) 
                        let fileURL = directory.appendingPathComponent(identifier) 
                        try data.write(to: fileURL, options: []) 
                        return try UNNotificationAttachment.init(identifier: identifier, url: fileURL, options: options) 
                    } catch {} 
                    return nil 
            } 
            func exitGracefully(_ reason: String = "") { 
                let bca    = request.content.mutableCopy() as? UNMutableNotificationContent 
                bca!.title = reason 
                contentHandler(bca!) 
            }
            DispatchQueue.main.async { 
                guard let content = (request.content.mutableCopy() as? UNMutableNotificationContent) else { 
                    return exitGracefully() 
                } 
                let userInfo : [AnyHashable: Any] = request.content.userInfo; 
                let data = userInfo["data"] as? [String:Any] ?? [:]; 
                guard let attachmentURL = data["imageUrl"] as? String else { 
                    return exitGracefully() 
                } 
                guard let imageData = try? Data(contentsOf: URL(string: attachmentURL)!) else { 
                    return exitGracefully() 
                } 
                guard let attachment = save("image.png", data: imageData, options: nil) else { 
                    return exitGracefully() 
                } 
                content.attachments = [attachment] 
                contentHandler(content) 
            } 
        } 
    }   
    override func serviceExtensionTimeWillExpire() { 
        // Called just before the extension will be terminated by the system. 
        // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. 
        if let contentHandler = contentHandler, let bestAttemptContent =  content { 
            contentHandler(bestAttemptContent) 
        } 
    } 
}

में सूचनाएं प्राप्त करें Android

आने वाली सूचनाओं को पार्स करने के लिए नमूना कोड स्निपेट Android

भाग 1: अधिसूचना संदेश से ट्रैकिंग आईडी प्राप्त करना

नोट

Customer Insights - Journeys अधिसूचना प्रारूप के स्थान पर डेटा संदेश प्रारूप का उपयोग करता है। इसके लिए क्लाइंट ऐप को सही लिंक (ट्रैक किए गए या ट्रैक न किए गए) को निकालने के लिए Customer Insights - Journeys द्वारा भेजे गए डेटा पेलोड को पार्स करना आवश्यक है। अधिक जानें: FCM संदेशों के बारे में

OnMessageReceived की FirebaseMessagingService विधि को ओवरराइड करें और पेलोड से आवश्यक डेटा निकालें जैसा कि दिखाया गया है:

@Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
         
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ 
        Log.d(TAG, "From: " + remoteMessage.getFrom()); 
        String message = null; 
        String title = null; 
        String deepLink = null; 
        String name = null; 
        String trackingId = null; 

        String imageUrl = null; 
         
// Check if message contains a notification payload. 
        if (remoteMessage.getNotification() != null) { 
            message = remoteMessage.getNotification().getBody(); 
            title = remoteMessage.getNotification().getTitle(); 
        } 
         
// Check if message contains a data payload. 
        if (remoteMessage.getData().size() > 0) { 
            if (remoteMessage.getData().get("title") != null) { 
                title = remoteMessage.getData().get("title"); 
            } 
            if (remoteMessage.getData().get("body") != null) { 
                message = remoteMessage.getData().get("body"); 
            } 

if (remoteMessage.getData().get("imageUrl") != null) { 
    imageUrl = remoteMessage.getData().get("imageUrl"); 
} 

// If tracking consent has been taken, use link otherwise use 'originalLink' 
            if (remoteMessage.getData().get("link") != null) { 
                deepLink = remoteMessage.getData().get("link"); 
            } 
            if (remoteMessage.getData().containsKey("trackingId")) { 
                trackingId = remoteMessage.getData().get("trackingId"); 
            } 
        } 
        if (message != null || title != null) { 
            sendNotification(message, title, imageUrl, deepLink, name, trackingId); 
        } else { 
            Log.d(TAG, "Empty Notification Received"); 
        } 
    } 

भाग 2: अधिसूचना बनाएँ

अधिसूचना खोलने पर ईवेंट उत्पन्न करने के लिए अधिसूचना सामग्री बनाएं और डेटा में ट्रैकिंग आईडी जोड़ें।

private void sendNotification(String message, String title, String deeplink, String name, String trackingId) { 
    NotificationManager notificationManager = (NotificationManager) 
        this.getSystemService(Context.NOTIFICATION_SERVICE); 
 
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( 
        this, 
        NOTIFICATION_CHANNEL_ID) 
        .setContentText(message) 
        .setContentTitle(title)              .setLargeIcon(getBitmapFromURL((imageUrl))) 
        .setPriority(NotificationCompat.PRIORITY_HIGH) 
        .setSmallIcon(android.R.drawable.ic_popup_reminder) 
        .setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL) 
        .setContentIntent(createContentIntent(this, deeplink, name, trackingId)) 
        .setDeleteIntent(createOnDismissedIntent(this, trackingId)) 
        .setStyle(new NotificationCompat.BigTextStyle() 
            .bigText(message)); 
 
    notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); 
} 
 
private PendingIntent createOnDismissedIntent(Context context, String trackingId) { 
    Intent intent = new Intent(context, NotificationDismissalReceiver.class); 
    intent.putExtra("TrackingId", trackingId); 
 
    return PendingIntent.getBroadcast(context.getApplicationContext(),0, intent, 0); 
} 
 
private PendingIntent createContentIntent(Context context, String deeplink, String name, String trackingId) { 
    Intent intent; 
 
    if (deeplink != null) { 
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(deeplink)); 
    } else { 
        intent = new Intent(this, MainActivity.class); 
    } 
    Bundle pushData = new Bundle(); 
    pushData.putString("name", name); 
 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    intent.putExtras(pushData); 
    intent.putExtra("Source", "Notification"); 
    intent.putExtra("TrackingId", trackingId); 
 
    return PendingIntent.getActivity(this, NOTIFICATION_ID, intent, PendingIntent.FLAG_ONE_SHOT); 
} 
 
public static Bitmap getBitmapFromURL(String src) { 
    try { 
        URL url = new URL(src); 
        HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
        connection.setDoInput(true); 
        connection.connect(); 
        InputStream input = connection.getInputStream(); 
        Bitmap myBitmap = BitmapFactory.decodeStream(input); 
        return myBitmap; 
    } catch (IOException e) { 
        // Log exception 
        return null; 
    } 
} 

भाग 3: एक अधिसूचना खोला घटना उत्पन्न करें

ट्रैकिंग आईडी प्राप्त करने के लिए अधिसूचना के माध्यम से आवेदन खोलें। MainActivity

@Override
        protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        String source = getIntent().getStringExtra("Source"); 
        if (source != null && !source.isEmpty()) 
        { 
            String trackingId = getIntent().getStringExtra("TrackingId"); 
            EventTrackerClient.sendEventToServer(this.getApplicationContext(), trackingId, EventType.Opened); 
        } 
        checkPlayServices(); 
        FirebaseService.createChannelAndHandleNotifications(getApplicationContext());