跳转到主要内容
PRODUCT DOCUMENTS

快速找到所需文档,高效完成接入与排障

浏览产品文档与友盟 Skill,展开目录并阅读正文。

Web云配

Web版云配&AB测试SDK集成文档

1. 集成

在body结束标签前引入jssdk:

  1. <body>
  2. ...
  3. <script src="https://s.cnzz.com/remote-config.js?id=YOUR_SITE_ID"></script>
  4. <script>
  5. window.urc.fetch({
  6. active: true,
  7. callback: function (data) {
  8. console.log('fetch: ', data);
  9. }
  10. });
  11. </script>
  12. </body>

2. 设置默认值

  1. <body>
  2. ...
  3. <script src="https://s.cnzz.com/remote-config.js?id=YOUR_SITE_ID"></script>
  4. <script>
  5. window.urc.setDefaultValues({
  6. test: '123'
  7. });
  8. </script>
  9. </body>

3. 获取远程配置

  1. <body>
  2. ...
  3. <script src="https://s.cnzz.com/remote-config.js?id=YOUR_SITE_ID"></script>
  4. <script>
  5. window.urc.setDefaultValues({
  6. test: '123'
  7. });
  8. window.urc.fetch({
  9. active: true, // true表示获取后立即生效,false表示下次打开页面生效 默认为false
  10. callback: function (data) {
  11. console.log('fetch: ', data);
  12. }
  13. });
  14. </script>
  15. </body>

4. 获取参数值

  1. <body>
  2. ...
  3. <script src="https://s.cnzz.com/remote-config.js?id=YOUR_SITE_ID"></script>
  4. <script>
  5. window.urc.getValue(el.value);
  6. </script>
  7. </body>

5. 手动激活

  1. <body>
  2. ...
  3. <script src="https://s.cnzz.com/remote-config.js?id=YOUR_SITE_ID"></script>
  4. <script>
  5. // 在调用fetch时,如果没有设置立即生效,可在需要时手动激活最近一次fetch获取的参数值
  6. window.urc.active();
  7. </script>
  8. </body>

完整示例

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>云配测试页面</title>
  7. <script type="text/javascript" src="https://v1.cnzz.com/z_stat.php?id=1275041087&web_id=1275041087"></script>
  8. </head>
  9. <body>
  10. <input id="keyInput" type="text">
  11. <button onclick="getValue()">getValue</button>
  12. <script>
  13. function getValue() {
  14. var el = document.getElementById('keyInput');
  15. var value = window.urc.getValue(el.value);
  16. console.log(value);
  17. }
  18. </script>
  19. <script src="https://s.cnzz.com/remote-config.js?id=1275041087"></script>
  20. <script>
  21. window.urc.setDefaultValues({
  22. test: '123'
  23. });
  24. window.urc.fetch({
  25. active: true,
  26. callback: function (data) {
  27. console.log('fetch: ', data);
  28. }
  29. });
  30. </script>
  31. </body>
  32. </html>