Skip to content

Commit d0b4f3f

Browse files
committed
[GA4] prod review changes
- htm -> html - inline play event uses normal content oid - sendEvent does deduping itself - handleEvent -> handleClick - courses goto just clicks the link - merge WEBSITE_SECTION (formerly "brand") into "category" - Better Cat3 detection for generic links - link hostname (formerly "cat4") -> "brand" - "cat4" is now authors (can be set on generic links via "data-content-authors") - add item_name
1 parent 68d9ce7 commit d0b4f3f

5 files changed

Lines changed: 65 additions & 61 deletions

File tree

‎_includes/content_filelinks.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="content_links">
33
{% if include.content.external_url %}
44
{% assign linkfmt = "" %}
5-
{%- capture linkbody -%}<i class="fa{% if include.content.external_url contains "youtu" %}{% assign linkfmt = "YouTube (link)" %}b fa-youtube"></i> YouTube{% elsif include.content.external_url contains "//www.academia.edu/" %}c-academia"></i>cademia.edu{% assign linkfmt = "Academia.edu" %}{% else %}s fa-{% assign ext = include.content.external_url | slice: -4, 4 %}{% if ext == ".pdf" %}{% assign linkfmt = "pdf" %}file-pdf"></i> pdf{% elsif ext == ".mp3" %}{% assign linkfmt = "mp3" %}file-audio"></i> mp3{% elsif ext == ".zip" %}{% assign linkfmt = "zip" %}file-archive"></i> zip{% else %}{% if ext == ".htm" %}{% assign linkfmt = "htm" %}{% elsif ext == "html" %}{% assign linkfmt = "html" %}{% endif %}{% case include.content.category %}{% when "av" %}volume-up{% when "booklets" %}book-open{% when "monographs" %}book-open{% else %}globe{% endcase %}"></i> Online{% endif %}{% endif %}{%- endcapture -%}
5+
{%- capture linkbody -%}<i class="fa{% if include.content.external_url contains "youtu" %}{% assign linkfmt = "YouTube (link)" %}b fa-youtube"></i> YouTube{% elsif include.content.external_url contains "//www.academia.edu/" %}c-academia"></i>cademia.edu{% assign linkfmt = "Academia.edu" %}{% else %}s fa-{% assign ext = include.content.external_url | slice: -4, 4 %}{% if ext == ".pdf" %}{% assign linkfmt = "pdf" %}file-pdf"></i> pdf{% elsif ext == ".mp3" %}{% assign linkfmt = "mp3" %}file-audio"></i> mp3{% elsif ext == ".zip" %}{% assign linkfmt = "zip" %}file-archive"></i> zip{% else %}{% if ext == ".htm" %}{% assign linkfmt = "html" %}{% elsif ext == "html" %}{% assign linkfmt = "html" %}{% endif %}{% case include.content.category %}{% when "av" %}volume-up{% when "booklets" %}book-open{% when "monographs" %}book-open{% else %}globe{% endcase %}"></i> Online{% endif %}{% endif %}{%- endcapture -%}
66
<a class="btn" {% if include.newtab %}target="_blank"{% endif %} {% include content_link_data_attributes.html content=include.content linktype="Main External URL" linkfmt=linkfmt %} href="{{ include.content.external_url }}"{% for nrh in site.data.content.noreferrerhosts %}{% if include.content.external_url contains nrh %} rel="noreferrer"{% break %}{% endif %}{% endfor %}>{{ linkbody }}</a>
77
{% endif %}
88
{% if include.content.file_links.size > 0 %}

‎_includes/content_link_data_attributes.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{%- if c.status == "featured" -%}{%- assign value = value | times: site.data.ga.featured_value_multiplier -%}{%- endif -%}
55
{%- if include.linktype == "Preview" -%}{%- assign value = value | times: 0.5 -%}{%- endif -%}
66
{%- if include.linktype == "WorldCat" -%}{%- assign value = 0.15 -%}{%- endif -%}
7-
ga-event-value="{{ value }}" data-content-path="{{ content_path }}" {% if include.linkfmt %}data-content-link-ext="{{ include.linkfmt }}" {% endif %}data-content-category="{{ c.category }}" data-content-subcat="{{ c.subcat }}" data-content-course="{{ c.course | default: 'archive' }}"
7+
data-content-title="{{ c.title | smartify | markdownify | strip_html | strip }}" ga-event-value="{{ value }}" data-content-path="{{ content_path }}" {% if include.linkfmt %}data-content-link-ext="{{ include.linkfmt }}" {% endif %}data-content-category="{{ c.category }}" data-content-subcat="{{ c.subcat }}" data-content-course="{{ c.course | default: 'archive' }}" data-content-authors="{{ c.authors | join: ", " }}"
88
{%- comment -%}
99
Only the common, data attributes are added here.
1010
The specific HREFs, etc are added in-situ

