This GTM template allows for a customer to be logged in, logged out, or to be modified via your GTM implementation. This tag required the successful loading of the mParticle SDK to have been completed prior to this tag firing. This does require some additional set-up in comparison to other GTM tag templates, an identity callback function and user identities will need to be added to the data layer before the tag is triggered.
- Enable the data layer.
<script>
//configure the data layer
window.dataLayer = window.dataLayer || [];
</script>
- Add an identity callback to the data layer.
<script>
//add a custom identity callback to the data layer
dataLayer.push({
identityCallback: function(result) {
if (result.getUser()) {
// Do something once an identity call has been made.
// For more information, see https://docs.mparticle.com/developers/sdk/web/idsync/#sdk-initialization-and-identify
console.log(result);
}
},
});
</script>
- Add desired user identities to the data layer.
<script type="text/javascript">
//this is an example function that runs when the login button is clicked.
function processIDSync(eventName){
let email = document.querySelector('#email').value;
dataLayer.push({
'userIdentities': {
'email': email
}
})
//this is the example GTM custom event trigger for IDSync, please note that the identities are pushed before the trigger event.
dataLayer.push({'event': eventName'})
}
</script>
- Select the IDSync Template from the Google Community Template Gallery.
- Configure the tag with the desired IDSync event type.
- Configure the trigger to coincide with the login event.
- Deploy the tag.