Skip to content

Commit

Permalink
Merge pull request #6 from virtual-labs/fix-ui-3.0-exp-js-integration
Browse files Browse the repository at this point in the history
added analytics
  • Loading branch information
BalammaBoya authored Nov 4, 2020
2 parents 405bbeb + d78f724 commit 2fc841a
Show file tree
Hide file tree
Showing 1,216 changed files with 62,927 additions and 70,243 deletions.
110 changes: 110 additions & 0 deletions scripts/gtm-patcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/python

from bs4 import BeautifulSoup, Tag, Comment
import sys

headSnippet = """(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');"""

iframeSrc = "https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR"


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>"
def patch_php(filepath):
# print(filepath)
try:
if(1):
f1 = open(filepath,"r")
lines = f1.readlines()
string_inserted = ''
for line in lines:
if("<script class='gtm'>" in line):
return
f1.close()
if(1):
# print(filepath)
f1 = open(filepath,"r")
lines = f1.readlines()
# print(lines)
string_inserted = ''
for line in lines:
if('<head>' in line):
line = line.split('<head>')
temp_string = line[0]
temp_string+='<head>\n'
temp_string+=insert_head+'\n'
for i in line[1:]:
temp_string+=i
line = temp_string
string_inserted+=line
print(string_inserted)
f1.close()
f = open(filepath,"w")
f.write(string_inserted)
f.close()

except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
return -1
except:
print "Unexpected error:", sys.exc_info()[0]
return -2
print "Analytics Patched Successfully"
return 0

# load the file
def patch(filepath):
if("php" in filepath):
patch_php(filepath)
return 0
try:
with open(filepath) as inf:
txt = inf.read()
# soup = BeautifulSoup(txt, 'html.parser')
soup = BeautifulSoup(txt, "html5lib")
mydiv = soup.head.find('script', { 'class': 'gtm' })
if not mydiv:
scrTag = Tag(soup, name = 'script')
scrTag['class'] = "gtm"
scrTag.string = headSnippet
soup.head.insert(0, Comment('End Google Tag Manager'))
soup.head.insert(0, scrTag)
soup.head.insert(0, Comment('Google Tag Manager'))
#scrTag.insert_before(Comment('Google Tag Manager'))
#scrTag.insert_after(Comment('End Google Tag Manager'))

# insert body snippet into the document
iframeTag = Tag(soup, name = 'iframe')
iframeTag['src'] = iframeSrc
iframeTag['height'] = "0"
iframeTag['width'] = "0"
iframeTag['style'] = "display:none;visibility:hidden"

noscrTag = Tag(soup, name = 'noscript')
noscrTag['class'] = 'gtm'
noscrTag.insert(0, iframeTag)
soup.body.insert(0, Comment('End Google Tag Manager (noscript)'))
soup.body.insert(0, noscrTag)
soup.body.insert(0, Comment('Google Tag Manager (noscript)'))
#noscrTag.insert_before(Comment('Google Tag Manager (noscript)'))
#noscrTag.insert_after(Comment('End Google Tag Manager (noscript)'))

# save the file again
with open(filepath, 'w') as outf:
outf.write(str(soup))

except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
return -1
except:
print "Unexpected error:", sys.exc_info()[0]
return -2
print "Analytics Patched Successfully"
return 0


