Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add limited GA to the buyers guide #1974

Merged
merged 14 commits into from
Oct 23, 2018
Merged

Add limited GA to the buyers guide #1974

merged 14 commits into from
Oct 23, 2018

Conversation

Pomax
Copy link
Contributor

@Pomax Pomax commented Oct 18, 2018

Addresses some of the events in #1925, but not done in a real sense.

Added:

  • support link click event
  • "copy link" click event

note that bg-main.js does not import and init product-analytics.js yet

@cadecairos cadecairos temporarily deployed to foundation-mofostaging-pr-1974 October 18, 2018 23:04 Inactive
@Pomax
Copy link
Contributor Author

Pomax commented Oct 19, 2018

@alanmoo @mmmavis hopefully this is enough to just finish up on

@Pomax Pomax temporarily deployed to foundation-mofostaging-pr-1974 October 19, 2018 05:18 Inactive
@alanmoo alanmoo temporarily deployed to foundation-mofostaging-pr-1974 October 19, 2018 13:30 Inactive
@cadecairos cadecairos temporarily deployed to foundation-mofostaging-pr-1974 October 19, 2018 15:54 Inactive
@cadecairos cadecairos temporarily deployed to foundation-mofostaging-pr-1974 October 19, 2018 16:06 Inactive
@alanmoo alanmoo temporarily deployed to foundation-mofostaging-pr-1974 October 19, 2018 16:41 Inactive
@alanmoo alanmoo temporarily deployed to foundation-mofostaging-pr-1974 October 19, 2018 18:17 Inactive
Copy link
Contributor

@alanmoo alanmoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a reasonable start- I'm fine landing it to get some sort of GA in there.

@cadecairos cadecairos temporarily deployed to foundation-mofostaging-pr-1974 October 19, 2018 21:34 Inactive

let productLiveChat = document.querySelector(`#product-live-chat`);
let siteSocialButtonFacebook = document.querySelector(`#nav-social-button-fb`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well use document.getElementById if we're using it that much, since it's considerably faster than querySelector.

};
}

if (siteSocialButtonFacebook) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're repeating code this much, it's probably better to make this a single action, and then trigger them for each element:

function addAnalytics(elementId, category, action, label, beacon) {
  let element  = document.getElementById(elementId);
  if (element) {
    let opts = { category, action, label };
    if (beacon) { opts.transport = `beacon`; }
    element.onclick = () => ReactGA.event(opts); // <= this is... probably bad?
  } else {
    // we can warn about the fact that an expected element does not exist, here
  }
}

...

addAnalytics(`nav-social-button-fb`, `site`, `share tap`, `share site to facebook`, true);
// etc

Note the "this is probably bad", though, because onclick is a plain property: if something else sets an onclick first, that is now lost, and if something else sets an onclick later, that will remove the GA binding, so ideally we use addEventListener...

@Pomax Pomax changed the title [WIP] some GA... Add limited GA to the buyers guide Oct 22, 2018
@Pomax Pomax temporarily deployed to foundation-mofostaging-pr-1974 October 22, 2018 21:59 Inactive
@Pomax Pomax requested a review from mmmavis October 22, 2018 23:18
<a class="social-button social-button-fb hidden-sm-down" id="nav-social-button-fb" href="{{facebook_share_link}}"><span class="sr-only">Facebook</span></a>
<a class="social-button social-button-twitter hidden-sm-down" id="nav-social-button-twitter" href="{{twitter_share_link}}{{share_text|urlencode}}" target="_blank"><span class="sr-only">Twitter</span></a>
<a class="social-button social-button-email hidden-sm-down" id="nav-social-button-email" href="{{email_share_link}}{{share_text|urlencode}}"><span class="sr-only">Email</span></a>
<a class="social-button social-button-link copy-link hidden-sm-down" id="nave-social-button-link" href=""><span class="sr-only">Copy link</span></a>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nave typo?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we tracking clicks on mobile as well? If so let's add id to elements on mobile version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 let me add those

source/js/buyers-guide/product-analytics.js Show resolved Hide resolved

function getElementGAInformation(pageTitle, productName) {
return {
'product-live-chat`': {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra ` here

source/js/buyers-guide/product-analytics.js Show resolved Hide resolved
@Pomax Pomax temporarily deployed to foundation-mofostaging-pr-1974 October 23, 2018 01:02 Inactive
@Pomax Pomax requested a review from mmmavis October 23, 2018 01:24
@Pomax Pomax temporarily deployed to foundation-mofostaging-pr-1974 October 23, 2018 01:30 Inactive
@Pomax Pomax temporarily deployed to foundation-mofostaging-pr-1974 October 23, 2018 15:43 Inactive
@Pomax Pomax requested a review from alanmoo October 23, 2018 16:59
@Pomax Pomax temporarily deployed to foundation-mofostaging-pr-1974 October 23, 2018 16:59 Inactive
@alanmoo alanmoo temporarily deployed to foundation-mofostaging-pr-1974 October 23, 2018 17:03 Inactive
@Pomax Pomax removed the request for review from mmmavis October 23, 2018 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants