Skip to content

Commit 7a6e77d

Browse files
committed
fix theory and intro
1 parent 35321a1 commit 7a6e77d

File tree

454 files changed

+14228
-13501
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

454 files changed

+14228
-13501
lines changed

scripts/gtm-patcher.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/python
2+
3+
from bs4 import BeautifulSoup, Tag, Comment
4+
import sys
5+
6+
headSnippet = """(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
7+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
8+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
9+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
10+
})(window,document,'script','dataLayer','GTM-W59SWTR');"""
11+
12+
iframeSrc = "https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR"
13+
14+
15+
insert_head = "<script class='gtm'>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-W59SWTR');</script>"
16+
def patch_php(filepath):
17+
# print(filepath)
18+
try:
19+
if(1):
20+
f1 = open(filepath,"r")
21+
lines = f1.readlines()
22+
string_inserted = ''
23+
for line in lines:
24+
if("<script class='gtm'>" in line):
25+
return
26+
f1.close()
27+
if(1):
28+
# print(filepath)
29+
f1 = open(filepath,"r")
30+
lines = f1.readlines()
31+
# print(lines)
32+
string_inserted = ''
33+
for line in lines:
34+
if('<head>' in line):
35+
line = line.split('<head>')
36+
temp_string = line[0]
37+
temp_string+='<head>\n'
38+
temp_string+=insert_head+'\n'
39+
for i in line[1:]:
40+
temp_string+=i
41+
line = temp_string
42+
string_inserted+=line
43+
print(string_inserted)
44+
f1.close()
45+
f = open(filepath,"w")
46+
f.write(string_inserted)
47+
f.close()
48+
49+
except IOError as e:
50+
print "I/O error({0}): {1}".format(e.errno, e.strerror)
51+
return -1
52+
except:
53+
print "Unexpected error:", sys.exc_info()[0]
54+
return -2
55+
print "Analytics Patched Successfully"
56+
return 0
57+
58+
# load the file
59+
def patch(filepath):
60+
if("php" in filepath):
61+
patch_php(filepath)
62+
return 0
63+
try:
64+
with open(filepath) as inf:
65+
txt = inf.read()
66+
# soup = BeautifulSoup(txt, 'html.parser')
67+
soup = BeautifulSoup(txt, "html5lib")
68+
mydiv = soup.head.find('script', { 'class': 'gtm' })
69+
if not mydiv:
70+
scrTag = Tag(soup, name = 'script')
71+
scrTag['class'] = "gtm"
72+
scrTag.string = headSnippet
73+
soup.head.insert(0, Comment('End Google Tag Manager'))
74+
soup.head.insert(0, scrTag)
75+
soup.head.insert(0, Comment('Google Tag Manager'))
76+
#scrTag.insert_before(Comment('Google Tag Manager'))
77+
#scrTag.insert_after(Comment('End Google Tag Manager'))
78+
79+
# insert body snippet into the document
80+
iframeTag = Tag(soup, name = 'iframe')
81+
iframeTag['src'] = iframeSrc
82+
iframeTag['height'] = "0"
83+
iframeTag['width'] = "0"
84+
iframeTag['style'] = "display:none;visibility:hidden"
85+
86+
noscrTag = Tag(soup, name = 'noscript')
87+
noscrTag['class'] = 'gtm'
88+
noscrTag.insert(0, iframeTag)
89+
soup.body.insert(0, Comment('End Google Tag Manager (noscript)'))
90+
soup.body.insert(0, noscrTag)
91+
soup.body.insert(0, Comment('Google Tag Manager (noscript)'))
92+
#noscrTag.insert_before(Comment('Google Tag Manager (noscript)'))
93+
#noscrTag.insert_after(Comment('End Google Tag Manager (noscript)'))
94+
95+
# save the file again
96+
with open(filepath, 'w') as outf:
97+
outf.write(str(soup))
98+
99+
except IOError as e:
100+
print "I/O error({0}): {1}".format(e.errno, e.strerror)
101+
return -1
102+
except:
103+
print "Unexpected error:", sys.exc_info()[0]
104+
return -2
105+
print "Analytics Patched Successfully " + filepath
106+
return 0
107+
108+
109+
if __name__=='__main__':
110+
patch(sys.argv[1])

scripts/patch-analytics.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# This command applies the gtm-patcher.py script to each html and php file
4+
# recursively in the directory where it is executed. As this intended
5+
# applying analytics code to each lab and experiment file, this script
6+
# should be executed in the src/ directory.
7+
8+
# Any html file that starts with 'content' in its name, will be ignored
9+
# by the script as applying the script to these files breaks the page
10+
# structure.
11+
12+
# The gtm-patcher.py file comes from vlabs-analytics project which
13+
# can be found here: https://github.com/virtual-labs/vlabs-analytics
14+
15+
# NOTE: This command will change the src files.
16+
17+
find . -type f \
18+
\( \
19+
\( -name "*.html" -or -name "*.php" \) \
20+
! -name "content*.html" \
21+
\) \
22+
-exec ../scripts/gtm-patcher.py {} \;

