The integration between Exchange and Google Analytics is a multi-step process that is composed of generating the Exchange Capture JavaScript snippet, placing that snippet into your website by using Google Tag Manager, overriding the Google Analytics sendHitTask, and enabling you application in Exchange Capture.
Follow the steps listed in this guide to walk through and enable the Exchange and Google Analytics Tag Manager integration.
- Register Google Analytics registered as an endpoint.
- Add the sendHitTask override to your web page by using Google Tag Manager.
- Generate and add the Acoustic Exchange Capture JavaScript snippet to your web page by using Google Tag Manager.
- Obtain your Google Analytics event-level authentication key.
- Enable Google Analytics in Acoustic Exchange Capture to complete the integration.
Before you begin
Exchange
- You must have an Exchange account.
- You must be a licensed user of an Exchange or a business partner solution.
If you do not have an Exchange account and are a licensed user of an Exchange solution or a business partner solution.
Google Analytics
Ensure that you have a Google Analytics account and that you have configured your site according to Google Analytics' requirements.
If you do not have a Google Analytics account, contact the Google Analytics provisioning team. Learn more at Google Analytics Solutions.
For more information on Google Analytics requirements, see the Google Analytics user help.
Google Tag Manager
- Your Google Tag Manager (GTM) account is configured with a Google Analytics container.
- Your website is already tagged with the Google Tag Manager (GTM) code snippet.
- E-commerce is enabled in Google Tag Manager (GTM).
Register Google Analytics as an endpoint
To begin sharing Google Analytics data with Exchange and business partner solutions through Exchange, Google Analytics must be registered as an endpoint.
Exchange requires read permissions and a refresh token for your Google Analytics account to register as an endpoint. By granting read permissions you are allowing Exchange to communicate with your Google Analytics account. After Read permissions are granted, Exchange uses the refresh token to securely communicate with your Google Analytics account.
By registering Google Analytics as an endpoint in Exchange, you can leverage the data that is collected by Google Analytics with marketing ecosystems like Campaign Engage to retarget customers with timely and relevant offers.
- Log in to Exchange.
- On the Endpoints tab, click Register new endpoint to display the endpoint registration wizard.
- Select Google Analytics and click Next, and follow the onscreen instructions to complete the wizard.
Add the sendHitTask override
By adding the sendHitTask override JavaScript snippet to your web page by using Google Tag Manager, you are overriding the sendHitTask in Google Analytics. The JavaScript snippet performs a custom function that causes event data to flow to both Exchange and Google Analytics in real time.
The sendHitTask override captures event data as a hit and sends it to Google Analytics and the Exchange file as a hitPayLoad. The GAtoUBXEventMapper.js then maps the data to an Exchange naming convention and syntax.
To add the sendHitTask using Google Tag Manager:
- In Google Tag Manager, create a new variable and designate the type as custom JavaScript.
- Copy and paste the JavaScript snippet below into Google Tag Manager for the custom JavaScript content.
sendHitTask override JavaScript snippet
function() {
return function(model) {
var globalSendTaskName = '_' + model.get('trackingId') + '_sendHitTask';
var originalSendHitTask = window[globalSendTaskName] = window[globalSendTaskName] || model.get('sendHitTask');
model.set('sendHitTask', function(sendModel) {
originalSendHitTask(sendModel);
var payLoad = sendModel.get('hitPayload');
google_ubx.sendEventFromPayload(payLoad, identifiersMapperArray);
});
};
}
Example
This example code snippet uses clientId as an example. You must decide which identifier you want to use, and replace it in the example. Refer to the guidelines for creating a custom mapper array for Exchange identifiers.
function() {
return function(model) {
var globalSendTaskName = '_' + model.get('trackingId') + '_sendHitTask';
var originalSendHitTask = window[globalSendTaskName] = window[globalSendTaskName] || model.get('sendHitTask');
model.set('sendHitTask', function(sendModel) {
originalSendHitTask(sendModel);
var identifiersMapperArray = [];
var clientId = sendModel.get('clientId');
identifiersMapperArray.push({ "name": "gaClientId", "value": clientId });
var payLoad = sendModel.get('hitPayload');
google_ubx.sendEventFromPayload(payLoad, identifiersMapperArray);
});
};
}
Code |
Function |
originalSendHitTask(model) |
Sends the hit to Google Analytics. |
var payLoad = model.get("hitPayload") |
Retrieves the hitPayload. |
google_ubx.sendEventFromPayload(payLoad, identifiersMapperArray.push) |
Sends the hitPayLoad to your mapper array. |
- In Google Tag Manager, edit the Google Analytics Setting variable. In More Settings > Fields to set, add a new field customTask, set the value to the custom JavaScript variable.
- Designate the field name as customTask, and set the value to use the sendHitTask override JavaScript snippet.
Add the Exchange Capture JavaScript snippet
To perform a Exchange Google Analytics integration, you paste the Exchange Capture JavaScript snippet into your web page using Google Tag Manager.
- Go to Exchange > Tools > Exchange Capture. If the Copy embed code screen does not display when you visit Exchange Capture, select the embed code icon.
- Copy and save the code snippet.
- In Google Tag Manager, create a new Tag and designate the type as Custom HTML.
- Paste the Exchange Capture JavaScript into the HTML section, and set the Trigger to All pages. Load the snippet after the Google Analytics JavaScript and the sendHitTask override snippet. This is typically done by configuring tag sequencing.
If you do not use the Google Analytics setting variable in your tags, then edit the tag of which you want the event sent to Exchange, select Enable overriding settings in this tag.
- In More settings > Fields to set, add a new field customTask
- Set the value to be the custom JavaScript variable.
Find your Google Analytics event-level authentication key
When you register an endpoint in Exchange, an event-level authentication key is generated for the endpoint. Ensure that Google Analytics is registered as an endpoint.
In the Exchange and Google Analytics integration, the event-level authentication key is used to provide a secure means of communication between Google Analytics and Exchange. Additionally, the authentication key is required to enable the Exchange Capture JavaScript snippet.
- In Exchange, go to the Endpoints tab.
- Select Endpoint details.
- Copy and save the key.
Enable Google Analytics in Exchange Capture
To activate the JavaScript snippet that you embedded in you web page, you need enable your application in the Exchange Capture user interface.
Paste the event-level authentication key in its assigned field in Exchange Capture to enable the Exchange Capture JavaScript snippet.
- Log in to Exchange and navigate to the Tools menu.
- Select Acoustic Exchange Capture.
- In Acoustic Exchange Capture, find and select your application. Follow the instructions on screen to completion.
After a 2-hour activation period, Exchange Capture activates the code on your web site and data begins to flow from publisher to subscriber endpoints.
Map custom event types in Google Analytics with Google Tag Manager
Google Analytics gives you the flexibility to create your own custom event types to suit your business needs. Exchange respects that flexibility and customization by accepting custom Google Analytics events that are mapped to Exchange supported event types. As such, you can override an existing event type in the Exchange mapper and send any event that is supported by the Google Analytics endpoint. To do so, you must create custom identifier and attribute mapper arrays and pass the event data directly in Google Tag Manager.
- Create a custom JavaScript snippet.
Template:
function() { return function(model) { var globalSendTaskName = ‘_’ + model.get(‘trackingId’) + ‘_sendHitTask’; var originalSendHitTask = window[globalSendTaskName] = window[globalSendTaskName] || model.get(‘sendHitTask’); model.set(‘sendHitTask’, function(sendModel) { originalSendHitTask(sendModel); var payLoad = sendModel.get(‘hitPayload’); google_ubx.sendEventFromPayload(payLoad, <identifiersMapperArray>, <custom event name>, <attributeMapperArray>); }); }; }
- Create custom identifier and attribute mapper arrays.
Use the following code as a template for your mapper arrays.
var googleToUBXIdentifiersMapper = []; googleToUBXIdentifiersMapper.push ({"googleName":"googleIdentifierField1", "ubxName":"ubxIdentifierField1"}); googleToUBXIdentifiersMapper.push ({"googleName":"googleIdentifierField2", "ubxName":"ubxIdentifierField2"}); var googleToUBXAttributesMapper = []; googleToUBXAttributesMapper.push ({"googleName":"googleAttributesField1", "ubxName":"ubxAttributesField1", "type":"string"}); googleToUBXAttributesMapper.push ({"googleName":"googleAttributesField2", "ubxName":"ubxAttributesField2", "type":"number"});
- In the
googleIdentifierFieldN
field, enter the Google identifier name. - In the
ubxIdentifierFieldN
field, enter the Exchange identifier name. - In the
googleAttributesFieldN
field, enter the Google attribute names. - In the
ubxAttributeFieldN
field, enter the appropriate attributes for the event type. - To finalize the customization, call
google_ubx.sendEventFromPayload(payLoad, <identifiersMapperArray>, <custom event name>, <attributeMapperArray>)
in:function() { return function(model) { var globalSendTaskName = ‘_’ + model.get(‘trackingId’) + ‘_sendHitTask’; var originalSendHitTask = window[globalSendTaskName] = window[globalSendTaskName] || model.get(‘sendHitTask’); model.set(‘sendHitTask’, function(sendModel) { originalSendHitTask(sendModel); var payLoad = sendModel.get(‘hitPayload’); google_ubx.sendEventFromPayload(payLoad, googleToUBXIdentifiers,“wroteReview”,googleToUBXAttributesMapper); }); }; }
Your final result can look similar to the following code sample.var googleToUBXIdentifiers = []; googleToUBXIdentifiers.push({"googleName":"cd1", "ubxName":"recipientId"}); googleToUBXIdentifiers.push({"googleName":"cd2", "ubxName":"cookieID"}); var googleToUBXAttributesMapper = []; googleToUBXAttributesMapper.push({"googleName":"pr1id", "ubxName":"productID","type":"string"}); googleToUBXAttributesMapper.push({"googleName":"pr1ca", "ubxName":"category","type":"string"}); googleToUBXAttributesMapper.push({"googleName":"cd5", "ubxName":"review","type":"string"}); function() { return function(model) { var globalSendTaskName = ‘_’ + model.get(‘trackingId’) + ‘_sendHitTask’; var originalSendHitTask = window[globalSendTaskName] = window[globalSendTaskName] || model.get(‘sendHitTask’); model.set(‘sendHitTask’, function(sendModel) { originalSendHitTask(sendModel); var payLoad = sendModel.get(‘hitPayload’); google_ubx.sendEventFromPayload(payLoad, googleToUBXIdentifiers,“wroteReview”,googleToUBXAttributesMapper); }); }; }
- In the
- In Google Tag Manager, set the
customTask
field to where the event is being sent - In the Tag, select Enable overriding settings in this tag.
- Go to More settings > Fields to set and set the field name to
customTask
and set the value to be your new custom JavaScript snippet.
Map custom identifiers by using Google Tag Manager
In some cases, you might find it necessary to deviate from the default set of identifiers that Google Analytics provides and create custom identifiers. If you choose to do so, you can send the custom identifiers to Exchange by creating a custom identifier mapper array. The identifier mapper array is a JSON object that maps custom Google Analytics identifiers to existing Exchange identifiers by using the keys googleName
and ubxName
.
For example, the custom Google Analytics identifier dimesion6
, parameter name cd6
, can be mapped to an Exchange identifier by creating an array like googleToUBXIdentifiersMapper.push({"googleName":"cd6", "ubxName":"cookieId"});
and adding the name of the array to your Google Tag Manager Custom JavaScript snippet. In this example, the Exchange identifier name is cookieId
. This method of mapping will prove successful as long as the custom Google Analytics identifiers can be mapped to existing Exchange identifiers. If you attempt to map a custom Google Analytics identifier with an identifier that does not exist in the Exchange identifier repository, this method will fail.
To add a custom identifier to the Exchange identifier repository, contact Exchange provisioning.
For more information on custom Google Analytics identifiers, see Custom Dimensions / Metrics and the Analytics.js Field Reference in Google Analytics user help.
To map custom identifiers to Exchange identifiers and events, use the following code as a template for your mapper array.
var identifiersMapperArray = [];
identifiersMapperArray.push
({"googleName":"googleField1","ubxName":"ubxIdentifierField1"});
identifiersMapperArray.push
({"googleName":"googleField2","ubxName":"ubxIdentifierField2"});
identifiersMapperArray.push
({"googleName":"googleField3","ubxName":"ubxIdentifierField3"});
identifiersMapperArray.push
({"googleName":"googleField4","ubxName":"ubxIdentifierField4"});
function() {
return function(model) {
var globalSendTaskName = ‘_’ + model.get(‘trackingId’) + ‘_sendHitTask’;
var originalSendHitTask = window[globalSendTaskName] = window[globalSendTaskName] || model.get(‘sendHitTask’);
model.set(‘sendHitTask’, function(sendModel) {
originalSendHitTask(sendModel);
var payLoad = sendModel.get(‘hitPayload’);
google_ubx.sendEventFromPayload(payLoad, <mapper name)>;
});
};
}
- Enter the name of the mapper array in the
identifiersMapperArray
field. - Enter the Google Analytics custom identifier names in the
googleNameN
fields. - Enter the Exchange identifier names in the
ubxIdentifierFieldN
fields. - Map the identifiers by calling
google_ubx.sendEventFromPayload(payLoad, <mapper name>)
in
function() {
return function(model) {
var globalSendTaskName = ‘_’ + model.get(‘trackingId’) + ‘_sendHitTask’;
var originalSendHitTask = window[globalSendTaskName] = window[globalSendTaskName] || model.get(‘sendHitTask’);
model.set(‘sendHitTask’, function(sendModel) {
originalSendHitTask(sendModel);
var payLoad = sendModel.get(‘hitPayload’);
google_ubx.sendEventFromPayload(payLoad, <mapper name)>;
});
};
}
Map custom attributes by using Google Tag Manager
If you have custom attributes in Google Analytics and would like to send them to Exchange, you can do so by creating a custom attribute mapper array. The attribute mapper array is a JSON object that maps custom attributes to Exchange attributes by using the keys googleName
and ubxName
.
For example, the custom Google Analytics attribute dimesion7
, parameter name cd7
, can be mapped to an Exchange attribute by creating an array like googleToUBXattributesMapper.push({"googleName":"cd7", "ubxName":"productID"});
and calling the name of the array to Google Tag Manager custom JavaScript snippet. In this example, the Exchange attribute name is productID
.
Additionally, this integration requires that an identifier mapper array and Exchange event type mapper array are called in tandem with the attributes mapper array. For example, google_ubx.sendEventFromPayload(payLoad, identifiersMapperArray,
ubxEventTypeMapper, attributesMapperArray);
.
To map custom attribute to Exchange attribute and events, use the following code as a template for your mapper array.
var attributesMapperArray = [];
attributesMapperArray.push
({"googleName":"googleField1", "ubxName":"ubxAttributesField1",
"type":"string"});
attributesMapperArray.push
({"googleName":"googleField2", "ubxName":"ubxAttributesField2",
"type":"number"});
attributesMapperArray.push
({"googleName":"googleField3", "ubxName":"ubxAttributesField3",
"type":"string"});
function() {
return function(model) {
var globalSendTaskName = ‘_’ + model.get(‘trackingId’) + ‘_sendHitTask’;
var originalSendHitTask = window[globalSendTaskName] = window[globalSendTaskName] || model.get(‘sendHitTask’);
model.set(‘sendHitTask’, function(sendModel) {
originalSendHitTask(sendModel);
var payLoad = sendModel.get(‘hitPayload’);
google_ubx.sendEventFromPayload(payLoad, <identifiersMapperArray>,
<ubxEventTypeMapper>, <attribute mapper name>)>;
});
};
}
- Enter the name of the mapper array in the
attributesMapperArray
field. - Enter the Google Analytics custom attribute names in the
googleNameN
fields. - Enter the Exchange attribute names in the
ubxattributeFieldN
fields. - Map the attributes by calling
google_ubx.sendEventFromPayload(payLoad, identifiersMapperArray, ubxEventTypeMapper, <attribute mapper name>)
in
function() {
return function(model) {
var globalSendTaskName = ‘_’ + model.get(‘trackingId’) + ‘_sendHitTask’;
var originalSendHitTask = window[globalSendTaskName] = window[globalSendTaskName] || model.get(‘sendHitTask’);
model.set(‘sendHitTask’, function(sendModel) {
originalSendHitTask(sendModel);
var payLoad = sendModel.get(‘hitPayload’);
google_ubx.sendEventFromPayload(payLoad, <identifiersMapperArray>,
<ubxEventTypeMapper>, <attribute mapper name>)>;
});
};
}