if __name__=='__main__':
patch(sys.argv[1])
17 changes: 17 additions & 0 deletions scripts/patch-analytics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
in_dir(){
for entry in $1/*".php"
do
"../scripts/gtm-patcher.py" "$entry"
done
for entry in $1/*".html"
do
"../scripts/gtm-patcher.py" "$entry"
done
for entry in $1/*
do
if [ -d "${entry}" ] ; then
in_dir $entry
fi
done
}
in_dir "."
46 changes: 24 additions & 22 deletions src/documents/installFlash.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!--?xml version="1.0" encoding="iso-8859-1"?--><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"><head><!--Google Tag Manager--><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><!--End Google Tag Manager-->
<title>installFlash</title>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/>
<meta name="title" content="installFlash"/>
<meta name="generator" content="Org-mode"/>
<meta name="generated" content="2014-12-23T16:50+0530"/>
<meta name="author" content="apurv"/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<meta content="installFlash" name="title"/>
<meta content="Org-mode" name="generator"/>
<meta content="2014-12-23T16:50+0530" name="generated"/>
<meta content="apurv" name="author"/>
<meta content="" name="description"/>
<meta content="" name="keywords"/>
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
html { font-family: Times, serif; font-size: 12pt; }
Expand Down Expand Up @@ -108,7 +109,7 @@
</script>

</head>
<body>
<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)-->

<div id="preamble">

Expand Down Expand Up @@ -139,7 +140,7 @@ <h2>Table of Contents</h2>
</div>
</div>

<div id="outline-container-1" class="outline-2">
<div class="outline-2" id="outline-container-1">
<h2 id="sec-1"><span class="section-number-2">1</span> Flash Plugin</h2>
<div class="outline-text-2" id="text-1">

Expand All @@ -154,15 +155,15 @@ <h2 id="sec-1"><span class="section-number-2">1</span> Flash Plugin</h2>

</div>

<div id="outline-container-1-1" class="outline-3">
<div class="outline-3" id="outline-container-1-1">
<h3 id="sec-1-1"><span class="section-number-3">1.1</span> For Linux</h3>
<div class="outline-text-3" id="text-1-1">



</div>

<div id="outline-container-1-1-1" class="outline-4">
<div class="outline-4" id="outline-container-1-1-1">
<h4 id="sec-1-1-1"><span class="section-number-4">1.1.1</span> GUI ( Graphical User Interface ) Installation</h4>
<div class="outline-text-4" id="text-1-1-1">

Expand Down Expand Up @@ -217,7 +218,7 @@ <h4 id="sec-1-1-1"><span class="section-number-4">1.1.1</span> GUI ( Graphical U

</div>

<div id="outline-container-1-1-2" class="outline-4">
<div class="outline-4" id="outline-container-1-1-2">
<h4 id="sec-1-1-2"><span class="section-number-4">1.1.2</span> CLI ( Command Line Interface ) Installation</h4>
<div class="outline-text-4" id="text-1-1-2">

Expand Down Expand Up @@ -258,7 +259,7 @@ <h4 id="sec-1-1-2"><span class="section-number-4">1.1.2</span> CLI ( Command Lin

</div>

<div id="outline-container-1-2" class="outline-3">
<div class="outline-3" id="outline-container-1-2">
<h3 id="sec-1-2"><span class="section-number-3">1.2</span> For Window</h3>
<div class="outline-text-3" id="text-1-2">

Expand All @@ -284,7 +285,7 @@ <h3 id="sec-1-2"><span class="section-number-3">1.2</span> For Window</h3>

</div>

<div id="outline-container-1-3" class="outline-3">
<div class="outline-3" id="outline-container-1-3">
<h3 id="sec-1-3"><span class="section-number-3">1.3</span> Testing installation</h3>
<div class="outline-text-3" id="text-1-3">

Expand All @@ -295,7 +296,7 @@ <h3 id="sec-1-3"><span class="section-number-3">1.3</span> Testing installation<

</div>

<div id="outline-container-1-4" class="outline-3">
<div class="outline-3" id="outline-container-1-4">
<h3 id="sec-1-4"><span class="section-number-3">1.4</span> Browser Settings</h3>
<div class="outline-text-3" id="text-1-4">

Expand Down Expand Up @@ -330,5 +331,6 @@ <h3 id="sec-1-4"><span class="section-number-3">1.4</span> Browser Settings</h3>
<a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a>

</div>
</body>
</html>


</body></html>
Loading

0 comments on commit 2fc841a

Please sign in to comment.