Skip to content
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

Merged
merged 37 commits into from
Jul 22, 2024
Merged

Conversation

rmbielby
Copy link
Contributor

@rmbielby rmbielby commented Nov 8, 2023

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.

@rmbielby rmbielby self-assigned this Nov 8, 2023
@rmbielby rmbielby marked this pull request as draft November 8, 2023 11:03
@rmbielby rmbielby added the enhancement New feature or request label Nov 8, 2023
@rmbielby rmbielby linked an issue Feb 5, 2024 that may be closed by this pull request
Copy link

@github-advanced-security github-advanced-security bot left a 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.

@rmbielby rmbielby marked this pull request as ready for review March 13, 2024 11:40
R/initialisers.R Dismissed Show dismissed Hide dismissed
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

Lines should not be more than 80 characters. This line is 85 characters.
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

Lines should not be more than 80 characters. This line is 104 characters.
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

Lines should not be more than 80 characters. This line is 104 characters.
R/initialisers.R Dismissed Show dismissed Hide dismissed
R/initialisers.R Outdated Show resolved Hide resolved
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

Lines should not be more than 80 characters. This line is 82 characters.
R/initialisers.R Dismissed Show dismissed Hide dismissed
R/initialisers.R Outdated Show resolved Hide resolved
Copy link
Contributor

@cjrace cjrace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor things in comments, some lintr things to either dismiss or address, plus a couple of notes returned when running devtools::check() locally, I've commented on some in line, but there's one more too:

Not 100% sure on this, but worth a quick check if we're doing something wrong?
image

README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
R/tidy_code.R Outdated Show resolved Hide resolved
R/initialisers.R Outdated Show resolved Hide resolved
R/initialisers.R Outdated Show resolved Hide resolved
R/initialisers.R Outdated Show resolved Hide resolved
R/initialisers.R Outdated Show resolved Hide resolved
google-analytics.html Outdated Show resolved Hide resolved
R/initialisers.R Outdated Show resolved Hide resolved
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

Lines should not be more than 80 characters. This line is 81 characters.
R/initialisers.R Dismissed Show dismissed Hide dismissed
@rmbielby
Copy link
Contributor Author

Few minor things in comments, some lintr things to either dismiss or address, plus a couple of notes returned when running devtools::check() locally, I've commented on some in line, but there's one more too:

Not 100% sure on this, but worth a quick check if we're doing something wrong?

Think I've covered everything above if you want to have another look through.

@cjrace
Copy link
Contributor

cjrace commented Jul 19, 2024

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

Lines should not be more than 80 characters. This line is 131 characters.
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

no visible global function definition for 'getURL'
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

no visible global function definition for '%>%'
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

no visible binding for global variable '.'
R/initialisers.R Dismissed Show dismissed Hide dismissed
R/initialisers.R Dismissed Show dismissed Hide dismissed
@cjrace cjrace assigned cjrace and unassigned rmbielby Jul 22, 2024
Copy link
Contributor

@cjrace cjrace left a 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/initialisers.R Outdated Show resolved Hide resolved
R/initialisers.R Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
inst/google-analytics.hml Outdated Show resolved Hide resolved
R/initialisers.R Outdated Show resolved Hide resolved
R/initialisers.R Outdated Show resolved Hide resolved
google-analytics.html Outdated Show resolved Hide resolved
@cjrace cjrace assigned rmbielby and unassigned cjrace Jul 22, 2024
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

Lines should not be more than 80 characters. This line is 82 characters.
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

Only use double-quotes.
backed those up before over-writing.")
user_input <- readline(
prompt = "Are you happy to overwrite the existing analytics script (y/N) "
) |>

Check notice

Code scanning / lintr

Indentation should be 4 spaces but is 6 spaces. Note

Indentation should be 4 spaces but is 6 spaces.
@rmbielby rmbielby merged commit 688c866 into main Jul 22, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function to create google analytics file
2 participants