Skip to content

Commit

Permalink
Merge pull request #35060 from dimagi/ay/adblocker-gtm-fix-local
Browse files Browse the repository at this point in the history
Fixes the issue of adblocker blocking the tag manager HQ script
  • Loading branch information
ajeety4 authored Sep 4, 2024
2 parents 5c61109 + 64056d3 commit 2ed5b54
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion corehq/apps/analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Their script is included in [signup](https://github.com/dimagi/commcare-hq/blob/

### Google Tag Manager (GTM)

Its script is available in the [gtm.js](https://github.com/dimagi/commcare-hq/blob/master/corehq/apps/analytics/static/analytix/js/gtm.js) which loads the GTM tracking script and sends the desired user properties to GTM.
Its script is available in the [gtx.js](https://github.com/dimagi/commcare-hq/blob/master/corehq/apps/analytics/static/analytix/js/gtx.js) which loads the GTM tracking script and sends the desired user properties to GTM.
Any tracking of events should be configured at the GTM console end in tandem with the desired analytics tooling. The goal is to track specific features in HQ and also disable them when there is no need via the GTM console itself.
Any `id` attribute added to html element for tracking through console should be prefixed with `gtm-` to indicate that this element is likely being tracked in GTM.
This should potentially avoid accidental removal of id attribute from these elements. (Similar approach may be followed for any tooling in case of tracking of elements through console.)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"use strict";
/**
* Handles communication with the google tag manager API.
* Handles communication with the google tag manager API.
* gtx is the filename because some ad blockers blocks 'gtm.js'*
*/
hqDefine('analytix/js/gtm', [
hqDefine('analytix/js/gtx', [
'jquery',
'underscore',
'analytix/js/initial',
Expand Down
3 changes: 2 additions & 1 deletion corehq/apps/analytics/templates/analytics/analytics_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<script src="{% static 'analytix/js/hubspot.js' %}"></script>
<script src="{% static 'analytix/js/drift.js' %}"></script>
<script src="{% static 'analytix/js/appcues.js' %}"></script>
<script src="{% static 'analytix/js/gtm.js' %}"></script>
{# gtx is the filename because some adblockers blocks 'gtm.js' #}
<script src="{% static 'analytix/js/gtx.js' %}"></script>
{% endcompress %}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hqDefine("hqwebapp/js/bootstrap3/base_main", [
'analytix/js/google',
'analytix/js/hubspot',
'analytix/js/kissmetrix',
'analytix/js/gtm',
'analytix/js/gtx',
'hqwebapp/js/bootstrap3/mobile_experience_warning',
], function () {
// nothing to do, this is just to define the dependencies for hqwebapp/base.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hqDefine("hqwebapp/js/bootstrap5/base_main", [
'analytix/js/google',
'analytix/js/hubspot',
'analytix/js/kissmetrix',
'analytix/js/gtm',
'analytix/js/gtx',
'hqwebapp/js/bootstrap5/mobile_experience_warning',
], function () {
// nothing to do, this is just to define the dependencies for hqwebapp/base.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<script src="{% static 'analytix/js/hubspot.js' %}"></script>
<script src="{% static 'analytix/js/drift.js' %}"></script>
<script src="{% static 'analytix/js/appcues.js' %}"></script>
<script src="{% static 'analytix/js/gtm.js' %}"></script>
<script src="{% static 'analytix/js/gtx.js' %}"></script>

<script src="{% static 'knockout/build/output/knockout-latest.js' %}"></script>
<script src="{% static 'hqwebapp/js/lib/knockout_plugins/knockout_mapping.ko.min.js' %}"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<script src="{% static 'analytix/js/hubspot.js' %}"></script>
<script src="{% static 'analytix/js/drift.js' %}"></script>
<script src="{% static 'analytix/js/appcues.js' %}"></script>
<script src="{% static 'analytix/js/gtm.js' %}"></script>
<script src="{% static 'analytix/js/gtx.js' %}"></script>

<script src="{% static 'knockout/build/output/knockout-latest.js' %}"></script>
<script src="{% static 'hqwebapp/js/lib/knockout_plugins/knockout_mapping.ko.min.js' %}"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'analytix/js/google',
'analytix/js/hubspot',
'analytix/js/kissmetrix',
'analytix/js/gtm',
'analytix/js/gtx',
- 'hqwebapp/js/bootstrap3/mobile_experience_warning',
+ 'hqwebapp/js/bootstrap5/mobile_experience_warning',
], function () {
Expand Down

0 comments on commit 2ed5b54

Please sign in to comment.