Monday, November 11, 2013

Building Entity Deep Links with AdWords Scripts

I was trying to build a report on problems in an account and I was thinking to myself, "Man, it sure would be nice to deep link directly to the entity that was having issues." Then I realized that is the script change logs could do it, I probably could too.

It turns out, there are two magic numbers that you need in order to get this to work. When you login to your account, in the url, you will see __u= and __c=. According to this blog post, these values are the 'effectiveUserId' and 'customerId' respectively. Unfortunately, there isn't a way to access these values when using scripts, so you will have to manually copy them into the script below.

After that, you can include the function in all your scripts and deep link to your heart's content. It isn't the prettiest thing in the world but it is self contained so it should be easy to copy into the bottom of your scripts.

Thanks,
Russ

  // Link to the Keyword Tab of the AdGroup
  Logger.log(getUrl(someAdGroupEntity,'Keywords'));
  // Link to the Ads Tab of the AdGroup
  Logger.log(getUrl(someAdGroupEntity,'Ads'));      
  // Link to Location Settings Tab of the Campaign
  Logger.log(getUrl(comeCampaignEntity,'Settings:Locations')); 


/***********************************
* Build Deep Link Urls for Entities
* Version 1.0 
* Created By: Russ Savage
* FreeAdWordsScripts.com
***********************************/
function getUrl(entity,tab) {
  var customerId = '__c from the url';
  var effectiveUserId = '__u from the url';
  var decodedTab = getTab(tab);  
  
  var base = 'https://adwords.google.com/cm/CampaignMgmt?';
  var url = base+'__c='+customerId+'&__u='+effectiveUserId+'#';
  
  if(typeof entity['getBudget'] !== 'undefined') {
    //A Campaign
    return url+'c.'+entity.getId()+'.'+decodedTab+'&app=cm';
  }
  if(typeof entity['createKeyword'] !== 'undefined') {
    //An AdGroup
    return url+'a.'+entity.getId()+'_'+entity.getCampaign().getId()+'.'+decodedTab+'&app=cm';
  }
  if(typeof entity['getMatchType'] !== 'undefined') {
    //A Keyword
    return url+'a.'+entity.getAdGroup().getId()+'_'+entity.getCampaign().getId()+'.key&app=cm';
  }
  if(typeof entity['getHeadline'] !== 'undefined') {
    //An Ad
    return url+'a.'+entity.getAdGroup().getId()+'_'+entity.getCampaign().getId()+'.create&app=cm';
  }
  return url+'r.ONLINE.di&app=cm';
  
  function getTab(tab) {
    var mapping = {
      'Ad groups':'ag','Settings:All settings':'st_sum',
      'Settings:Locations':'st_loc','Settings:Ad schedule':'st_as',
      'Settings:Devices':'st_p','Ads':'create',
      'Keywords':'key','Audiences':'au','Ad extensions':'ae',
      'Auto targets':'at','Dimensions' : 'di'
    };
    if(mapping[tab]) { return mapping[tab]; }
    return 'key'; //default to keyword tab
  }
}

11 comments:

  1. You should consider this while you gonna adopt this code to the modern realities.

    ReplyDelete
  2. I have read so many content regarding the blogger lovers except this post is in fact a nice article,
    keep it up.
    VCUT Pro

    ReplyDelete
  3. Good blog. Keep sharing. I love them Are you also searching for Spanish writing help? we are the best solution for you. We are best known for delivering Spanish writing services to students without having to break the bank

    ReplyDelete
  4. 0km Business is the large trading platform for wholesalers, resellers, closeout dealers and importers. The wholesale marketplace is a must for traders who want to make new business contacts or are looking for new suppliers and buyers.

    Offer remaining items, special items, new goods, trend items, bankruptcy goods, imported goods and surplus assets.
    0kmbusiness

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Thanks for sharing the scripts. With an ever-increasing population, there is an ever-increasing amount of waste thrown out onto the planet's surface. This has a fatal impact on the planet's sustainability and future generations. Recycling is the best solution for maintaining a circular economy and ensuring that whatever we produce stays in the loop rather than being disposed of in a landfill. For best recycling service experience check out what recycling company in uae has to offer.

    ReplyDelete
  7. Thanks for sharing such informative content. Our writers are well equipped to handle different types of academic papers and it therefore goes without saying that once you order for our Capstone Project Help your entire academic writing challenges shall be no more.

    ReplyDelete
  8. The main reason why people avoid Buy Essay Online is the price. They think it might be expensive. Considering the efforts, time and devotion put in each paper it should cost a lot. In fact, it's not actually that much. If you plan to buy essay to enclose it to your college application, you realize there's no need to empty your bank account for it.

    ReplyDelete
  9. Any disturbance in your LG washing machine will dissipate your day so why take a risk hire a professional company personnel who can easily fix your washing machine before the given time.
    LG Washing Machine Repair

    ReplyDelete
  10. Good blog. Keep sharing. I love them Are you also searching for Spanish writing help? we are the best solution for you. We are best known for delivering Spanish writing services to students without having to break the bank

    ReplyDelete