GA Connector relies on Apex triggers to receive information about changes in Salesforce objects (and send these updates to Google Analytics).

By default, GA Connector package contains triggers for most standard objects.

But if you want to track a custom object, you need to add a trigger yourself:

1. Go to Salesforce – Developer Console:

Developer Console link
Developer Console link

2. Click New – Apex Trigger

New Apex Trigger
New Apex Trigger

3. Set the name to something like GaConnectorCustomObject (replacing CustomObject with the name of your custom object), and select the sObject you’d like to set the trigger for:

Set up trigger parameters
Set up trigger parameters

4. Click Submit.

5. Then paste the following code:

Paste Trigger code
Paste Trigger code

6. Replace GaConnectorCustomObject in the code with the trigger name you selected in the previous step.

7. Replace “CustomObject” with the API name (not the regular name) of you custom object (API names usually end with “__c”).

8. Finally, press Ctrl + S (or Cmd + S if you’re on Mac). If you don’t see any error messages after the saving is done, then the object trigger is added!