Skip to content

Commit b49d2e8

Browse files
committed
Wire up Google Analytics + FB Pixel event tracking
This sets up initial tracking for clicks on: - Quick Start Module Local Install - Quick Start Module Cloud Partners - Get Started CTA buttons - Ecosystem Project cards - Resource Project cards - Global nav menu Note the Jekyll environment must be 'production' for events to register.
1 parent 684d42c commit b49d2e8

File tree

5 files changed

+96
-5
lines changed

5 files changed

+96
-5
lines changed

_includes/footer_scripts.html

+5
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@
3232
});
3333
}
3434
</script>
35+
36+
{% if jekyll.environment == 'production' %}
37+
<script src="{{ site.baseurl }}/assets/track-events.js"></script>
38+
<script>trackEvents.bind();</script>
39+
{% endif %}

assets/quick-start-module.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ ptbuild.on("click", function() {
4141
selectedOption(ptbuild, this, "ptbuild")
4242
});
4343

44-
// Force a selection onclick to get the right operating system selected from
45-
// the start
44+
// Pre-select user's operating system
4645
$(document).ready(function() {
47-
document.getElementById(opts.os).click();
46+
var userOsOption = document.getElementById(opts.os);
47+
48+
if (userOsOption) {
49+
selectedOption(os, userOsOption, "os");
50+
}
4851
});
4952

5053

assets/track-events.js

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
var trackEvents = {
2+
recordClick: function(eventCategory, eventLabel) {
3+
if (typeof ga == "function") {
4+
ga('send', 'event', {
5+
eventCategory: eventCategory,
6+
eventAction: "click",
7+
eventLabel: eventLabel
8+
});
9+
}
10+
11+
if (typeof fbq === "function") {
12+
fbq("trackCustom", eventCategory, {
13+
target: eventLabel
14+
});
15+
}
16+
},
17+
18+
bind: function() {
19+
// Clicks on the main menu
20+
$(".main-menu ul li a").on("click", function() {
21+
trackEvents.recordClick("Global Nav", $(this).text());
22+
return true;
23+
});
24+
25+
// Clicks on Resource cards
26+
$(".resource-card a").on("click", function() {
27+
trackEvents.recordClick("Resource Card", $(this).find("h4").text());
28+
return true;
29+
});
30+
31+
// Clicks on Ecosystem Project cards
32+
$(".ecosystem-card a").on("click", function() {
33+
trackEvents.recordClick("Ecosystem Project Card", $(this).find("h4").text());
34+
return true;
35+
});
36+
37+
// Clicks on 'Get Started' call to action buttons
38+
$("[data-cta='get-started']").on("click", function() {
39+
trackEvents.recordClick("Get Started CTA", $(this).text());
40+
return true;
41+
});
42+
43+
// Clicks on Cloud Platforms in Quick Start Module
44+
$(".cloud-option").on("click", function() {
45+
var platformName = $.trim($(this).find(".cloud-option-body").text());
46+
trackEvents.recordClick("Quick Start Module - Cloud Platforms", platformName);
47+
});
48+
49+
// Clicks on Cloud Platform Services in Quick Start Module
50+
$(".cloud-option ul li a").on("click", function() {
51+
var platformName = $.trim(
52+
$(this).
53+
closest("[data-toggle='cloud-dropdown']").
54+
find(".cloud-option-body").
55+
text()
56+
);
57+
58+
var serviceName = $.trim($(this).text());
59+
60+
trackEvents.recordClick(
61+
"Quick Start Module - Cloud Platforms",
62+
platformName + " - " + serviceName
63+
);
64+
65+
return true;
66+
});
67+
68+
// Clicks on options in Quick Start - Locally
69+
$(".quick-start-module .row .option").on("click", function() {
70+
var selectedOption = $.trim($(this).text());
71+
var rowIndex = $(this).closest(".row").index();
72+
var selectedCategory = $(".quick-start-module .headings .title-block").
73+
eq(rowIndex).
74+
find(".option-text").
75+
text();
76+
77+
trackEvents.recordClick(
78+
"Quick Start Module - Local Install",
79+
selectedCategory + ": " + selectedOption
80+
)
81+
})
82+
}
83+
};

features.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End-to-end
1616
<p class="lead">PyTorch enables fast, flexible experimentation and efficient production through a hybrid front-end, distributed training, and ecosystem of tools and libraries.
1717
</p>
1818

19-
<a href="{{ site.baseurl }}/get-started" class="btn btn-lg with-right-arrow btn-white">
19+
<a href="{{ site.baseurl }}/get-started" class="btn btn-lg with-right-arrow btn-white" data-cta="get-started">
2020
Get Started
2121
</a>
2222
</div>

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h1>From<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Research To<br />Product
1010

1111
<p class="lead">An open source deep learning platform that provides a seamless path from research prototyping to production deployment.</p>
1212

13-
<a href="{{ site.baseurl }}/get-started" class="btn btn-lg with-right-arrow">
13+
<a href="{{ site.baseurl }}/get-started" class="btn btn-lg with-right-arrow" data-cta="get-started">
1414
Get Started
1515
</a>
1616
</div>

0 commit comments

Comments
 (0)