{"action":"created","issue":{"url":"https://api.github.com/repos/optimizely/marketing-website/issues/769","labels_url":"https://api.github.com/repos/optimizely/marketing-website/issues/769/labels{/name}","comments_url":"https://api.github.com/repos/optimizely/marketing-website/issues/769/comments","events_url":"https://api.github.com/repos/optimizely/marketing-website/issues/769/events","html_url":"https://github.com/optimizely/marketing-website/pull/769","id":53144059,"number":769,"title":"Add concat banner/footer try-catch blocks","user":{"login":"dtothefp","id":4656726,"avatar_url":"https://avatars.githubusercontent.com/u/4656726?v=3","gravatar_id":"","url":"https://api.github.com/users/dtothefp","html_url":"https://github.com/dtothefp","followers_url":"https://api.github.com/users/dtothefp/followers","following_url":"https://api.github.com/users/dtothefp/following{/other_user}","gists_url":"https://api.github.com/users/dtothefp/gists{/gist_id}","starred_url":"https://api.github.com/users/dtothefp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dtothefp/subscriptions","organizations_url":"https://api.github.com/users/dtothefp/orgs","repos_url":"https://api.github.com/users/dtothefp/repos","events_url":"https://api.github.com/users/dtothefp/events{/privacy}","received_events_url":"https://api.github.com/users/dtothefp/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/optimizely/marketing-website/labels/eng+review","name":"eng review","color":"207de5"},{"url":"https://api.github.com/repos/optimizely/marketing-website/labels/in+progress","name":"in progress","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2014-12-30T20:23:24Z","updated_at":"2015-01-09T19:19:01Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/optimizely/marketing-website/pulls/769","html_url":"https://github.com/optimizely/marketing-website/pull/769","diff_url":"https://github.com/optimizely/marketing-website/pull/769.diff","patch_url":"https://github.com/optimizely/marketing-website/pull/769.patch"},"body":"This PR addresses https://optimizely.atlassian.net/browse/MKT-862.  The goal of the PR is to wrap the global JS bundle and page JS for staging and production in try-catch blocks in order to report bundle and page JS errors to Google Analytics.  This was accomplished by adjusting the concat banner/footer strings in the `grunt config` task and by adding a `targetName` variable inside each JS bundle by using the `process` option in the `grunt concat` task.  \r\n\r\nThe `targetName` variable is set equal to the current concat target.  Because each bundle is wrapped within a closure the `targetName` variable will be scoped to each bundle and therefore not overwritten by additional JS bundles on the page.  The `targetName` variable is later used within the `catch` block to report to GA whether a JS error occurred within the global JS bundle, or within a page/layout bundle.  *Note: if an error occurs in the global JS bundle it is likely an error will occur as well in a page/layout level bundle as it most likely uses JS from the global bundle.*\r\n\r\nDue to the fact that this PR addresses primarily code that is used in staging/production, it is difficult to test locally.  The best way to test locally is to adjust the concat banner and footer strings in the `grunt config:dev` task/target.  Therefore, to test locally alter the `grunt config:dev` target as follows to include the try-catch block as well as a debugger statement:\r\n\r\n```js\r\nconcat_banner: '(function($, w, d){ \\n\\n' +\r\n                       '  window.optly = window.optly || {}; \\n\\n' +\r\n                       '  window.optly.mrkt = window.optly.mrkt || {}; \\n\\n' +\r\n                       '  window.linkPath = \"/dist\"; \\n\\n' + \r\n                       '  try { \\n\\n',\r\n        concat_footer: '  } catch(error){ \\n\\n' +\r\n                       '    var path = window.location.pathname;\\n\\n' +\r\n                       '    var trimpath = path.lastIndexOf(\"/\") === path.length - 1 ? path.substr(0, path.lastIndexOf(\"/\")) : path;\\n\\n' + \r\n                       '    debugger;window.ga(\"send\", \"event\", targetName + \" JavaScript Error\", trimpath, error);\\n\\n' + \r\n                       '  }\\n\\n' +\r\n                       '})(jQuery, window, document);'\r\n```\r\n\r\nNext, introduce some sort of error in the global JS bundle and/or page level bundle.  Now run `grunt server` and make sure to open the JS console in the chrome inspector.  JS execution should halt at the breakpoint inside the `catch` block and the `targetName` variable can be inspected as well as the `error` object."},"comment":{"url":"https://api.github.com/repos/optimizely/marketing-website/issues/comments/69383963","html_url":"https://github.com/optimizely/marketing-website/pull/769#issuecomment-69383963","issue_url":"https://api.github.com/repos/optimizely/marketing-website/issues/769","id":69383963,"user":{"login":"optibot","id":1276102,"avatar_url":"https://avatars.githubusercontent.com/u/1276102?v=3","gravatar_id":"","url":"https://api.github.com/users/optibot","html_url":"https://github.com/optibot","followers_url":"https://api.github.com/users/optibot/followers","following_url":"https://api.github.com/users/optibot/following{/other_user}","gists_url":"https://api.github.com/users/optibot/gists{/gist_id}","starred_url":"https://api.github.com/users/optibot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/optibot/subscriptions","organizations_url":"https://api.github.com/users/optibot/orgs","repos_url":"https://api.github.com/users/optibot/repos","events_url":"https://api.github.com/users/optibot/events{/privacy}","received_events_url":"https://api.github.com/users/optibot/received_events","type":"User","site_admin":false},"created_at":"2015-01-09T19:19:01Z","updated_at":"2015-01-09T19:19:01Z","body":"Test PASSed.\nRefer to this link for build results (access rights to CI server needed): \nhttps://jenkins.dz.optimizely.com/job/marketing-staging_prs/1143/\nTest PASSed."}}