src/lab/Courses Aligned.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<script src="tabs.js" type="text/javascript"></script>
3030
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-67558473-1', 'auto');ga('send', 'pageview');</script>
3131
</head>
32-
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm"><iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"></iframe></noscript><!--End Google Tag Manager (noscript)-->
32+
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm">&amp;amp;amp;lt;iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"&amp;amp;amp;gt;&amp;amp;amp;lt;/iframe&amp;amp;amp;gt;</noscript><!--End Google Tag Manager (noscript)-->
3333
<div id="top">
3434
<header>
3535
<!-- Navigation -->

src/lab/Feedback.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<script src="tabs.js" type="text/javascript"></script>
3030
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-67558473-1', 'auto');ga('send', 'pageview');</script>
3131
</head>
32-
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm"><iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"></iframe></noscript><!--End Google Tag Manager (noscript)-->
32+
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm">&amp;amp;amp;lt;iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"&amp;amp;amp;gt;&amp;amp;amp;lt;/iframe&amp;amp;amp;gt;</noscript><!--End Google Tag Manager (noscript)-->
3333
<div id="top">
3434
<header>
3535
<!-- Navigation -->

src/lab/Introduction.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<script src="tabs.js" type="text/javascript"></script>
3030
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-67558473-1', 'auto');ga('send', 'pageview');</script>
3131
</head>
32-
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm"><iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"></iframe></noscript><!--End Google Tag Manager (noscript)-->
32+
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm">&amp;amp;amp;lt;iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"&amp;amp;amp;gt;&amp;amp;amp;lt;/iframe&amp;amp;amp;gt;</noscript><!--End Google Tag Manager (noscript)-->
3333
<div id="top">
3434
<header>
3535
<!-- Navigation -->

src/lab/List of experiments.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<script src="tabs.js" type="text/javascript"></script>
3030
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-67558473-1', 'auto');ga('send', 'pageview');</script>
3131
</head>
32-
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm"><iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"></iframe></noscript><!--End Google Tag Manager (noscript)-->
32+
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm">&amp;amp;amp;lt;iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"&amp;amp;amp;gt;&amp;amp;amp;lt;/iframe&amp;amp;amp;gt;</noscript><!--End Google Tag Manager (noscript)-->
3333
<div id="top">
3434
<header>
3535
<!-- Navigation -->

src/lab/Prerequisites.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<script src="tabs.js" type="text/javascript"></script>
3030
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-67558473-1', 'auto');ga('send', 'pageview');</script>
3131
</head>
32-
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm"><iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"></iframe></noscript><!--End Google Tag Manager (noscript)-->
32+
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm">&amp;amp;amp;lt;iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"&amp;amp;amp;gt;&amp;amp;amp;lt;/iframe&amp;amp;amp;gt;</noscript><!--End Google Tag Manager (noscript)-->
3333
<div id="top">
3434
<header>
3535
<!-- Navigation -->

src/lab/Target Audience.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<script src="tabs.js" type="text/javascript"></script>
3030
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-67558473-1', 'auto');ga('send', 'pageview');</script>
3131
</head>
32-
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm"><iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"></iframe></noscript><!--End Google Tag Manager (noscript)-->
32+
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm">&amp;amp;amp;lt;iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"&amp;amp;amp;gt;&amp;amp;amp;lt;/iframe&amp;amp;amp;gt;</noscript><!--End Google Tag Manager (noscript)-->
3333
<div id="top">
3434
<header>
3535
<!-- Navigation -->

src/lab/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<title> UI Manual</title>
88
</head>
99

10-
<body><!--Google Tag Manager (noscript)--><noscript class="gtm"><iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"></iframe></noscript><!--End Google Tag Manager (noscript)-->
10+
<body><!--Google Tag Manager (noscript)--><noscript class="gtm">&amp;amp;amp;lt;iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"&amp;amp;amp;gt;&amp;amp;amp;lt;/iframe&amp;amp;amp;gt;</noscript><!--End Google Tag Manager (noscript)-->
1111

1212
<div id="lab"> <!-- The Lab Document Container-->
1313

src/lab/exp1/Experiment.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<script src="tabs.js" type="text/javascript"></script>
3030
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-67020197-1', 'auto');ga('send', 'pageview');</script>
3131
</head>
32-
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm"><iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"></iframe></noscript><!--End Google Tag Manager (noscript)-->
32+
<body class="index" id="page-top"><!--Google Tag Manager (noscript)--><noscript class="gtm">&amp;amp;amp;lt;iframe height="0" src="https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR" style="display:none;visibility:hidden" width="0"&amp;amp;amp;gt;&amp;amp;amp;lt;/iframe&amp;amp;amp;gt;</noscript><!--End Google Tag Manager (noscript)-->
3333
<div id="top">
3434
<header>
3535
<!-- Navigation -->

0 commit comments

Comments
 (0)