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 segment analytics #74

Merged
merged 3 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,9 @@
}

autoclass_content = 'both'

# qiskit package specific variables
html_context = {
'repo_name': 'Example Repo',
'analytics_enabled': True
}
23 changes: 13 additions & 10 deletions qiskit_sphinx_theme/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@
</div>
{% endif %}

{% if theme_pytorch_project == 'tutorials' %}
{% if analytics_enabled %}

<hr class="helpful-hr hr-top">
<div class="helpful-container">
<div class="helpful-question">Was this helpful?</div>
<div class="helpful-question yes-link" data-behavior="was-this-helpful-event" data-response="yes">Yes</div>
<div class="helpful-question no-link" data-behavior="was-this-helpful-event" data-response="no">No</div>
<div class="was-helpful-thank-you">Thank you</div>
<div class="helpful-question">Was this page helpful?</div>
<a class="helpful-question yes-link" onclick="clicked('yes')">Yes</a>
<a class="helpful-question no-link" onclick="clicked('no')">No</a>
<div class="was-helpful-thank-you" id="was-helpful-thank-you">Thank you!</div>
</div>
<hr class="helpful-hr hr-bottom"/>

{% else %}

<hr>


{% endif %}

<div role="contentinfo">
Expand Down Expand Up @@ -69,3 +65,10 @@

</footer>

<script>
function clicked(ctaType) {
document.getElementById('was-helpful-thank-you').style.visibility = 'visible';
window.trackCta(`Helpful - ${ctaType}`);
}
</script>

92 changes: 56 additions & 36 deletions qiskit_sphinx_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,63 @@
{% endif %}

<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
<!-- <link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" /> -->
{%- for css in css_files %}
{%- if css|attr("rel") %}
<link rel="{{ css.rel }}" href="{{ pathto(css.filename, 1) }}" type="text/css"{% if css.title is not none %} title="{{ css.title }}"{% endif %} />
{%- else %}
<link rel="stylesheet" href="{{ pathto(css, 1) }}" type="text/css" />
{%- endif %}
{%- endfor %}
{%- for cssfile in extra_css_files %}
<link rel="stylesheet" href="{{ pathto(cssfile, 1) }}" type="text/css" />
{%- endfor %}

{%- block linktags %}
{%- if hasdoc('about') %}
<link rel="author" title="{{ _('About these documents') }}" href="{{ pathto('about') }}" />
{%- endif %}
{%- if hasdoc('genindex') %}
<link rel="index" title="{{ _('Index') }}" href="{{ pathto('genindex') }}" />
{%- endif %}
{%- if hasdoc('search') %}
<link rel="search" title="{{ _('Search') }}" href="{{ pathto('search') }}" />
{%- endif %}
{%- if hasdoc('copyright') %}
<link rel="copyright" title="{{ _('Copyright') }}" href="{{ pathto('copyright') }}" />
{%- endif %}
{%- if next %}
<link rel="next" title="{{ next.title|striptags|e }}" href="{{ next.link|e }}" />
{%- endif %}
{%- if prev %}
<link rel="prev" title="{{ prev.title|striptags|e }}" href="{{ prev.link|e }}" />
{%- endif %}
{%- endblock %}
{%- block extrahead %} {% endblock %}

{# Keep modernizr in head - http://modernizr.com/docs/#installing #}
<script src="{{ pathto('_static/js/modernizr.min.js', 1) }}"></script>

<!-- SEGMENT ANALYTICS -->
{% if analytics_enabled %}
<script src="https://cloud.ibm.com/analytics/build/bluemix-analytics.min.js"></script>
<script>
(function () {
'use strict'
window._analytics = {
segment_key: 'ffdYLviQze3kzomaINXNk6NwpY9LlXcw',
coremetrics: false,
optimizely: false,
googleAddServices: false,
fullStory: false,
autoPageEventSpa: false,
autoFormEvents: false,
autoPageView: false
}

window.digitalData = {
page: {
pageInfo: {
productTitle: 'IBM Q Experience',
analytics: {
category: 'Qiskit.org'
}
}
}
}

if (!window.bluemixAnalytics || !window.digitalData) { return }

const category = window.digitalData.page.pageInfo.analytics.category
const productTitle = window.digitalData.page.pageInfo.productTitle
const routeName = 'documentation'

window.bluemixAnalytics.pageEvent(category, routeName, {
navigationType: 'pushState',
productTitle: productTitle,
title: document.title
})

window.trackCta = (action) => {
if (!window.bluemixAnalytics || !window.digitalData) { return }

const category = window.digitalData.page.pageInfo.analytics.category
const productTitle = window.digitalData.page.pageInfo.productTitle

window.bluemixAnalytics.trackEvent('CTA Clicked', {
productTitle,
category,
CTA: action
})
}

}());
</script>
{% endif %}
</head>

<div class="container-fluid header-holder tutorials-header" id="header-holder">
Expand Down
4 changes: 2 additions & 2 deletions qiskit_sphinx_theme/static/css/theme.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.