-
Notifications
You must be signed in to change notification settings - Fork 2
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
Function to initialise google analytics html script #4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lintr found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
R/initialisers.R
Outdated
gtag('config', 'G-XXXXXXXXXX'); | ||
|
||
/* | ||
The custom trackers below can be tailored to match the inputs used in your dashboard. |
Check notice
Code scanning / lintr
Lines should not be more than 80 characters. This line is 85 characters. Note
R/initialisers.R
Outdated
|
||
$(document).on('click', 'ul#navlistPanel', function(e) { | ||
gtag('event', 'navlistPanel', {'event_category' : 'navbar click', | ||
'event_label' : document.querySelector('ul#navlistPanel > li.active > a').getAttribute('data-value') |
Check notice
Code scanning / lintr
Lines should not be more than 80 characters. This line is 104 characters. Note
R/initialisers.R
Outdated
|
||
$(document).on('click', 'ul#tabsetpanels', function(e) { | ||
gtag('event', 'tab panels', {'event_category' : 'tab panel clicks', | ||
'event_label' : document.querySelector('ul#tabsetpanels > li.active > a').getAttribute('data-value') |
Check notice
Code scanning / lintr
Lines should not be more than 80 characters. This line is 104 characters. Note
R/tidy_code.R
Outdated
@@ -6,7 +6,7 @@ | |||
#' @param subdirs List of sub-directories to | |||
#' (recursively search for R scripts to be styled) | |||
#' | |||
#' @return True or False value based on if scripts were changed | |||
#' @return TRUE if any changes have been made to any scripts, FALSE if all passed. |
Check notice
Code scanning / lintr
Lines should not be more than 80 characters. This line is 82 characters. Note
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R/initialisers.R
Outdated
" %>% gsub("XXXXXXXXXX", ga_code, .) | ||
if (file.exists("google-analytics.html")) { | ||
message("Analytics file already exists.") | ||
message("If you have any customisations in that file, make sure you've backed |
Check notice
Code scanning / lintr
Lines should not be more than 80 characters. This line is 81 characters. Note
Think I've covered everything above if you want to have another look through. |
R/initialisers.R
Outdated
) | ||
} | ||
|
||
webpage <- getURL("https://raw.githubusercontent.com/dfe-analytical-services/dfeshiny/analytsics-init/inst/google-analytics.hml") |
Check notice
Code scanning / lintr
Lines should not be more than 80 characters. This line is 131 characters. Note
R/initialisers.R
Outdated
) | ||
} | ||
|
||
webpage <- getURL("https://raw.githubusercontent.com/dfe-analytical-services/dfeshiny/analytsics-init/inst/google-analytics.hml") |
Check warning
Code scanning / lintr
no visible global function definition for 'getURL' Warning
R/initialisers.R
Outdated
} | ||
|
||
webpage <- getURL("https://raw.githubusercontent.com/dfe-analytical-services/dfeshiny/analytsics-init/inst/google-analytics.hml") | ||
html_script <- readLines(tc <- textConnection(webpage)) %>% |
Check warning
Code scanning / lintr
no visible global function definition for '%>%' Warning
R/initialisers.R
Outdated
|
||
webpage <- getURL("https://raw.githubusercontent.com/dfe-analytical-services/dfeshiny/analytsics-init/inst/google-analytics.hml") | ||
html_script <- readLines(tc <- textConnection(webpage)) %>% | ||
gsub("XXXXXXXXXX", ga_code, .) |
Check warning
Code scanning / lintr
no visible binding for global variable '.' Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few final comments @rmbielby
R/analytics.R
Outdated
backed those up before over-writing.") | ||
user_input <- stringr::str_trim( | ||
readline( | ||
prompt = "Are you happy to overwrite the existing analytics script (y/N) " |
Check notice
Code scanning / lintr
Lines should not be more than 80 characters. This line is 82 characters. Note
R/analytics.R
Outdated
write_out <- TRUE | ||
} | ||
if (write_out) { | ||
cat(html_script, file = "google-analytics.html", sep = '\n') |
Check notice
Code scanning / lintr
Only use double-quotes. Note
Adding a script to create a basic google-analyics.html file with a provided GA4 key.
The function
initialise_analytics()
creates the script and I've added some validation to check he provided key at least looks like a genuine GA4 key. I've also added some tests to make sure that validation is working.