asked on
Replace Google Analytics with other type
My customer has been using Google Analytics in all the programs in several apps for a long time. The code is like this:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-PE5G5Y55LG"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-PE5G5Y55LG');
</script>
They want to replace this with another form of Analytics. I use Text Crawler (V3), Pro, to do search & replace in text files (Windows 10). I pasted in the code above into the "Search" line & the replacement into the "Replace" line. It only replaces the first line (<!-- Global......) with the other text. I notice there is a "Regular Expression" option, I don't know what that means in this context. Would that do multiple lines?
In doing a search it looks like I MIGHT be able to do this in Notepad++, which I use all the time, but it's not clear how. I want to do MULTIPLE files, find text block A, replace with text block B.
Is there a way to do that in Text Crawler or do I have to use something else. If something else, what is it. I realize I could write a program in php to do this, prefer not to have to do that.
Thank you
ASKER
Thanks
I use PHP storm for my sites and PHP storm has this feature and that is what I have been using for search and replace in multiple files.
Personal I would look whether a centralized file
Have a local file as
Analyitics.js
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-PE5G5Y55LG"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-PE5G5Y55LG');
</script>
Test whether that wouldwork
This way shoukd you need tochange,
Single file thatis all it takes.
To avoid this scenario in the future.
ASKER
I use Notepad++ all the time to do the simple stuff, like the example shows.
But I figured another way, there are only 8 lines in the Google block (not counting blank lines). I can erase those one at a time (8 passes) & then replace </head> with the new (one line) link followed by </head>
Richard
ASKER
Richard
and actually create a template
<!-- analytic start -->
<!-- analytic end -->
whether the above is a single block of code or a reference to a file ...
ASKER
That is EXACTLY what I did originally. It worked. So I assumed it would work for all.
It didn't.
Richard
(remember to save the changes)
ASKER
I'll try it.
Richard