{"action":"created","comment":{"url":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/comments/74834953","id":74834953,"diff_hunk":"@@ -0,0 +1,87 @@\n+'use strict';\n+\n+var Analytics = {\n+\n+  tagManagerIsLoaded: false,\n+\n+  EVENT_CATERGORY: 'CFGOV Event',\n+\n+  /**\n+   * Initialize the Analytics module.\n+   */\n+  init: function() {\n+    // detect if Google tag manager is loaded\n+    if ( window.hasOwnProperty( 'google_tag_manager' ) ) {\n+      Analytics.tagManagerIsLoaded = true;\n+    } else {\n+      var _tagManager;\n+      Object.defineProperty( window, 'google_tag_manager', {\n+        enumerable: true,\n+        configurable: true,\n+        get: function() {\n+          return _tagManager;\n+        },\n+        set: function( value ) {\n+          _tagManager = value;\n+          Analytics.tagManagerIsLoaded = true;\n+        }\n+      } );\n+    }\n+  },\n+\n+  /**\n+   * @name sendEvent\n+   * @kind function\n+   *\n+   * @description\n+   * Pushes an event to the GTM dataLayer.\n+   *\n+   * @param {string} action Name of event.\n+   * @param {string} label DOM element label.\n+   * @param {Function} callback Function to call on GTM submsission.\n+   * @param {number} timeout Callback invocation fallback time.\n+  * @returns {Analytics} An instance\n+   */\n+  sendEvent: function( action, label, callback, timeout ) {\n+    var dataLayerOptions = {\n+      event:        Analytics.EVENT_CATERGORY,\n+      action:       action,\n+      label:        label || '',\n+      eventTimeout: timeout || 500\n+    };\n+\n+    if ( callback ) {\n+      dataLayerOptions.eventCallback = callback;\n+    }\n+\n+    if ( Analytics.tagManagerIsLoaded ) {\n+      window.dataLayer.push( dataLayerOptions );\n+    } else if ( typeof callback === 'function' ) {\n+      return callback();\n+    }\n+\n+    return Analytics;\n+  },\n+\n+  /**\n+   * @name sendEvents\n+   * @kind function\n+   *\n+   * @description\n+   * Pushes multiple events to the GTM dataLayer.\n+   *\n+   * @param {array} eventsArray Array of event objects.\n+   */\n+  sendEvents: function( eventsArray ) {\n+    if ( Array.isArray( eventsArray ) ) {","path":"cfgov/unprocessed/js/modules/Analytics.js","position":76,"original_position":76,"commit_id":"af4665c727ce176fc90a7a2840b5eb3ff56a3041","original_commit_id":"af4665c727ce176fc90a7a2840b5eb3ff56a3041","user":{"login":"anselmbradford","id":704760,"avatar_url":"https://avatars.githubusercontent.com/u/704760?v=3","gravatar_id":"","url":"https://api.github.com/users/anselmbradford","html_url":"https://github.com/anselmbradford","followers_url":"https://api.github.com/users/anselmbradford/followers","following_url":"https://api.github.com/users/anselmbradford/following{/other_user}","gists_url":"https://api.github.com/users/anselmbradford/gists{/gist_id}","starred_url":"https://api.github.com/users/anselmbradford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anselmbradford/subscriptions","organizations_url":"https://api.github.com/users/anselmbradford/orgs","repos_url":"https://api.github.com/users/anselmbradford/repos","events_url":"https://api.github.com/users/anselmbradford/events{/privacy}","received_events_url":"https://api.github.com/users/anselmbradford/received_events","type":"User","site_admin":false},"body":"Even though IE8 is in a non-JS state in regard to UI JS, it needs GTM JS to be available, right? `isArray` is not supported :( Is there a fallback for here? Same for `forEach` below.","created_at":"2016-08-15T21:05:47Z","updated_at":"2016-08-15T21:05:47Z","html_url":"https://github.com/cfpb/cfgov-refresh/pull/2308#discussion_r74834953","pull_request_url":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/2308","_links":{"self":{"href":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/comments/74834953"},"html":{"href":"https://github.com/cfpb/cfgov-refresh/pull/2308#discussion_r74834953"},"pull_request":{"href":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/2308"}}},"pull_request":{"url":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/2308","id":81155646,"html_url":"https://github.com/cfpb/cfgov-refresh/pull/2308","diff_url":"https://github.com/cfpb/cfgov-refresh/pull/2308.diff","patch_url":"https://github.com/cfpb/cfgov-refresh/pull/2308.patch","issue_url":"https://api.github.com/repos/cfpb/cfgov-refresh/issues/2308","number":2308,"state":"open","locked":false,"title":"Adding Filter Analytics","user":{"login":"sebworks","id":1696212,"avatar_url":"https://avatars.githubusercontent.com/u/1696212?v=3","gravatar_id":"","url":"https://api.github.com/users/sebworks","html_url":"https://github.com/sebworks","followers_url":"https://api.github.com/users/sebworks/followers","following_url":"https://api.github.com/users/sebworks/following{/other_user}","gists_url":"https://api.github.com/users/sebworks/gists{/gist_id}","starred_url":"https://api.github.com/users/sebworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebworks/subscriptions","organizations_url":"https://api.github.com/users/sebworks/orgs","repos_url":"https://api.github.com/users/sebworks/repos","events_url":"https://api.github.com/users/sebworks/events{/privacy}","received_events_url":"https://api.github.com/users/sebworks/received_events","type":"User","site_admin":false},"body":"Adding Filter Analytics \r\n\r\n## Additions\r\n\r\n-  Added `cfgov/unprocessed/js/modules/Analytics.js` to serve as a singleton for sending events to GTM.  This is based on code contained in [eRegs](https://github.com/cfpb/regulations-site/blob/84891b05e8c24530b78260593bfca29e5b44ecb8/regulations/static/regulations/js/source/events/ga-events.js).\r\n\r\n- Added `test/unit_tests/modules/Analytics-spec.js` as a skeleton until I write tests.  The tests are atricky because it's a single and has a self-invoking `init` function.\r\n\r\n## Changes\r\n\r\n- Modified `cfgov/jinja2/v1/_includes/organisms/filterable-list-controls.html` to fix issues with the filter labels.\r\n- Modified `cfgov/unprocessed/js/organisms/FilterableListControls.js` to send filter events when checkboxes are changed, text is entered, or the form is submitted.\r\n- Modified `test/unit_tests/organisms/FilterableListControls-spec.js` to fix issue surrounding jsdom and the window object.  \r\n\r\n## Testing\r\n\r\n- Visit `http://localhost:8000/about-us/blog/`\r\n- Expand the filter.\r\n- Goto the console and type `window.dataLayer`.\r\n- Expand the events in the dataLayer.\r\n- You should see the following:\r\n\r\n```\r\naction:       “Filter:open\"\r\nevent:        “CFGOV Event\"\r\neventTimeout: 500\r\nlabel:        “Filter posts\"\r\n```\r\n\r\n## Review\r\n\r\n- @anselmbradford \r\n- @contolini \r\n-  @wernerc\r\n- @kelleyholden\r\n\r\n\r\n## Screenshots\r\n\r\n- \r\n<img width=\"843\" alt=\"screen shot 2016-08-12 at 12 55 30 pm\" src=\"https://cloud.githubusercontent.com/assets/1696212/17630160/20d9dd3a-608c-11e6-9bc7-8822425a946f.png\">\r\n<img width=\"338\" alt=\"screen shot 2016-08-12 at 12 54 39 pm\" src=\"https://cloud.githubusercontent.com/assets/1696212/17630161/20ded4fc-608c-11e6-9f6e-d0d23da9fe38.png\">\r\n<img width=\"840\" alt=\"screen shot 2016-08-12 at 12 54 23 pm\" src=\"https://cloud.githubusercontent.com/assets/1696212/17630162/20ded4d4-608c-11e6-958d-6eecb21af1cb.png\">\r\n<img width=\"818\" alt=\"screen shot 2016-08-12 at 12 54 12 pm\" src=\"https://cloud.githubusercontent.com/assets/1696212/17630164/20e0ca28-608c-11e6-9ac4-a73ad580834d.png\">\r\n\r\n## Notes\r\n\r\n- I've created an dataLayer object in the following format:\r\n\r\n ```\r\n  var dataLayerOptions = {\r\n      event: 'CFGOV Event' ,\r\n      action: 'Filter:'  + field.type + event.name ,\r\n      label: label.textContent  + ':' +  field.value,  // Defaults to '',\r\n      eventCallback: callback // Optional but should be used on form submissions.\r\n      eventTimeout:  timeout // Defaults to 500\r\n};\r\n ```\r\n\r\nThis is the article describing the technique: http://www.simoahava.com/gtm-tips/use-eventtimeout-eventcallback/. I'm triggering events using the `change` event, it provides better utility than using `click`, `mousedown` or `keyup`. \r\n\r\n## Todos\r\n\r\n~~Write unit tests for `Analytics.js`~~\r\n\r\n## Checklist\r\n\r\n* [ ] Changes are limited to a single goal (no scope creep)\r\n* [ ] Code can be automatically merged (no conflicts)\r\n* [ ] Code follows the standards laid out in the [front end playbook](https://github.com/cfpb/front-end)\r\n* [ ] Passes all existing automated tests\r\n* [ ] New functions include new tests\r\n* [ ] New functions are documented (with a description, list of inputs, and expected output)\r\n* [ ] Placeholder code is flagged\r\n* [ ] Visually tested in supported browsers and devices\r\n* [ ] Project documentation has been updated (including the \"Unreleased\" section of the CHANGELOG)\r\n\r\n","created_at":"2016-08-12T17:39:41Z","updated_at":"2016-08-15T21:05:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"86adc0a0e36587bce350f952a4f5e2d19621230c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/2308/commits","review_comments_url":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/2308/comments","review_comment_url":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cfpb/cfgov-refresh/issues/2308/comments","statuses_url":"https://api.github.com/repos/cfpb/cfgov-refresh/statuses/af4665c727ce176fc90a7a2840b5eb3ff56a3041","head":{"label":"cfpb:filter_analytics","ref":"filter_analytics","sha":"af4665c727ce176fc90a7a2840b5eb3ff56a3041","user":{"login":"cfpb","id":1071563,"avatar_url":"https://avatars.githubusercontent.com/u/1071563?v=3","gravatar_id":"","url":"https://api.github.com/users/cfpb","html_url":"https://github.com/cfpb","followers_url":"https://api.github.com/users/cfpb/followers","following_url":"https://api.github.com/users/cfpb/following{/other_user}","gists_url":"https://api.github.com/users/cfpb/gists{/gist_id}","starred_url":"https://api.github.com/users/cfpb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cfpb/subscriptions","organizations_url":"https://api.github.com/users/cfpb/orgs","repos_url":"https://api.github.com/users/cfpb/repos","events_url":"https://api.github.com/users/cfpb/events{/privacy}","received_events_url":"https://api.github.com/users/cfpb/received_events","type":"Organization","site_admin":false},"repo":{"id":18852566,"name":"cfgov-refresh","full_name":"cfpb/cfgov-refresh","owner":{"login":"cfpb","id":1071563,"avatar_url":"https://avatars.githubusercontent.com/u/1071563?v=3","gravatar_id":"","url":"https://api.github.com/users/cfpb","html_url":"https://github.com/cfpb","followers_url":"https://api.github.com/users/cfpb/followers","following_url":"https://api.github.com/users/cfpb/following{/other_user}","gists_url":"https://api.github.com/users/cfpb/gists{/gist_id}","starred_url":"https://api.github.com/users/cfpb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cfpb/subscriptions","organizations_url":"https://api.github.com/users/cfpb/orgs","repos_url":"https://api.github.com/users/cfpb/repos","events_url":"https://api.github.com/users/cfpb/events{/privacy}","received_events_url":"https://api.github.com/users/cfpb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cfpb/cfgov-refresh","description":"Django project that powers the redesigned consumerfinance.gov website.","fork":false,"url":"https://api.github.com/repos/cfpb/cfgov-refresh","forks_url":"https://api.github.com/repos/cfpb/cfgov-refresh/forks","keys_url":"https://api.github.com/repos/cfpb/cfgov-refresh/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cfpb/cfgov-refresh/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cfpb/cfgov-refresh/teams","hooks_url":"https://api.github.com/repos/cfpb/cfgov-refresh/hooks","issue_events_url":"https://api.github.com/repos/cfpb/cfgov-refresh/issues/events{/number}","events_url":"https://api.github.com/repos/cfpb/cfgov-refresh/events","assignees_url":"https://api.github.com/repos/cfpb/cfgov-refresh/assignees{/user}","branches_url":"https://api.github.com/repos/cfpb/cfgov-refresh/branches{/branch}","tags_url":"https://api.github.com/repos/cfpb/cfgov-refresh/tags","blobs_url":"https://api.github.com/repos/cfpb/cfgov-refresh/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cfpb/cfgov-refresh/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cfpb/cfgov-refresh/git/refs{/sha}","trees_url":"https://api.github.com/repos/cfpb/cfgov-refresh/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cfpb/cfgov-refresh/statuses/{sha}","languages_url":"https://api.github.com/repos/cfpb/cfgov-refresh/languages","stargazers_url":"https://api.github.com/repos/cfpb/cfgov-refresh/stargazers","contributors_url":"https://api.github.com/repos/cfpb/cfgov-refresh/contributors","subscribers_url":"https://api.github.com/repos/cfpb/cfgov-refresh/subscribers","subscription_url":"https://api.github.com/repos/cfpb/cfgov-refresh/subscription","commits_url":"https://api.github.com/repos/cfpb/cfgov-refresh/commits{/sha}","git_commits_url":"https://api.github.com/repos/cfpb/cfgov-refresh/git/commits{/sha}","comments_url":"https://api.github.com/repos/cfpb/cfgov-refresh/comments{/number}","issue_comment_url":"https://api.github.com/repos/cfpb/cfgov-refresh/issues/comments{/number}","contents_url":"https://api.github.com/repos/cfpb/cfgov-refresh/contents/{+path}","compare_url":"https://api.github.com/repos/cfpb/cfgov-refresh/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cfpb/cfgov-refresh/merges","archive_url":"https://api.github.com/repos/cfpb/cfgov-refresh/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cfpb/cfgov-refresh/downloads","issues_url":"https://api.github.com/repos/cfpb/cfgov-refresh/issues{/number}","pulls_url":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls{/number}","milestones_url":"https://api.github.com/repos/cfpb/cfgov-refresh/milestones{/number}","notifications_url":"https://api.github.com/repos/cfpb/cfgov-refresh/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cfpb/cfgov-refresh/labels{/name}","releases_url":"https://api.github.com/repos/cfpb/cfgov-refresh/releases{/id}","deployments_url":"https://api.github.com/repos/cfpb/cfgov-refresh/deployments","created_at":"2014-04-16T19:22:03Z","updated_at":"2016-08-10T00:12:07Z","pushed_at":"2016-08-15T20:20:09Z","git_url":"git://github.com/cfpb/cfgov-refresh.git","ssh_url":"git@github.com:cfpb/cfgov-refresh.git","clone_url":"https://github.com/cfpb/cfgov-refresh.git","svn_url":"https://github.com/cfpb/cfgov-refresh","homepage":"http://www.consumerfinance.gov/","size":129035,"stargazers_count":70,"watchers_count":70,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":38,"mirror_url":null,"open_issues_count":105,"forks":38,"open_issues":105,"watchers":70,"default_branch":"master"}},"base":{"label":"cfpb:master","ref":"master","sha":"86cafa04cd0bf5caf00f0957927247b9b4033ede","user":{"login":"cfpb","id":1071563,"avatar_url":"https://avatars.githubusercontent.com/u/1071563?v=3","gravatar_id":"","url":"https://api.github.com/users/cfpb","html_url":"https://github.com/cfpb","followers_url":"https://api.github.com/users/cfpb/followers","following_url":"https://api.github.com/users/cfpb/following{/other_user}","gists_url":"https://api.github.com/users/cfpb/gists{/gist_id}","starred_url":"https://api.github.com/users/cfpb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cfpb/subscriptions","organizations_url":"https://api.github.com/users/cfpb/orgs","repos_url":"https://api.github.com/users/cfpb/repos","events_url":"https://api.github.com/users/cfpb/events{/privacy}","received_events_url":"https://api.github.com/users/cfpb/received_events","type":"Organization","site_admin":false},"repo":{"id":18852566,"name":"cfgov-refresh","full_name":"cfpb/cfgov-refresh","owner":{"login":"cfpb","id":1071563,"avatar_url":"https://avatars.githubusercontent.com/u/1071563?v=3","gravatar_id":"","url":"https://api.github.com/users/cfpb","html_url":"https://github.com/cfpb","followers_url":"https://api.github.com/users/cfpb/followers","following_url":"https://api.github.com/users/cfpb/following{/other_user}","gists_url":"https://api.github.com/users/cfpb/gists{/gist_id}","starred_url":"https://api.github.com/users/cfpb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cfpb/subscriptions","organizations_url":"https://api.github.com/users/cfpb/orgs","repos_url":"https://api.github.com/users/cfpb/repos","events_url":"https://api.github.com/users/cfpb/events{/privacy}","received_events_url":"https://api.github.com/users/cfpb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cfpb/cfgov-refresh","description":"Django project that powers the redesigned consumerfinance.gov website.","fork":false,"url":"https://api.github.com/repos/cfpb/cfgov-refresh","forks_url":"https://api.github.com/repos/cfpb/cfgov-refresh/forks","keys_url":"https://api.github.com/repos/cfpb/cfgov-refresh/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cfpb/cfgov-refresh/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cfpb/cfgov-refresh/teams","hooks_url":"https://api.github.com/repos/cfpb/cfgov-refresh/hooks","issue_events_url":"https://api.github.com/repos/cfpb/cfgov-refresh/issues/events{/number}","events_url":"https://api.github.com/repos/cfpb/cfgov-refresh/events","assignees_url":"https://api.github.com/repos/cfpb/cfgov-refresh/assignees{/user}","branches_url":"https://api.github.com/repos/cfpb/cfgov-refresh/branches{/branch}","tags_url":"https://api.github.com/repos/cfpb/cfgov-refresh/tags","blobs_url":"https://api.github.com/repos/cfpb/cfgov-refresh/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cfpb/cfgov-refresh/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cfpb/cfgov-refresh/git/refs{/sha}","trees_url":"https://api.github.com/repos/cfpb/cfgov-refresh/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cfpb/cfgov-refresh/statuses/{sha}","languages_url":"https://api.github.com/repos/cfpb/cfgov-refresh/languages","stargazers_url":"https://api.github.com/repos/cfpb/cfgov-refresh/stargazers","contributors_url":"https://api.github.com/repos/cfpb/cfgov-refresh/contributors","subscribers_url":"https://api.github.com/repos/cfpb/cfgov-refresh/subscribers","subscription_url":"https://api.github.com/repos/cfpb/cfgov-refresh/subscription","commits_url":"https://api.github.com/repos/cfpb/cfgov-refresh/commits{/sha}","git_commits_url":"https://api.github.com/repos/cfpb/cfgov-refresh/git/commits{/sha}","comments_url":"https://api.github.com/repos/cfpb/cfgov-refresh/comments{/number}","issue_comment_url":"https://api.github.com/repos/cfpb/cfgov-refresh/issues/comments{/number}","contents_url":"https://api.github.com/repos/cfpb/cfgov-refresh/contents/{+path}","compare_url":"https://api.github.com/repos/cfpb/cfgov-refresh/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cfpb/cfgov-refresh/merges","archive_url":"https://api.github.com/repos/cfpb/cfgov-refresh/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cfpb/cfgov-refresh/downloads","issues_url":"https://api.github.com/repos/cfpb/cfgov-refresh/issues{/number}","pulls_url":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls{/number}","milestones_url":"https://api.github.com/repos/cfpb/cfgov-refresh/milestones{/number}","notifications_url":"https://api.github.com/repos/cfpb/cfgov-refresh/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cfpb/cfgov-refresh/labels{/name}","releases_url":"https://api.github.com/repos/cfpb/cfgov-refresh/releases{/id}","deployments_url":"https://api.github.com/repos/cfpb/cfgov-refresh/deployments","created_at":"2014-04-16T19:22:03Z","updated_at":"2016-08-10T00:12:07Z","pushed_at":"2016-08-15T20:20:09Z","git_url":"git://github.com/cfpb/cfgov-refresh.git","ssh_url":"git@github.com:cfpb/cfgov-refresh.git","clone_url":"https://github.com/cfpb/cfgov-refresh.git","svn_url":"https://github.com/cfpb/cfgov-refresh","homepage":"http://www.consumerfinance.gov/","size":129035,"stargazers_count":70,"watchers_count":70,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":38,"mirror_url":null,"open_issues_count":105,"forks":38,"open_issues":105,"watchers":70,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/2308"},"html":{"href":"https://github.com/cfpb/cfgov-refresh/pull/2308"},"issue":{"href":"https://api.github.com/repos/cfpb/cfgov-refresh/issues/2308"},"comments":{"href":"https://api.github.com/repos/cfpb/cfgov-refresh/issues/2308/comments"},"review_comments":{"href":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/2308/comments"},"review_comment":{"href":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cfpb/cfgov-refresh/pulls/2308/commits"},"statuses":{"href":"https://api.github.com/repos/cfpb/cfgov-refresh/statuses/af4665c727ce176fc90a7a2840b5eb3ff56a3041"}}}}
{"actor":{"display_login":"anselmbradford"}}