Skip to content

Commit

Permalink
Merge pull request #27188 from guardian/dina/prepare-code-to-remove-ga
Browse files Browse the repository at this point in the history
Prepare code to remove `GA` from Web and AMP
  • Loading branch information
deedeeh authored Jun 11, 2024
2 parents 295a97c + 3bf743d commit 679fea2
Show file tree
Hide file tree
Showing 45 changed files with 7 additions and 1,127 deletions.
14 changes: 1 addition & 13 deletions admin/app/jobs/AnalyticsSanityCheckJob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,22 @@ class AnalyticsSanityCheckJob(ophanApi: OphanApi) extends GuLogging {
},
)

val googleConversionRate = GaugeMetric(
name = "google-percent-conversion",
description = "The percentage of raw page views that contain a recorded Google Analytics page view",
metricUnit = StandardUnit.Percent,
get = () => {
googlePageViews.get.toDouble / rawPageViews.get.toDouble * 100.0d
},
)

def run()(implicit executionContext: ExecutionContext): Unit = {

val fRawPageViews: Future[GetMetricStatisticsResult] = CloudWatchStats.rawPageViews()
val fGooglePageViews = CloudWatchStats.googleAnalyticsPageViews()
val fOphanViews = ophanViews()
for {
rawPageViewsStats <- fRawPageViews
googlePageViewsStats <- fGooglePageViews
ophanViewsCount <- fOphanViews
} yield {

def metricLastSum(stats: GetMetricStatisticsResult): Long =
stats.getDatapoints.asScala.headOption.map(_.getSum.longValue).getOrElse(0L)

rawPageViews.set(metricLastSum(rawPageViewsStats))
googlePageViews.set(metricLastSum(googlePageViewsStats))
ophanPageViews.set(ophanViewsCount)

CloudWatch.putMetrics("Analytics", List(ophanConversionRate, googleConversionRate), List.empty)
CloudWatch.putMetrics("Analytics", List(ophanConversionRate), List.empty)
}

}
Expand Down
3 changes: 0 additions & 3 deletions admin/app/services/CloudWatchStats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,4 @@ object CloudWatchStats extends GuLogging {

def rawPageViews()(implicit executionContext: ExecutionContext): Future[GetMetricStatisticsResult] =
sanityData("kpis-page-views")

def googleAnalyticsPageViews()(implicit executionContext: ExecutionContext): Future[GetMetricStatisticsResult] =
sanityData("kpis-analytics-page-views-google")
}
10 changes: 0 additions & 10 deletions admin/test/resources/pagepresser/r2/interactivePageWithJQuery.html
Original file line number Diff line number Diff line change
Expand Up @@ -1662,16 +1662,6 @@ <h3>Contact us</h3>
<div id='recipe-grid'>
</div>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-33493121-29', 'theguardian.com');
ga('send', 'pageview');

</script>
</div>
<script>
// send the query string to the iFrame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,16 +682,6 @@ <h3>Contact us</h3>
</style>
<div id="recipe-grid">
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-33493121-29', 'theguardian.com');
ga('send', 'pageview');

</script>
</div>
<script>
// send the query string to the iFrame
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

<amp-analytics config="https://ophan.theguardian.com/amp.json" @if(context.environment.mode != Mode.Dev) { data-credentials="include" }></amp-analytics>

@fragments.amp.hostedGoogleAnalytics(page)
<amp-analytics id="comscore" type="comscore">
<script type="application/json">{ "vars": { "c2": "6035250" } }</script>
</amp-analytics>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
}/count/pv.gif"></amp-pixel>

<amp-analytics config="https://ophan.theguardian.com/amp.json" @if(context.environment.mode != Mode.Dev) { data-credentials="include" }></amp-analytics>
@fragments.amp.hostedGoogleAnalytics(page)

<amp-analytics id="comscore" type="comscore">
<script type="application/json">{ "vars": { "c2": "6035250" } }</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<body>

<amp-analytics config="https://ophan.theguardian.com/amp.json" @if(context.environment.mode != Mode.Dev) { data-credentials="include" }></amp-analytics>
@fragments.amp.hostedGoogleAnalytics(page)
<amp-analytics id="comscore" type="comscore">
<script type="application/json">{ "vars": { "c2": "6035250" } }</script>
</amp-analytics>
Expand Down
10 changes: 0 additions & 10 deletions common/app/conf/switches/MonitoringSwitches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ trait MonitoringSwitches {
exposeClientSide = false,
)

