如何使用Web(JS)在OneSignal中设置external_user_id?
我注意到,当任何用户首次加载我的Web应用程序时,OneSignal正在创建唯一的 player_id ,并在其数据库中添加列。
我正在尝试使用以下代码将自定义 external_user_id 添加到同一信号db字段中(按 onsignal docs ):
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" ></script>
<script>
let externalUserId = "123456789";
OneSignal.push(function() {
OneSignal.setExternalUserId(externalUserId);
});
</script>
但是,某种程度上, external_user_id field仍设置为空。
因此,我在其中添加了以下代码。
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" ></script>
<script>
let externalUserId = "123456789";
window.OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.init({
appId: "xoxoxoxoxoxoxoxoxo",
});
});
OneSignal.push(function() {
console.log("triggering");
OneSignal.setExternalUserId(externalUserId);
console.log("triggering");
});
它没有错误,但 external_user_id 仍未更新。
这是我添加到 android Studio 的Insignal代码
package com.appgrep.xoxoxo;
import android.app.Application;
public class OneSignal extends Application {
private static final String ONESIGNAL_APP_ID = "xoxoxoxoxoxoxoxoxo";
@Override
public void onCreate() {
super.onCreate();
// OneSignal Initialization
com.onesignal.OneSignal.initWithContext(this);
com.onesignal.OneSignal.setAppId(ONESIGNAL_APP_ID);
}
}
我只是尝试使用 web(js) 任何帮助将不胜感激。
Amit的建议获得用户ID
var OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.getUserId(function(userId) {
console.log("OneSignal User ID:", userId);
$("#some").text(userId);
});
});
getUserid
函数不是触发。
我可以喜欢:
var OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.on('subscriptionChange', function (isSubscribed) {
OneSignal.push(function() {
OneSignal.getUserId(function(userId) {
console.log("OneSignal User ID:", userId);
});
});
});
});
但是在我的情况下,没有订阅,所有用户在打开网络应用程序后立即注册一个信号,并且订阅是自动挑选的。
I noticed that OneSignal is creating a unique player_id and adding a column in its database when my web app is loaded for the first time by any user.
I'm trying to add a custom external_user_id into the same one signal DB field using below code (as per OneSignal docs):
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" ></script>
<script>
let externalUserId = "123456789";
OneSignal.push(function() {
OneSignal.setExternalUserId(externalUserId);
});
</script>
But somehow, the external_user_id field is still set to empty.
So I added the below code to it.
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" ></script>
<script>
let externalUserId = "123456789";
window.OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.init({
appId: "xoxoxoxoxoxoxoxoxo",
});
});
OneSignal.push(function() {
console.log("triggering");
OneSignal.setExternalUserId(externalUserId);
console.log("triggering");
});
It has no errors, yet external_user_id is still not updated.
This is the OneSignal code I have added to my Android Studio
package com.appgrep.xoxoxo;
import android.app.Application;
public class OneSignal extends Application {
private static final String ONESIGNAL_APP_ID = "xoxoxoxoxoxoxoxoxo";
@Override
public void onCreate() {
super.onCreate();
// OneSignal Initialization
com.onesignal.OneSignal.initWithContext(this);
com.onesignal.OneSignal.setAppId(ONESIGNAL_APP_ID);
}
}
I just am trying to add External_User_Id in OneSignal using Web (JS)
Any help is greatly appreciated.
Amit's suggestion to get a user id
var OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.getUserId(function(userId) {
console.log("OneSignal User ID:", userId);
$("#some").text(userId);
});
});
the getUserId
function is not triggereing.
I can do like:
var OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.on('subscriptionChange', function (isSubscribed) {
OneSignal.push(function() {
OneSignal.getUserId(function(userId) {
console.log("OneSignal User ID:", userId);
});
});
});
});
But in my scenario, there is no subscription, all users are registered in one signal as soon as their open the web app and the subscription is auto-ticked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试使用Web(JS)设置external_user_id,并且毫无问题地工作正常。
要求
现在只需打开Dev Console并粘贴以下代码设置external_user_id
现在检查external_user_id是否设置了
请参阅Dev Console的屏幕截图
另外,请访问OneSignal仪表板并检查用户,您将external_user_id只需确保使外部_USER_ID列可见,
检查仪表板图像中的external_user_id
使用测试完成时,请删除demo externe_user_id
文档:< “ https://documentation.onesignal.com/docs/external-user-ids” rel =“ nofollow noreferrer”> https://documentation.onesignal.com/docs/external-user-user-ids
请注意,如果您要通过Android SDK设置external_user_id,并且想在Web上更新它
使用以下代码
替换&lt; app_id&gt;使用页面的应用程序ID
I have tried setting external_user_id using web(js) and it's working fine without problem.
Requirement
Now just open the Dev console and paste the following code to set external_user_id
Now check if external_user_id is set or not
See screenshot of dev console
alternatively, visit OneSignal dashboard and check the user, you will external_user_id just make sure to make external_user_id column visible,
Check external_user_id in dashboard image
When done with your testing remove the demo external_user_id
Documentation: https://documentation.onesignal.com/docs/external-user-ids
Just keep in mind if you are setting External_user_id through Android SDK and want to update it on web
Use the following code
Replace <APP_ID> with your app app id of the page
我认为通过Web Buddy不可能。
您要做的就是使用网站更新Oneignl中的字段。我认为这不是一个信号,让您做。
I think it's not possible through web buddy.
What you are trying to do is to update a field in onesignl using website. Which i don't think one signal let's you do.