diff --git a/analytics/bodySnippet b/analytics/bodySnippet new file mode 100644 index 0000000..49a5b7d --- /dev/null +++ b/analytics/bodySnippet @@ -0,0 +1,4 @@ + + + diff --git a/analytics/headSnippet b/analytics/headSnippet new file mode 100644 index 0000000..7bab151 --- /dev/null +++ b/analytics/headSnippet @@ -0,0 +1,18 @@ + + + diff --git a/analytics/insert-analytics.sh b/analytics/insert-analytics.sh new file mode 100755 index 0000000..205f02d --- /dev/null +++ b/analytics/insert-analytics.sh @@ -0,0 +1,29 @@ +#!/bin/bash +root=expbuilds +chmod -R u+rwx $root +head_snippet=$(tr -d '\n' < analytics/headSnippet) +body_snippet=$(tr -d '\n' < analytics/bodySnippet) +topic_map=$(tr -d '\n' < analytics/topic_config.json) +function insert_analytics_snippets () { + fn=$1 + + if [ $(grep -c "window.dataLayer" $fn) == 0 ] + then + sed -i "s@@${head_snippet//&/\\&}@" $fn + sed -i "s@@${body_snippet//&/\\&}@" $fn + else + echo "analytics script already present." + echo + fi +} +# get the list of html pages +pages=$(find $root -not -path "*/themes/*" -type f -name "*.html") + +# insert snippets in all html pages +for p in $pages +do + #echo $p + insert_analytics_snippets $p +done + +find $root -name "*.html" -exec sed -i "s@TOPIC_MAP@$topic_map@" {} \; diff --git a/analytics/insert-analytics.sh~ b/analytics/insert-analytics.sh~ new file mode 100755 index 0000000..15ea8c0 --- /dev/null +++ b/analytics/insert-analytics.sh~ @@ -0,0 +1,29 @@ +#!/bin/bash +root=build/docs +chmod -R u+rwx $root +head_snippet=$(tr -d '\n' < analytics/headSnippet) +body_snippet=$(tr -d '\n' < analytics/bodySnippet) +topic_map=$(tr -d '\n' < analytics/topic_config.json) +function insert_analytics_snippets () { + fn=$1 + + if [ $(grep -c "window.dataLayer" $fn) == 0 ] + then + sed -i "s@@${head_snippet//&/\\&}@" $fn + sed -i "s@@${body_snippet//&/\\&}@" $fn + else + echo "analytics script already present." + echo + fi +} +# get the list of html pages +pages=$(find $root -not -path "*/themes/*" -type f -name "*.html") + +# insert snippets in all html pages +for p in $pages +do + #echo $p + insert_analytics_snippets $p +done + +find $root -name "*.html" -exec sed -i "s@TOPIC_MAP@$topic_map@" {} \; diff --git a/build_exp.sh b/build_exp.sh index 1846f23..555c245 100755 --- a/build_exp.sh +++ b/build_exp.sh @@ -42,21 +42,61 @@ cd exprepos/$reponame; git fetch --all; git checkout $tag; cd ../../ template=ui3template ## conversion + +## Copy template files to the build directory of the experiment. + mkdir -p expbuilds/$EXP_SHORT_NAME cp -r $template/* expbuilds/$EXP_SHORT_NAME -find expbuilds/$EXP_SHORT_NAME/*.html -maxdepth 1 -type f -exec sed -i "s/{{BROAD_AREA}}/$BROAD_AREA/g" {} + -find expbuilds/$EXP_SHORT_NAME/*.html -maxdepth 1 -type f -exec sed -i "s/{{LAB_NAME}}/$DISPLAY_LAB_NAME/g" {} + -find expbuilds/$EXP_SHORT_NAME/*.html -maxdepth 1 -type f -exec sed -i "s/{{COLLEGE_NAME}}/$COLLEGE_NAME/g" {} + -find expbuilds/$EXP_SHORT_NAME/*.html -maxdepth 1 -type f -exec sed -i "s/{{PHASE}}/$PHASE/g" {} + -find expbuilds/$EXP_SHORT_NAME/*.html -maxdepth 1 -type f -exec sed -i "s/{{EXP_NAME}}/$EXP_NAME/g" {} + -find expbuilds/$EXP_SHORT_NAME/*.html -maxdepth 1 -type f -exec sed -i "s/{{EXP_SHORT_NAME}}/$EXP_SHORT_NAME/g" {} + -find expbuilds/$EXP_SHORT_NAME/*.html -maxdepth 1 -type f -exec sed -i "s,{{BA_LINK}},$BROAD_AREA_LINK,g" {} + -find expbuilds/$EXP_SHORT_NAME/*.html -maxdepth 1 -type f -exec sed -i "s,{{LAB_LINK}},$LAB_LINK,g" {} + + +## Copy content (simulations, and other files like markdown, images etc) from the source repo directory +## to the build directory and rename it to "round-template". cp -r exprepos/$reponame expbuilds/$EXP_SHORT_NAME mv expbuilds/$EXP_SHORT_NAME/$reponame expbuilds/$EXP_SHORT_NAME/round-template + +## Insert analytics snippet in the "experiment" directory. +head_snippet=$(tr -d '\n' < analytics/headSnippet) +body_snippet=$(tr -d '\n' < analytics/bodySnippet) + +function insert_analytics_snippets () { + fn=$1 + bodytag=$(grep "@${head_snippet//&/\\&}@" $fn + sed -i "s@$bodytag@$bodytag${body_snippet//&/\\&}@" $fn + else + echo "analytics script already present." + echo + fi +} + +pages=$(find expbuilds/$EXP_SHORT_NAME/round-template/experiment/ -type f -name "*.html") + +echo $pages + +# insert snippets in all html pages +for p in $pages +do + echo $p + insert_analytics_snippets $p +done + + +## Replace the placeholders for the data layer variables with actual values. + +find expbuilds/$EXP_SHORT_NAME/ -type f -name "*.html" -exec sed -i "s/{{BROAD_AREA}}/$BROAD_AREA/g" {} + +find expbuilds/$EXP_SHORT_NAME/ -type f -name "*.html" -exec sed -i "s/{{LAB_NAME}}/$DISPLAY_LAB_NAME/g" {} + +find expbuilds/$EXP_SHORT_NAME/ -type f -name "*.html" -exec sed -i "s/{{COLLEGE_NAME}}/$COLLEGE_NAME/g" {} + +find expbuilds/$EXP_SHORT_NAME/ -type f -name "*.html" -exec sed -i "s/{{PHASE}}/$PHASE/g" {} + +find expbuilds/$EXP_SHORT_NAME/ -type f -name "*.html" -exec sed -i "s/{{EXP_NAME}}/$EXP_NAME/g" {} + +find expbuilds/$EXP_SHORT_NAME/ -type f -name "*.html" -exec sed -i "s/{{EXP_SHORT_NAME}}/$EXP_SHORT_NAME/g" {} + +find expbuilds/$EXP_SHORT_NAME/ -type f -name "*.html" -exec sed -i "s,{{BA_LINK}},$BROAD_AREA_LINK,g" {} + +find expbuilds/$EXP_SHORT_NAME/ -type f -name "*.html" -exec sed -i "s,{{LAB_LINK}},$LAB_LINK,g" {} + + + cp fixpointer.py expbuilds/$EXP_SHORT_NAME/round-template/experiment/simulation/ cd expbuilds/$EXP_SHORT_NAME/round-template/experiment/simulation/ python fixpointer.py