Skip to content

Instantly share code, notes, and snippets.

View stefanatcroud's full-sized avatar

Stefan Holmes stefanatcroud

View GitHub Profile
@stefanatcroud
stefanatcroud / ec-cjs-gtm.js
Last active September 6, 2024 09:50
Demonstrate the email transform required for Enhanced Conversions
// Add the below as a Custom JavaScript variable in GTM and it will use
// the Data Layer Variable "DLV - user_email" as the plaintext email input.
//
// Output will be a preformatted email address adhering to Google's
// requirements for Enhanced Conversions.
function() {
email = {{DLV - user_email}}.trim().toLowerCase().split('@');
return (email[1] === 'gmail.com' || email[1] === 'googlemail.com')
? email[0].replaceAll('.','').split('+')[0] + '@' + email[1]
: email[0].split('+')[0] + '@' + email[1]
@stefanatcroud
stefanatcroud / como_v2_defaults_us_versus_row.html
Last active January 9, 2024 16:45
Bespoke CoMo script for US versus non-US visitors
<!-- Google Consent Mode V2 -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('consent', 'default', {
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
analytics_storage: 'denied',
wait_for_update: 500
@stefanatcroud
stefanatcroud / como_v2_defaults.html
Created December 6, 2023 09:42
Google Consent Mode (CoMo) V2 Default Script
<!-- Google Consent Mode V2 -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
analytics_storage: 'denied',
wait_for_update: 500
@stefanatcroud
stefanatcroud / item_id_separator.js
Created August 1, 2023 10:48
Script for GTM to use in a Custom JavaScript variable that returns a vertical bar separated list of item.id's taken from GA4 ecommerce data layer
function () {
return google_tag_manager[{{Container ID}}].dataLayer.get("ecommerce.items").map(function(a){return a.item_id}).join("|")
}
@stefanatcroud
stefanatcroud / CMAPI_Integration.js
Last active November 24, 2023 11:07 — forked from shadybones/CMAPI_Integration.js
Enable TrustArc integrations. Sends a "TrustArc Consent" data layer event, which contains "trustarc.consent" as a string indicating each consent status, much like how OneTrust reports consent updates.
<script>
var __i__ = self.postMessage && setInterval(function () {
if (self.PrivacyManagerAPI && __i__) {
var apiObject = {
PrivacyManagerAPI:
{
action: "getConsentDecision",
timestamp: new Date().getTime(),
self: self.location.host
}