Does Targeted Notification  Works in WebView App?

I will give you a brief about the enabling targeted Notifications in WebView apps in the best way. After you implemented these steps to your WebView app, you will be able to push targeted notification to your users.

What is Targeted Notification?

Targeted notifications are notifications that are sent to a specific individual user based on its behavior, preferences, or other relevant criteria. These notifications are designed to be more relevant and personalized.

How to Enable Targeted Notifications for WebView Apps?

Note: In this tutorial, I will assume you are using Firebase for pushing notification, and your domain address is https://webvify.app.

Firstly, you need to have the FCM registration token of the user to push notification to the user’s device. This token is produced on the application, and need to be transferred from the application to your website’s database to use it.

To transfer the token, you can add the token to the initial link of the application like below.

Initial URL: https://webvify.app?firebase_token={FCM_TOKEN_VALUE}

Then, you will be able to access the token once the user enter to the website via the application. After user login, you will understand whom the token belongs to, then save it to the database.

Finally, you can use the user’s token to push a targeted notification to him/her. The targeted notification will be only received to the token’s owner, not everyone.

Here is the code for pushing targeted notification via PHP.

<?php
    $url = 'https://fcm.googleapis.com/fcm/send';


    # Please visit below website to learn how to get Cloud Messaging API (Legacy) for your firebase project
    # https://www.youtube.com/watch?v=iOJGtKmk6tk
    $api_key = 'Paste Cloud Messaging API (Legacy) to here';

    $fields = array(
        # Firebase Device Token
        'registration_ids' => array(
            "Firebase-token"
        ),
        'notification' => array(
            "body" => "Hello from php",
            "title" => "Title from php",
            "image" => "image",
        ),
        'data' => array(
            "link" => "link",
        ),
    );

    $headers = array(
        'Content-Type:application/json',
        'Authorization:key=' . $api_key
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('FCM Send Error: ' . curl_error($ch));
    }
    curl_close($ch);
    echo $result;
?>

You can use the above code to pushing targeted notification to a specific user via PHP. If you are using another programing language, you find the same functional code by googling about it.

In Webvify, we are giving support about the targeted notification. If you want, we can convert your website to mobile app, and add push targeted notification feature to it. Furthermore, we provide an end-to-end solution from developing apps to publishing them to Google Play & App Store. Besides, It guarantees you 100% app approval by the storesand you gonna pay after the apps are published in the stores.

We are waiting for you,

Thanks.

By Ömer Bayrak

Senior Mobile Developer

Leave a Reply

Your email address will not be published. Required fields are marked *