Skip to content

Instantly share code, notes, and snippets.

@ju1
Last active February 28, 2017 14:54
Show Gist options
  • Save ju1/9e7deaaa6441fd3f0107b3c914b51f8f to your computer and use it in GitHub Desktop.
Save ju1/9e7deaaa6441fd3f0107b3c914b51f8f to your computer and use it in GitHub Desktop.
Soundcloud Recipe for Google Tag Manager
{
"exportFormatVersion": 2,
"exportTime": "2017-02-28 14:54:03",
"containerVersion": {
"path": "accounts/1164259306/containers/6431936/versions/0",
"accountId": "1164259306",
"containerId": "6431936",
"containerVersionId": "0",
"container": {
"path": "accounts/1164259306/containers/6431936",
"accountId": "1164259306",
"containerId": "6431936",
"name": "Soundcloud recipe",
"publicId": "GTM-KVN9SZV",
"usageContext": [
"WEB"
],
"fingerprint": "1488290881348",
"tagManagerUrl": "https://tagmanager.google.com/#/container/accounts/1164259306/containers/6431936/workspaces?apiLink=container"
},
"tag": [
{
"accountId": "1164259306",
"containerId": "6431936",
"tagId": "2",
"name": "GA - Event - Soundcloud Interaction",
"type": "ua",
"parameter": [
{
"type": "BOOLEAN",
"key": "nonInteraction",
"value": "false"
},
{
"type": "BOOLEAN",
"key": "doubleClick",
"value": "false"
},
{
"type": "BOOLEAN",
"key": "setTrackerName",
"value": "false"
},
{
"type": "BOOLEAN",
"key": "useDebugVersion",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "eventCategory",
"value": "{{dlv - eventCategory}}"
},
{
"type": "TEMPLATE",
"key": "trackType",
"value": "TRACK_EVENT"
},
{
"type": "BOOLEAN",
"key": "enableLinkId",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "eventAction",
"value": "{{dlv - eventAction}}"
},
{
"type": "TEMPLATE",
"key": "eventLabel",
"value": "{{dlv - eventLabel}}"
},
{
"type": "BOOLEAN",
"key": "enableEcommerce",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "trackingId",
"value": "{{YOUR_GA_TRACKING_ID}}"
}
],
"fingerprint": "1488293636261",
"firingTriggerId": [
"6"
],
"tagFiringOption": "ONCE_PER_EVENT"
},
{
"accountId": "1164259306",
"containerId": "6431936",
"tagId": "1",
"name": "cHTML - Soundcloud Listener",
"type": "html",
"parameter": [
{
"type": "TEMPLATE",
"key": "html",
"value": "<!-- Load the SoundCloud API synchronously -->\n<script src=\"https://w.soundcloud.com/player/api.js\"></script>\n<!-- Initiate the API integration -->\n<script>\n (function() {\n try {\n // initWidget is called when a SoundCloud iframe is found on the page\n var initWidget = function(w) {\n var currentSound, act, pos, q1, q2, q3, go, lab;\n var cat = 'SoundCloud';\n var widget = SC.Widget(w);\n \n // Events.READY is dispatched when the widget has been loaded\n widget.bind(SC.Widget.Events.READY, function() {\n \n // Get the title of the currently playing sound\n widget.getCurrentSound(function(cs) { \n lab = cs['title']; \n });\n \n // Fire a dataLayer event when Events.PLAY is dispatched\n widget.bind(SC.Widget.Events.PLAY, function() { \n act = 'Play'; \n sendDl(cat, act, lab); \n });\n \n // Fire a dataLayer event when Events.PAUSE is dispatched\n // The only exception is when the sound ends, and the auto-pause is not reported\n widget.bind(SC.Widget.Events.PAUSE, function(obj) { \n pos = Math.round(obj['relativePosition'] * 100);\n if (pos !== 100) {\n act = 'Pause'; \n sendDl(cat, act, lab); \n }\n });\n \n // As the play progresses, send events at 25%, 50% and 75%\n widget.bind(SC.Widget.Events.PLAY_PROGRESS, function(obj) { \n go = false;\n pos = Math.round(obj['relativePosition'] * 100);\n if (pos === 25 && !q1) {\n act = '25%';\n q1 = true;\n go = true;\n }\n if (pos === 50 && !q2) {\n act = '50%';\n q2 = true;\n go = true;\n }\n if (pos === 75 && !q3) {\n act = '75%';\n q3 = true;\n go = true;\n }\n if (go) {\n sendDl(cat, act, lab);\n }\n });\n \n // When the sound finishes, send an event at 100%\n widget.bind(SC.Widget.Events.FINISH, function() { \n act = '100%'; \n q1 = q2 = q3 = false; \n sendDl(cat, act, lab); \n });\n });\n };\n \n // Generic method for pushing the dataLayer event\n // Use a Custom Event Trigger with \"scEvent\" as the event name\n // Remember to create Data Layer Variables for eventCategory, eventAction, and eventLabel\n var sendDl = function(cat, act, lab) {\n window.dataLayer.push({\n 'event' : 'scEvent',\n 'eventCategory' : cat,\n 'eventAction' : act,\n 'eventLabel' : lab\n });\n };\n\n // For each SoundCloud iFrame, initiate the API integration\n var i,len;\n var iframes = document.querySelectorAll('iframe[src*=\"api.soundcloud.com\"]');\n for (i = 0, len = iframes.length; i < len; i += 1) {\n initWidget(iframes[i]);\n }\n } catch(e) { console.log('Error with SoundCloud API: ' + e.message); }\n })();\n</script>"
},
{
"type": "BOOLEAN",
"key": "supportDocumentWrite",
"value": "false"
}
],
"fingerprint": "1488290935917",
"firingTriggerId": [
"8"
],
"tagFiringOption": "ONCE_PER_EVENT"
}
],
"trigger": [
{
"accountId": "1164259306",
"containerId": "6431936",
"triggerId": "6",
"name": "Custom - Soundcloud Interaction",
"type": "CUSTOM_EVENT",
"customEventFilter": [
{
"type": "EQUALS",
"parameter": [
{
"type": "TEMPLATE",
"key": "arg0",
"value": "{{_event}}"
},
{
"type": "TEMPLATE",
"key": "arg1",
"value": "scEvent"
}
]
}
],
"fingerprint": "1488289653864"
},
{
"accountId": "1164259306",
"containerId": "6431936",
"triggerId": "8",
"name": "Pageview - DOM ready",
"type": "DOM_READY",
"fingerprint": "1488290987233"
}
],
"variable": [
{
"accountId": "1164259306",
"containerId": "6431936",
"variableId": "2",
"name": "dlv - eventAction",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "eventAction"
}
],
"fingerprint": "1488289600905"
},
{
"accountId": "1164259306",
"containerId": "6431936",
"variableId": "1",
"name": "dlv - eventCategory",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "eventCategory"
}
],
"fingerprint": "1488289587640"
},
{
"accountId": "1164259306",
"containerId": "6431936",
"variableId": "3",
"name": "dlv - eventLabel",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "eventLabel"
}
],
"fingerprint": "1488289613134"
}
],
"builtInVariable": [
{
"accountId": "1164259306",
"containerId": "6431936",
"type": "PAGE_URL",
"name": "Page URL"
},
{
"accountId": "1164259306",
"containerId": "6431936",
"type": "PAGE_HOSTNAME",
"name": "Page Hostname"
},
{
"accountId": "1164259306",
"containerId": "6431936",
"type": "PAGE_PATH",
"name": "Page Path"
},
{
"accountId": "1164259306",
"containerId": "6431936",
"type": "REFERRER",
"name": "Referrer"
},
{
"accountId": "1164259306",
"containerId": "6431936",
"type": "EVENT",
"name": "Event"
}
],
"fingerprint": "0",
"tagManagerUrl": "https://tagmanager.google.com/#/versions/accounts/1164259306/containers/6431936/versions/0?apiLink=version"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment