Help inserting a new goal

86 views
Skip to first unread message

James Torrecampo

unread,
Sep 6, 2015, 11:30:26 PM9/6/15
to Google Analytics Management API
Hi all,

I have been given permission to insert goals, but I am having trouble inserting a goal from my site using the demo code on - https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/goals/insert

The scope has already been set to https://www.googleapis.com/auth/analytics.edit

Here is my function. A
m i missing anything?


function insertGoal1() {
  var request = gapi.client.analytics.management.goals.insert(
    {
      'accountId': 'xxx',
      'webPropertyId': 'UA-xxx-1',
      'profileId': 'xxx',
      'resource': {
        'id': '6',
        'kind': 'analytics#goal',
         'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/xxx/webproperties/UA-xxx-1/profiles/xxx/goals/6',
         'accountId': 'xxx',
        'webPropertyId': 'UA-xxx-1',
        'internalWebPropertyId': 'xxx',
        'profileId': 'xxx',
          'name': 'User time on site',
        'value': 2,
        'active': true,
        'type': 'VISIT_TIME_ON_SITE',
        'visitTimeOnSiteDetails': {
          'comparisonType': 'GREATER_THAN',
          'comparisonValue': 300
        }
        "parentLink": {
        "type": 'analytics#profile',
         "href": 'https://www.googleapis.com/analytics/v3/management/accounts/xxx/webproperties/UA-xxx-1/profiles/xxx',
          },
           "urlDestinationDetails": {
    "url": '/chat',
    "caseSensitive": false,
    "matchType": 'EXACT',
    "firstStepRequired": false,
    },
  }
 });
  request.execute(function (response) { // Handle the response. });
 }
}

Matthew Cohoon

unread,
Sep 6, 2015, 11:32:03 PM9/6/15
to Google Analytics Management API
What is the error response you are getting?
-Matt

--
You received this message because you are subscribed to the Google Groups "Google Analytics Management API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-analytics-mana...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Torrecampo

unread,
Sep 6, 2015, 11:42:02 PM9/6/15
to Google Analytics Management API
Hi Matt.
I'm not getting any response..
To unsubscribe from this group and stop receiving emails from it, send an email to google-analytics-management-api+unsubscribe@googlegroups.com.

Matt

unread,
Sep 8, 2015, 11:58:28 AM9/8/15
to Google Analytics Management API
I would encourage you to check the developer console to see if any errors are logged there. Also check the networking tab to see if you are making a proper connection to the API.

With out seeing the rest of your code, authentication and actually how this method get called its hard to tell whats is going on?
Have you going through the steps of the quickstart guide or the embed API setup?
-Matt

James Torrecampo

unread,
Sep 13, 2015, 7:43:35 AM9/13/15
to Google Analytics Management API
Hi,

I don't think the code above is even making a connection. As I can't see anything in the console.

Yes I have been able to create several charts and tables using the Embed API, as well as some JSON format reports using the core Reporting API.

Going back to the goals insert example code, I have tried the below but it doesn't seem to do anything. Are you able to describe exactly what happens if you tried this code on your end?

/*
 * Note: This code assumes you have an authorized Analytics client object.
 * See the Goals Developer Guide for details.
 */


/*
 * This request creates a new goal.
 */

function insertGoal() {
 
var request = gapi.client.analytics.management.goals.insert(
   
{
     
'accountId': '123456',
     
'webPropertyId': 'UA-123456-1',
     
'profileId': '7654321',
     
'resource': {
       
'id': '7',
       
'active': false,
       
'name': 'My Goal',

       
'type': 'VISIT_TIME_ON_SITE',
       
'visitTimeOnSiteDetails': {
         
'comparisonType': 'GREATER_THAN',
         
'comparisonValue': 300
       
}
     
}

Matthew Cohoon

unread,
Sep 13, 2015, 4:26:36 PM9/13/15
to Google Analytics Management API
I would encourage you to start debugging it. Put in print statements and break points right as you enter the function.
var request = gapi.client.analytics.management.goals.insert(....)
should construct a request object. with the dev console interrogate that object, what member objects does it have?
Then call execute
request.execute(function (response) {
   console.log("we got a response!")
   // Handle the response.
});

More break points, more print statements. From all you've said it sounds to me like your code is not making it into the insertGoal() function.
what does your code look like that calls insertGoal() ?

Once it makes it to the response  if there was an error there will be response.error member object which you can interrogate and find the reason for the error. if it was successful there should be a goal resource object which should describe the newly created goal.

-Matt

To unsubscribe from this group and stop receiving emails from it, send an email to google-analytics-mana...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Analytics Management API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-analytics-mana...@googlegroups.com.

James Torrecampo

unread,
Sep 16, 2015, 11:11:24 PM9/16/15
to Google Analytics Management API
I have tried to simply 'list' goal data using the sample code for JavaScript on https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/goals/list
I used that code and just replaced the IDs with my own credentials.

But even then, the Chrome JavaScript console does not seem to be reading the code at all? No errors, it's like it doesn't even exist. I have tried inserting the code in other parts of my code within the header tags but still nothing.

Is there an issue with my permissions for the Management API?
To unsubscribe from this group and stop receiving emails from it, send an email to google-analytics-management-api+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Analytics Management API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-analytics-management-api+unsubscribe@googlegroups.com.

Matthew Cohoon

unread,
Sep 17, 2015, 11:53:34 AM9/17/15
to Google Analytics Management API
Hi James,
If the print statements are not getting called and you are not getting the breakpoints then it is likely that the problem is in the surrounding code. The code that actually calls the method you are writing.

If you include all your code folks on stackoverflow are usually pretty good about finding the errors.


The Hello Analytics API is a good place to start to understand the structure of the code.

Start by putting a print statement and a break point after the client load statement:

gapi.client.load('analytics', 'v3').then(function() {

console.log('TODO(James): break point here.');
   
// Get a list of all Google Analytics accounts for this user
    gapi
.client.analytics.management.accounts.list().then(handleAccounts);

Once you have that breakpoint working you can change the code to from accounts.list() to goals.list() or goals.insert(...)

-Matt



To unsubscribe from this group and stop receiving emails from it, send an email to google-analytics-mana...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Analytics Management API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-analytics-mana...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Analytics Management API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-analytics-mana...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages