
This is a Test Ad ID that you need to add in your AndroidManifest.xml file. This is needed or otherwise you'll get a compile-time error when you launch the app:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
exports = async function(authEvent) {
const user = authEvent.user;
const myUserCollection = context.services.get("mongodb-atlas").db("mydb").collection("MyUser");
try {
const existingUser = await myUserCollection.findOne({ ownerId: user.id });
if (!existingUser) {
const newUser = {
ownerId: user.id,
coins: 0,
name: user.data.firstName,
email: user.data.email,
picture: user.data.picture
};
const result = await myUserCollection.insertOne(newUser);
console.log(result)
if (result.insertedId) {
console.log(newUser)
return newUser;
} else {
console.log("Insert failed.");
return null;
}
} else {
console.log("User already exists.");
return null;
}
} catch (error) {
console.error("Error:", error);
return null;
}
};
exports = async function(changeEvent) { try {
if (changeEvent.operationType === "insert") {
const serviceName = "mongodb-atlas";
const databaseName = "mydb";
const myUserCol = "MyUser"
const rewardCol = "Reward"
const ownerId = changeEvent.fullDocument.ownerId
const title = changeEvent.fullDocument.title
const myUserCollection = context.services.get(serviceName).db(databaseName).collection(myUserCol);
const rewardCollection = context.services.get(serviceName).db(databaseName).collection(rewardCol);
const reward = await rewardCollection.findOne({ title: title});
const updateQuery = { ownerId: ownerId };
const updateCoins = { $inc: { coins: -reward.coins } };
await myUserCollection.updateOne(updateQuery, updateCoins);
}
} catch(err) {
console.log("error performing mongodb write: ", err.message);
}
};
In this course I'm gonna teach you how to implement a Reward ad/Digital Coins System in your app with a Server-Side Verification (SSV). This same approach I've used in my own app to allow users to earn digital coins by viewing ads. In return, users can spend those coins, to redeem certain rewards that you want to provide.
We will use:
Admob mobile advertising platform which is developed by Google, to display a reward type of ad in our application. We will configure it to accept a server-side verification.
Google's User Messaging Platform (UMP) to handle the new European Consent Policy. Because if you don't implement it, users from over 30 countries will be able to suspend your ads and reduce a huge amount of money that you can potentially earn.
MongoDB Atlas to host the database where we will store all information about the users and their digital coins. We will handle user and admin permissions, collection schemas, network access list, authentication and database triggers, custom functions and more.
Our own Backend Server which will be used to validate reward ads and add Coins to our users. The server itself should receive requests from the Admob SDK, when a callback fires up after a user successfully completes a task of viewing an ad. That adds an extra layer of security by processing and verifying user actions on the server rather than solely relying on client-side verification. This reduces the risk of manipulation or tampering by malicious users who may attempt to manipulate the client-side verification process to fraudulently claim rewards.
And at the end we will deploy our Backend server so that we can use it in a production as well.
Bottom line, quite interesting topic that opens the door for monetization in your app.