你有没有人成功地将Moengage整合到ReactJs中?我已经尝试将它放在HTMLWebpackPlugin模板的index.html上的<head>
标记内。
<script type="text/javascript">
(function(i,s,o,g,r,a,m,n){
i['moengage_object']=r;t={}; q = function(f){return function(){(i['moengage_q']=i['moengage_q']||[]).push({f:f,a:arguments});};};
f = ['track_event','add_user_attribute','add_first_name','add_last_name','add_email','add_mobile',
'add_user_name','add_gender','add_birthday','destroy_session','add_unique_user_id','moe_events','call_web_push','track','location_type_attribute'];
for(k in f){t[f[k]]=q(f[k]);}
a=s.createElement(o);m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m);
i['moe']=i['moe'] || function(){n=arguments[0];return t;}; a.onload=function(){if(n){i[r] = moe(n);}};
})(window,document,'script','https://cdn.moengage.com/webpush/moe_webSdk.min.latest.js','Moengage');
</script>
我把moengage的配置放在一个名为'moengage.js'的文件中。所以我可以轻松地导入并在另一个文件中使用它。
export const Moengage = moe({
app_id:"APP ID",
debug_logs: 0
});
然后,我在另一个文件中使用它
import { Moengage } from '../config/moengage.js'
...
Moengage.track_event('Loan_Data', {
'loan_name': 'Example name',
'loan_type_id': 123,
})
不幸的是,我的不行。你有没有尝试过使用ReactJs?任何帮助都会很棒。谢谢
变量moe
在窗口中可用,因此将其放入配置文件将不起作用。初始化脚本必须放在<head>
标记中。
您可以在需要时通过moe
访问window
变量。在您的配置文件中,您可以尝试这样的事情:
export const Moengage = window.moe({
app_id:"APP ID",
debug_logs: 0
});
PS。我在MoEngage开发Web SDK。如有任何疑问,请随时通过[email protected]与我们联系。