将实验插入Google analytics api(gapi) [英] Insert experiment to Google analytics api (gapi)

查看:107
本文介绍了将实验插入Google analytics api(gapi)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过api插入一个实验到Google分析中(使用gapi)

  var experiment = {
name:Testing,
description:test,
status:READY_TO_RUN,
variations:[{
名称:原始,
url:http://abc.se,
},{
名称:变体1,
url:http://abc.se/1,
}],
};
$ b gapi.client.analytics.management.experiments.insert({
'accountId':currentProfile ['accountId'],
'profileId':currentProfile ['profileId'] ,
'webPropertyId':currentProfile ['webPropertyId'],
'resource':experiment
})。execute(callback);

我得到的响应代码是code:500,message:内部错误。,



主要赞赏任何帮助。
(stackoverflow上的第一个问题,如果我的问题很模糊,我会提前道歉。)解决方案

添加参数objectiveMetric。



最终代码:

  var requestBody = {
name:testing2,// required
status:READY_TO_RUN,//必需
objectiveMetric:ga:goal11Completions,/ /需要?
variations:[
{
name:test1,// required
status:ACTIVE,
url: http://abs.se/3//需要
},
{
name:test2,//必需
status:ACTIVE ,
url:http://abs.se/4// required
}
]
};


var request = gapi.client.request({$ b $'path':'/ analytics / v3 / management / accounts / {accountId} / webproperties / {webPropertyId} / profile'/ {profileId} / experiments',
'method':'POST',
'body':JSON.stringify(requestBody)});
request.execute(handleAccounts);
}

非常感谢Pete的帮助。

I'm trying to insert an experiment to Google analytics through their api (using gapi)

var experiment = {
  "name": "Testing",
  "description": "test",
  "status": "READY_TO_RUN",
     "variations": [{
        "name": "Original",
        "url": "http://abc.se",
      }, {
        "name": "Variant 1",
        "url": "http://abc.se/1",
      }],
};

gapi.client.analytics.management.experiments.insert({
  'accountId': currentProfile['accountId'],
  'profileId': currentProfile['profileId'],
  'webPropertyId': currentProfile['webPropertyId'],
  'resource': experiment
}).execute(callback);

The response-code I get is "code": 500, "message": "There was an internal error.",

Any help will be mostly appreciated. (First question on stackoverflow, I apologize in advance if my question is fuzzy.)

解决方案

The solution was to add the parameter "objectiveMetric". Altough it is not specified in the documentation.

final code:

var requestBody = {
  "name": "testing2", //required
  "status": "READY_TO_RUN", //required
  "objectiveMetric": "ga:goal11Completions", //required?
  "variations": [
  {
   "name": "test1", //required
   "status": "ACTIVE",
   "url": "http://abs.se/3" //required
  },
  {
   "name": "test2", //required
   "status": "ACTIVE",
   "url": "http://abs.se/4" //required
  }
 ]
};


var request = gapi.client.request({
  'path': '/analytics/v3/management/accounts/{accountId}/webproperties/{webPropertyId}/profiles/{profileId}/experiments',
  'method': 'POST',
  'body': JSON.stringify(requestBody)});
  request.execute(handleAccounts);
}

Big thanks to Pete for the help.

这篇关于将实验插入Google analytics api(gapi)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