val BoostGAUserTimingFidelity = Switch(
SwitchGroup.Monitoring,
"boost-ga-user-timing-fidelity",
"CAUTION: check with [email protected] before enabling. Extends the standard 0.1% sampling of user timing events on Google Analytics to 100%. Will send a LOT more events to GA, which costs $$$.",
owners = Seq(Owner.withName("unknown")),
safeState = Off,
sellByDate = never,
exposeClientSide = true,
)

val LogRemovedAmpElements = Switch(
SwitchGroup.Monitoring,
"log-removed-amp-elements",
Expand Down
4 changes: 0 additions & 4 deletions common/app/dev/DevParametersHttpRequestHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ class DevParametersHttpRequestHandler(
"dll", // Disable lazy loading of ads
"iasdebug", // IAS troubleshooting
"cmpdebug", // CMP troubleshooting
"utm_source", // Google Analytics source
"utm_medium", // Google Analytics medium
"utm_campaign", // Google Analytics campaign
"utm_term", // Google Analytics term
"sfdebug", // enable spacefinder visualiser. '1' = inline ads (first pass), '2' = inline ads (second pass), 'im' = inline merchandising ads, 'carrot' = carrot ads
"rikerdebug", // enable debug logging for Canadian ad setup managed by the Globe and Mail
"forceSendMetrics", // enable force sending of commercial metrics
Expand Down
1 change: 0 additions & 1 deletion common/app/model/meta.scala
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ case class MetaData(

/**
* Content type, lowercased and with spaces removed.
* This is used for Google Analytics, to be consistent with what the mobile apps do.
*/
def normalisedContentType: String = StringUtils.remove(contentType.map(_.name.toLowerCase).getOrElse(""), ' ')
}
Expand Down
1 change: 0 additions & 1 deletion common/app/navigation/helpers/UrlHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ object UrlHelpers {

import io.lemonlabs.uri.typesafe.dsl._

// INTCMP is passed as a separate param because people look at it in Google Analytics
// It's set to the most specific thing (componentId) to maximise its usefulness
val url = destination.url ? ("INTCMP" -> componentId) & ("acquisitionData" -> acquisitionData.toString)
Url.parse(url.toString).toString
Expand Down
3 changes: 0 additions & 3 deletions common/app/templates/inlineJS/blocking/config.scala.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ window.guardian = {
active: undefined,
onDetect: []
},
googleAnalytics: {
initialiseGa: undefined
},
config: @JavaScript(templates.js.javaScriptConfig(page).body)
};

Expand Down
10 changes: 1 addition & 9 deletions common/app/templates/javaScriptConfig.scala.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@import conf.Static
@import conf.Configuration
@import play.api.libs.json.Json
@import views.support.{CamelCase, JavaScriptPage, GoogleAnalyticsAccount}
@import views.support.{CamelCase, JavaScriptPage}
@import conf.Configuration.environment
@import navigation.NavMenu

Expand Down Expand Up @@ -46,14 +46,6 @@
}
}
},
"googleAnalytics": {
"trackers": {
"editorialTest": "@{GoogleAnalyticsAccount.editorialTest.trackerName}",
"editorialProd": "@{GoogleAnalyticsAccount.editorialProd.trackerName}",
"editorial": "@{GoogleAnalyticsAccount.editorialTracker(context).trackerName}"
},
"timingEvents": []
},
"libs": {
"googletag": "@{Configuration.javascript.config("googletagJsUrl")}",
"cmp": { "fullVendorDataUrl": "/commercial/cmp/vendorlist.json",
Expand Down
1 change: 0 additions & 1 deletion common/app/views/fragments/analytics/base.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
Core Analytics
******************************************************************************@

@fragments.analytics.google(page)
}
166 changes: 0 additions & 166 deletions common/app/views/fragments/analytics/google.scala.html

This file was deleted.

2 changes: 1 addition & 1 deletion common/app/views/fragments/inlineJSNonBlocking.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

// ************* ANALYTICS *************

// Ophan pageview ID and browser ID are needed by Google Analytics, which runs just after this script tag
// Ophan pageview ID and browser ID
@InlineJs(ophanConfig().body, "ophanConfig.js")

@if(page.metadata.contentType.exists { c =>
Expand Down
Loading

0 comments on commit 679fea2

Please sign in to comment.