Integrate Google Tag Manager with Advocate
3
Set up a user upsert tag
<script>
// 1. When UTT is ready, run the following function.
window.impactOnReady = function() {
// 2. Configure UTT for your user and widget.
// The information provided here is used to track your user and register them in your Advocate program.
// This request is authenticated via JWT.
// A note about generating JWTs:
// JWTs are tokens that are signed with your tenant API key. They must be generated server-side.
// To ensure the security of your tenant and program, do not expose your tenant API key to your frontend.
// For more information see https://integrations.impact.com/impact-brand/docs/json-web-tokens
var userConfig = {
// 2b. Add details about your user.
// This must include id and accountId but other fields such as email, firstName, locale,
// or even custom fields can be included.
// For more details and a list of user fields see https://integrations.impact.com/impact-brand/docs/install-the-utt
user: {
id: '{{email}}',
accountId: '{{email}}',
locale: 'en_US',
cookies: '{{advocate}}'
},
// 2c. Add your generated JWT here to authenticate your request.
jwt: '{{jwt}}'
};
// 3. Make the request to upsert your user and render your widget.
impact.api().upsertUser(userConfig).then(function(response) {
// The widget API automatically inserts the HTML for your widget into your page via an iFrame.
// However if needed, you can retrieve details about the upserted user and the widget HTML
// through this function response.
var user = response.user;
console.log(user);
window.dataLayer.push({'event': 'user upserted'});
}).catch(function(error) {
console.log(error);
});
};
</script>(Optional) Set up an API upsert tag
Next steps
Last updated