‎_includes/inline-av-player.html‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% assign rawfile = nil %}
1+
{%- assign rawfile = nil -%}
22
{% if include.content.slug %}
33
{% assign record = include.content %}
44
{% else %}
@@ -7,6 +7,7 @@
77
{% unless content_path contains record.slug %}
88
{% include content_path.liquid content=record %}
99
{% endunless %}
10+
{%- assign title = record.title | smartify | markdownify | strip_html | strip -%}
1011
{% if record.file_links[0] and record.file_links[0] != "" %}
1112
{% assign rawfile = site.data.content.filehost | append: record.file_links[0] %}
1213
{% assign ext = rawfile | slice: -4,4 %}
@@ -19,7 +20,7 @@
1920
{% if ext == ".mp3" or ext == ".m4a" or ext == ".mp4" or ext == ".ogg" or ext == ".aac" %}
2021
{% assign rawfile = record.external_url %}
2122
{% endif %}
22-
{% endif %}
23+
{%- endif -%}
2324
{% if record.external_url contains "youtu" %}{% unless record.external_url contains "list" %}
2425
<script>
2526
var tag = document.createElement('script');
@@ -50,12 +51,12 @@
5051
ga('send','event','Video','play','{{ content_path }}',Math.random()<{{ site.data.ga.av_start_val }}?1:0);
5152
window.uetq = window.uetq || []; window.uetq.push('event','c',{'event_category':'ol','event_label':'{{ content_path }}','revenue_value':{{ site.data.ga.av_start_val }},'currency':'USD'});
5253
started = true;
53-
buggytrack.sendEvent('{{ content_path }}#play',{{ site.data.ga.av_start_val }},['Content','av{% if record.subcat %}/{{ record.subcat }}{% endif %}','{{ record.course | default: 'archive' }}','youtu.be','Embedded YouTube Video']);
54+
buggytrack.sendEvent('{{ content_path }}','{{ title }}',{{ site.data.ga.av_start_val }},['content','av{% if record.subcat %}/{{ record.subcat }}{% endif %}','{{ record.course | default: 'archive' }}',"{{ record.authors | join: ", " }}",'Embedded YouTube Video'],'youtu.be');
5455
}
5556
if (event.data == YT.PlayerState.ENDED) {
5657
ga('send','event','Video','finish','{{ content_path }}',{{ site.data.ga.av_end_val }});
5758
window.uetq.push('event','c',{'event_category':'ol','event_label':'{{ content_path }}','revenue_value':{{ site.data.ga.av_end_val }},'currency':'USD'});
58-
buggytrack.sendEvent('{{ content_path }}#end',{{ site.data.ga.av_end_val }},['Content','av{% if record.subcat %}/{{ record.subcat }}{% endif %}','{{ record.course | default: 'archive' }}','youtu.be','Embedded YouTube Video']);
59+
buggytrack.sendEvent('{{ content_path }}#end','{{ title }}',{{ site.data.ga.av_end_val }},['content','av{% if record.subcat %}/{{ record.subcat }}{% endif %}','{{ record.course | default: 'archive' }}',"{{ record.authors | join: ", " }}",'Embedded YouTube Video'],'youtu.be');
5960
}
6061
{%- else -%}
6162
console.log(event.data);
@@ -77,9 +78,9 @@
7778
preload="metadata"
7879
style="width: 98%; margin-left: 1%"
7980
crossorigin="anonymous"
80-
onplay="ga('send','event','{{ tag | capitalize }}','play','{{ content_path }}',Math.random()<{{ site.data.ga.av_start_val }}?1:0); window.uetq = window.uetq || []; window.uetq.push('event','c',{'event_category':'ol','event_label':'{{ content_path }}','revenue_value':{{ site.data.ga.av_start_val }},'currency':'USD'}); gtag('event', 'video_start',{% capture gtagdata %} {video_duration: this.duration, video_current_time: this.currentTime, video_percent: (100*this.currentTime/this.duration), visible: true, video_url: '{{ rawfile }}', video_provider: '{% assign r = rawfile | split: '/' %}{{ r[2] }}', video_title: {{ include.content.title | jsonify | replace: '"', "'" }}}{% endcapture %}{{ gtagdata }});buggytrack.sendEvent('{{ content_path }}#play',{{ site.data.ga.av_start_val }},['Content','av{% if record.subcat %}/{{ record.subcat }}{% endif %}','{{ record.course | default: 'archive' }}','buddhistuniversity.net','Inline HTML5 {{ tag }} Player']);"
81-
onended="ga('send','event','{{ tag | capitalize }}','finish','{{ content_path }}',{{ site.data.ga.av_end_val }}); window.uetq.push('event','c',{'event_category':'ol','event_label':'{{ content_path }}','revenue_value':{{ site.data.ga.av_end_val }},'currency':'USD'}); gtag('event', 'video_complete', {{ gtagdata }});buggytrack.sendEvent('{{ content_path }}#end',{{ site.data.ga.av_end_val }},['Content','av{% if record.subcat %}/{{ record.subcat }}{% endif %}','{{ record.course | default: 'archive' }}','buddhistuniversity.net','Inline HTML5 {{ tag }} Player']);"
82-
ontimeupdate="Math.random()<0.01?gtag('event', 'video_progress', {{ gtagdata }}):undefined"
81+
onplay="ga('send','event','{{ tag | capitalize }}','play','{{ content_path }}',Math.random()<{{ site.data.ga.av_start_val }}?1:0); window.uetq = window.uetq || []; window.uetq.push('event','c',{'event_category':'ol','event_label':'{{ content_path }}','revenue_value':{{ site.data.ga.av_start_val }},'currency':'USD'}); gtag('event', 'video_start',{% capture gtagdata %} {video_duration: this.duration, video_current_time: this.currentTime, video_percent: (100*this.currentTime/this.duration), visible: true, video_url: '{{ rawfile }}', video_provider: '{% assign r = rawfile | split: '/' %}{{ r[2] }}', video_title: {{ record.title | jsonify | replace: '"', "'" }}}{% endcapture %}{{ gtagdata }});buggytrack.sendEvent('{{ content_path }}','{{ title }}',{{ site.data.ga.av_start_val }},['content','av{% if record.subcat %}/{{ record.subcat }}{% endif %}','{{ record.course | default: 'archive' }}','{{ record.authors | join: ", " | replace: "'", "\'" }}','Inline HTML5 {{ tag }} Player'],'buddhistuniversity.net');"
82+
onended="ga('send','event','{{ tag | capitalize }}','finish','{{ content_path }}',{{ site.data.ga.av_end_val }}); window.uetq.push('event','c',{'event_category':'ol','event_label':'{{ content_path }}','revenue_value':{{ site.data.ga.av_end_val }},'currency':'USD'}); gtag('event', 'video_complete', {{ gtagdata }});buggytrack.sendEvent('{{ content_path }}#end','{{ title }}',{{ site.data.ga.av_end_val }},['content','av{% if record.subcat %}/{{ record.subcat }}{% endif %}','{{ record.course | default: 'archive' }}','{{ record.authors | join: ", " | replace: "'", "\'" }}','Inline HTML5 {{ tag }} Player'],'buddhistuniversity.net');"
83+
ontimeupdate="Math.random()<0.00390625?gtag('event', 'video_progress', {{ gtagdata }}):undefined"
8384
>
8485
<source src="{{ rawfile }}" type="{{ mime }}">
8586
Your browser doesn't support playing this audio/video file inline.

‎assets/js/buggytrack.js‎

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ const BuggyTracker = function (d) {
5454
function linkInfo(link,l,p,gp,m){
5555
l=d.location.pathname;p=link.parentElement;gp=p.parentElement;
5656
m=l.match(publisherr);
57-
if(m && p.tagName=='H3') return ['publishers', m[1], 'html'];
57+
if(m) return p.tagName=='H3'?['publishers',m[1],'html']:['Generic Links',m[1]];
5858
m=l.match(seriesr);
59-
if(m && p.tagName=='H3') return ['series', m[1]];
59+
if(m) return [p.tagName=='H3'?'series':'Generic Links',m[1]];
6060
m=l.match(journalr);
61-
if(m && p.tagName=='H3') return ['journals', m[1], 'html'];
62-
if(p.className=='courselink' && l=='/courses/')
63-
return ['courses', 'external_courses'];
64-
if(link.className=='f3' && l=='/courses/') return ['courses', 'mit_courses', 'html'];
61+
if(m) return p.tagName=='H3'?['journals',m[1],'html']:['Generic Links',m[1]];
62+
if(l=='/courses/'){
63+
if(p.className=='courselink') return ['courses', 'external_courses'];
64+
if(link.className=='f3') return ['courses', 'mit_courses', 'html'];
65+
return ['Generic Links','courses'];
66+
}
6567
if(gp.className=='social-media-list') return ['marketing', 'social_media_links'];
6668
if(gp.className=='contact-list') return ['marketing', 'contact_links'];
6769
if(gp.tagName=='UL' && l=='/sources/')
@@ -70,12 +72,14 @@ const BuggyTracker = function (d) {
7072
link.getAttribute('data-slug') || link.text,
7173
'html'
7274
];
73-
return ['Generic Links', d.location.pathname];
75+
m=l.match(courser)||l.match(tagr)||l.match(authorr);
76+
if(m) return ['Generic Links',m[1]];
77+
return ['Generic Links', l];
7478
}
7579
function inferLinkType(link){
7680
if (link.host.startsWith('youtu')) return 'YouTube (link)';
7781
switch (link.pathname.slice(-4)) {
78-
case '.htm': return 'htm';
82+
case '.htm': return 'html';
7983
case 'html': return 'html';
8084
case '.mp3': return 'mp3';
8185
case '.pdf': return 'pdf';
@@ -91,48 +95,54 @@ const BuggyTracker = function (d) {
9195
if(!this._uid){this._uid=Math.random()*10000000;localStorage.setItem("uid", this._uid);}
9296
} return this._uid;
9397
};
94-
this.sendEvent=function(oid,value,categories){gtag('event','purchase',{
95-
transaction_id: "T_"+cyrb53(this.getUID()+":"+oid),
96-
value: value,
97-
items: [{
98-
item_id: oid,
99-
price: value,
100-
item_category: categories[0],
101-
item_category2: categories[1],
102-
item_category3: categories[2],
103-
item_category4: categories[3],
104-
item_category5: categories[4],
105-
item_list_name: whenceContent(d.referrer),
106-
item_brand: window.WEBSITE_SECTION
107-
}]
108-
});};
109-
this.handleEvent=function(e,link){link=e.target.closest('a');if(!link) return;
98+
this.sendEvent=function(oid,name,value,categories,thost){
99+
if (localStorage.getItem(oid+":click")) return; else localStorage.setItem(oid+":click",1);
100+
gtag('event','purchase',{
101+
transaction_id: "T_"+cyrb53(this.getUID()+":"+oid),
102+
value: value,
103+
items: [{
104+
item_id: oid,
105+
item_name: name,
106+
price: value,
107+
item_category: window.WEBSITE_SECTION+' '+categories[0],
108+
item_category2: categories[1],
109+
item_category3: categories[2],
110+
item_category4: categories[3],
111+
item_category5: categories[4],
112+
item_list_name: whenceContent(d.referrer),
113+
item_brand: thost
114+
}]
115+
});
116+
};
117+
this.handleEvent=function(e){this.handleClick(e.target.closest('a'));};
118+
this.handleClick=function(link){if(!link) return;
110119
var value = link.getAttribute('ga-event-value')*1;
111120
if(link.host != d.location.host || value > 0) {
112121
var cid = link.getAttribute('data-content-path');
113122
var oid = cid || link.href;
114-
if (localStorage.getItem(oid+":click")) return; else localStorage.setItem(oid+":click",1);
115123
value ||= 0.15;
116-
var categories=null;
124+
var categories=null,name=null;
117125
if(cid){
118126
var category = link.getAttribute('data-content-subcat');
119127
if (category) category = link.getAttribute('data-content-category')+'/'+category;
120128
else category = link.getAttribute('data-content-category');
121129
categories = [
122-
'Content',
130+
'content',
123131
category,
124132
link.getAttribute('data-content-course'),
125-
null,
133+
link.getAttribute('data-content-authors'),
126134
link.getAttribute('data-content-link-ext')
127135
];
136+
name = link.getAttribute('data-content-title');
128137
}else{
129138
categories=linkInfo(link);
130-
categories.splice(2,0,null);
131-
categories.unshift('External Link');
139+
categories.splice(2,0,link.getAttribute('data-content-authors')||'(unknown)');
140+
categories.unshift('link');
141+
name = link.text;
132142
}
133-
categories[3] = link.host || link.pathname;
143+
thost = link.host || link.pathname;
134144
categories[4] ||= inferLinkType(link);
135-
this.sendEvent(oid,value,categories);
145+
this.sendEvent(oid,name,value,categories,thost);
136146
}};
137147
d.addEventListener("click", this, {useCapture: true});
138148
d.addEventListener("contextmenu", this, {useCapture: true, passive: true});

0 commit comments

Comments
 (0)