Tuesday, December 11, 2012

Auto Add ValueTrack Params To All Destination URLs

Today we have a script that will help make sure all of your keywords are tagged with the appropriate ValueTrack parameters.  You can use this to ensure that all of your tracking params are added correctly to your urls.

You can add your own query string parameters to the mapping at the top of the script.  For example, if all the keywords in your account need to have the parameter "channel=sem" in their destination url, you could add that to the URL_PARAMS_TO_ADD mapping at the top of the file and it will be added to all your urls.

Also, I updated the script to allow you to add whatever values you want from the account into the url. See the examples for adding Campaign and AdGroup names to the url if you like.

Thanks,
Russ

/******************************************
* Auto Add ValueTrack (and other) Params If Not There
* Created By: Russ Savage
* Version 1.1
* ChangeLog v1.1
*  - Added the ability to add function calls into the parameters to add
* FreeAdWordsScripts.com
******************************************/
function main() {
   
  var URL_PARAMS_TO_ADD = { 
    "kw" : "{keyword}",
    "crid" : "{creative}",
    "mt" : "{matchtype}",
    "ntwk" : "{network}",
    "ap" : "{adposition}",
    "dv" : "{device}",
    "dvm" : "{devicemodel}",
    //"camp" : getCampaignName,  <----- This function is defined below
    //"ag" : getAdGroupName  <----- and so is this one
  };
   
  var kw_iter = AdWordsApp.keywords()
                  .withCondition("DestinationUrl != ''")
                  .get();
  
  while(kw_iter.hasNext()) {
    var kw = kw_iter.next();
    var destUrl = kw.getDestinationUrl();
    if(!destUrl || destUrl === '') { continue; }
    var toAppend = [];
    for(var key in URL_PARAMS_TO_ADD) {
      if(destUrl.indexOf(key) >= 0) { continue; }
      var value = URL_PARAMS_TO_ADD[key];
      
      //check to see if we should call a function
      if(typeof(value) === 'function') {
        value = encodeURI(value(kw));
      }
      toAppend.push(key+"="+value);
    }
    if(destUrl.indexOf('?') >= 0) {
      kw.setDestinationUrl(destUrl + "&"+toAppend.join('&'));
    } else {
      kw.setDestinationUrl(destUrl + "?"+toAppend.join('&'));
    }
    Logger.log(kw.getDestinationUrl());
  }
}

// As long as the function call is passed a kw object, you can insert
// whatever value you want into the url
function getCampaignName(kw) {
  return kw.getCampaign().getName();
}

function getAdGroupName(kw) {
  return kw.getAdGroup().getName();
}

9 comments:

  1. Have a look at this tips https://resume-chief.com/blog/resume-writing-tips. I know that programmers don't like to write resumes.

    ReplyDelete
  2. Are you having issues when it comes to getting programming assignments drafted? IdealAssignmentHelp is here to cover all your programming assignments without any kind of glitches at all. Yes, you can get connected to their Business Assignment Help team and make it easy for yourself to submit the respective paper within the given deadline and that too matching with the university stated instructions.

    ReplyDelete
  3. Many of the ValueTrack parameters map to fields in AdWords API reports, however not necessarily with identical text value then why not Try and check us here

    ReplyDelete
  4. Aluminum projecting is believed to be a piece of another person's recreation or leisure activity in excess of a modern reason that it holds. Indeed, Aluminum profile supplier in china even a craftsman or a stone worker participates in aluminum projecting

    ReplyDelete
  5. Additionally contains amazing cell which is found in the strip and squeeze of pomegranate. Moringa Seeds Cake Supplier Furthermore, its standard utilization keeps

    ReplyDelete
  6. Thanks a lot for your comment 🙂 have a great day!
    cable extruder manufacturer

    ReplyDelete
  7. Numerous individuals purchase bike parts from the neighborhood store and try not to trust that the firsts will originate from the makers processing plant. Automotive motorcycle parts manufacturer

    ReplyDelete
  8. where the softened plastic would be filled a pass on. Mould Tool Making Manufacturer The bite the dust would be looking like the item that will be made. The liquid would be filled the bite the dust and to cool under pressure.

    ReplyDelete
  9. Any individual who works in, or possesses a food and drink administration activity, knows the significance of refrigeration frameworks and hardware. external rotor manufacturer

    ReplyDelete